Professional Documents
Culture Documents
Presentation Euler Method
Presentation Euler Method
Presentation Euler Method
Introduction
Algorithm
Matlab code for Eular’s method
Results
Conclusion
Introduction
1. Define the initial conditions: initial value, time step, and number of
iterations.
2. Initialize the solution array with the initial value.
3. Loop through the desired number of iterations
4. Calculate the derivative at the current time.
5. Update the solution by multiplying the derivative with the time step
and adding it to the previous solution.
Update the current time
6. Plot the results.
Matlab code for Eular’s method
% Euler's method
% Approximate the solution to the initial-value problem
% dy/dt=y-t^2+1 ; 0<=t<=2 ; y(0)=0.5;
f = @(t,y) (y-t^2+1);
a = input('Enter left end ponit, a: ');
b = input('Enter right end point, b: ');
n = input('Enter no. of subintervals, n: ');
alpha = input('Enter the initial condition, alpha: ');
h = (b-a)/n;
t = a;
w = alpha;
fprintf(' t w\n');
fprintf('%5.4f %11.8f\n', t, w);
for i = 1:n
w = w+h*f(t, w);
t = a+i*h;
fprintf('%5.4f %11.8f\n', t, w);
plot(t,w,'r*'); grid on;
xlabel('t values'); ylabel('w values');
hold on;
end
>;
OutPut:
euler_final
Enter left end ponit, a: 0
Enter right end point, b: 2
Enter no. of subintervals, n: 10
Enter the initial condition, alpha: 0.5
t w
0.0000 0.50000000
0.2000 0.80000000
0.4000 1.15200000
0.6000 1.55040000
0.8000 1.98848000
1.0000 2.45817600
1.2000 2.94981120
1.4000 3.45177344
1.6000 3.95012813
1.8000 4.42815375
2.0000 4.86578450
>>
;
Results
Results
Advantages:
Simple and easy to implement.
Efficient for simple ODEs
Limitation:
ANY QUERIES????