Question

SOLVE USING MATLABProblem 22.1A. Solve the following initial value problem over the interval fromt 0 to 5 where y(0) 8. Display all your results on the same graph. dt The analytical solution is given by: y(0) - 4e-0.5t (a) Using the analytical solution. (b) Using Eulers method with h 0.5 and 0.25 (c) Using the midpoint method with h 0.5. (d) Using the fourth-order RK method with h 0.5.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clear all;
y(1)=8;
% analytical y= 4+(y(0)-4)*e-0.5t
t=0.01:0.01:5;
y1=4+(y(1)-4)*exp(-0.5*t);
% Eulers method y_n+1=y_n+h*f(t,y) with h=.5
h1=0.5;
t2=0:h1:5;
for n=2:length(t2)
y2(1)=y(1);
y2(n)=y2(n-1)+h1*(2-((y2(n-1))/2));
end
% Eulers method y_n+1=y_n+h*f(t,y) with h=.25
h2=0.25;
t3=0:h2:5;
for n=2:length(t3)
y3(1)=y(1);
y3(n)=y3(n-1)+h2*(2-((y3(n-1))/2));
end
%mid point method
h3=.5;
t4=0:.5*h3:5;
for n=2:length(t4)
y4(1)=y(1);
y4(n)=y4(n-1)+.5*h3*(2-((y3(n-1))/2));
end
% fourth-order RK method with h=.5
h5=0.5;

t5=0:h5:5;
for n=2:length(t5)
y5(1)=y(1);
K1=2-((y5(n-1))/2);
K2=2-((y5(n-1)+(K1*h5/2))/2);
K3=2-((y5(n-1)+(K2*h5/2))/2);
K4=2-((y5(n-1)+(K3*h5))/2);
m=(K1/6)+(K2/3)+(K3/3)+(K4/6);
y5(n)=y5(n-1)+m*h5;
end
plot(t,y1,t2,y2,t3,y3,'*y',t4,y4,'r',t5,y5,'*');grid on;
legend('analytical','Euler,h=0.5','Euler,h=0.25','midpoint,h=0.5','4th order RK h=0.5')

_analytical Euler,h=0.5 Euler,h-0.25 midpoint, h:0.5 7.5 4th order RK h 0.5 6.5 5.5 5 0.5 1.5 2.5 3.5 4.5

Add a comment
Know the answer?
Add Answer to:
SOLVE USING MATLAB Problem 22.1A. Solve the following initial value problem over the interval fromt 0...
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