Contents

   Applications



© The scientific sentence. 2010

Euler method

1. The method:


Euler method is used to solve a differential equation of the first order of the form:
y' = F(x,y)     (1)
along with an initial condition: y(0) = y0


This method stems from the expresson of the Taylor expansion of a continuous function around a point (x0,f(x0)); that is:
f(x) = f(x0) + (x - x0) f'(x0) + (x - x0)2 f"(x0) /2! + ...

Taking the first two terms of this expansio, we have:
y(x) = y(x0) + (x - x0) y'(x0)
with y' = dy/dx

Using the equation of the first order y' = F(x,y) we get:
y(x) = y(x0) + (x - x0) F(x0, y0)    (2)
with the initial condition: y(0) = y0


If "x" runs from "a" to "b", we can write the discrete values of x as:
xi = i (b - a)/n, where "n" is an integer.
The equation (2) can be rewritten as:
y1 = y0 + (x1 - x0) F(x0, y0)
with the initial condition: y(0) = y0
...
yn+1 = yn + (xn+1 - xn) F(xn, yn)
with the initial condition: y(0) = y0

All the segments xn+1 - xn are equal. We can write them as h, thetrefore:

yn+1 = yn + h F(xn, yn)
with the initial condition: y(0) = y0

By iterations, in numerical method, yn+1 is the solution, or the nearest solution, of the differential equation. Going further in the expansion, we can express the solution in the second order to get more accurate values for the solution:
yn+1 = yn + h (F(xn,yn) + F(xn+1,averagen))/2;
with : averagen= yn + h F(xn,yn);



2. Using the method for integration

The two fundamental theorems of integration are:
1. ∫[from a to b] g(x) dx = G(a) - G(b), where G is the antiderivative of g.
2. If ∫ [from a to x] g(x) dx = G(x), then G'(x) = g(x)

Therefore, for our example: y' = F(x,y); if we find yn = f(xn) for a given xn, we can according to the first theorem, write:

ym - yn = ∫ F(x) dx [from xn to xm]
This is how Euler method can be used to integrate functions.

Example

F(x,y) = cos(x) - 0.00*y;
If we write:
y' = F(x,y) = cos(x) with the initial condition:y(0) = 2.0, we will have:
y = sin(x) + 2.0
and y(π/2) - y(π/6) = 1 - 1/2 = 0.50

The euler numerical method gives:
y(π/2) - y(π/6) = 2.9770 - 2.4885 = 0.50



3. Example in C language



//integral_euler.c program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/*
y' = cos x -0.00 y = F(x,y)
*/

float F(float p, float q){
return cos(p) - 0.00*q;
}
int main()
{
float pi = 4 * atan(1);
float L = pi;
int n = 7;
float y[n];
float x[n];
float average[n];

x[0] = 0.0;
y[0] = 2.0;
float h = L/(n-1);
int j;
for(j =1; j<=n-1; j++){
x[j] = j*h;
}

int i;
for(i =0; i<=n-1; i++ ){
//First order:
//y[i+1] = y[i] + h* F(x[i],y[i]);
//second order:
average[i] = y[i] + h* F(x[i],y[i]);
y[i+1] = y[i] + h*(F(x[i],y[i]) + F(x[i+1],average[i]))/2;
}

int k;
for(k =0; k<=n-1; k++ ){
printf("x = %1.2f  y(x)= : %1.4f \n", x[k],y[k]);
}

printf(" ---------------  \n");

// Integral of f frpm pi/6 to pi/
printf("Integral y[%1.2f] - y[%1.2f] =  %1.4f \n", x[3], x[1],y[3] - y[1]);

return 0;
}


Compiled and executed, the program yields:

//Using first order:
//-----------------

x = 0.00  y(x)= : 2.0000 
x = 0.52  y(x)= : 2.5236 
x = 1.05  y(x)= : 2.9770 
x = 1.57  y(x)= : 3.2388 
x = 2.09  y(x)= : 3.2388 
x = 2.62  y(x)= : 2.9770 
x = 3.14  y(x)= : 2.5236 
 ---------------  
Integral y[1.57] - y[0.52] =  0.7152 



//Using second order:
---------------------

x = 0.00  y(x)= : 2.0000 
x = 0.52  y(x)= : 2.4885 
x = 1.05  y(x)= : 2.8461 
x = 1.57  y(x)= : 2.9770 
x = 2.09  y(x)= : 2.8461 
x = 2.62  y(x)= : 2.4885 
x = 3.14  y(x)= : 2.0000 
 ---------------  
Integral y[1.57] - y[0.52] =  0.4885 






  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
Perl
|
php
|
green cat
|
contact
|


© Scientificsentence 2010. All rights reserved.