Euler's Method: Dy y y y y Fxy DX X X H y y H Fxy
Euler's Method: Dy y y y y Fxy DX X X H y y H Fxy
Applying the Method
The differential equation given tells the formula for f(x, y) required by the Euler Method,
namely:
f(x, y) = x + 2y
and the initial condition tells the values of the coordinates of our starting point:
x
o
= 0 , y
0
= 0
Use the Euler method formulas to generate values for x
1
and y
1
.
The x-iteration formula, with n = 0 gives:
x
1
= x
o
+ h
or:
x
1
= 0 + 0.25
So:
x
1
= 0.25
And the y-iteration formula, with n = 0 gives:
y
1
= y
o
+ h f(x
o
, y
o
)
or:
y
1
= y
o
+ h (x
o
+ 2y
o
)
or:
y
1
= 0 + 0.25 (0 + 2*0)
Summarizing, the second point in our numerical solution is: x
1
=0.25 , y
1
=0
Above steps are repeated to get values of y at different instants.
Matlab implementation of eulers method:
func=input('Enter the Function You Want to Slove= ','s');
step_size=input('Input The step size= ');
initialx=input('initalx' );
final=input('Input the value of x upto which you want answer= ');
x=[initialx:step_size:final];
y=zeros(size(x));
y(1)=input('Initial Condition for y=');
f=inline(func);
i=2;
k=((final-initialx)/step_size) + 1;
while i<=k
y(i)=y(i-1)+ step_size*f(x(i-1),y(i-1));
i=i+1;
end
y(k)
clf
plot(x,y)
Solution of Differential equation using
Eulers and Trapezoidal method