Question
Differential Equation in matlab:
Please help!
Thanks

2. (30 pts.) Implement the Eulers method in MATLAB and solve the problem y a2+ y(0) 4, using different steps for the approximation. Plot the results.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab code for different steps:

% Euler's Methode
close all
clc;
clear all;
h = 0.2;
y(1) = 4;
x = 0:0.2:2;
for n = 1:size(x,2)-1
y(n+1) = y(n) + h*( (x(n))^2 + (y(n))^2 );
end

plot(x,y)
xlabel('t');
ylabel('y');

hold on

clear all;
h = 0.2;
y(1) = 4;
x = 0:0.02:2;
for n = 1:size(x,2)-1
y(n+1) = y(n) + h*( (x(n))^2 + (y(n))^2 );
end

plot(x,y)
xlabel('t');
ylabel('y');

hold on

clear all;
h = 0.2;
y(1) = 4;
x = 0:0.002:2;
for n = 1:size(x,2)-1
y(n+1) = y(n) + h*( (x(n))^2 + (y(n))^2 );
end

plot(x,y)
xlabel('t');
ylabel('y');

legend('h = 0.2', 'h=0.02', 'h = 0.002');

Plot obtained from euler's methode:

2e+156 h 0.02 h . 002 1.5e+156 1e+156 >1e+156 5e+155 0.5 1.5

Actual plot of the exact solution:

1-65 4.5 0.5 0.5 1.5 2.5 3.5 4.5

Add a comment
Know the answer?
Add Answer to:
Differential Equation in matlab: Please help! Thanks 2. (30 pts.) Implement the Euler's method in MATLAB...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT