Question

ME 32200 Programming course (MATLAB)

4. Please finish the following Matlab code for solving the ODE: dy = y(1+1) dt I.C. y(0) = 0 with the multi-step 4th order Mi

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

I have completed the code. Please find a screenshot of the code and output and the text of the code. Please note that this is a script file to be saved as MRK.m in the MATLAB root directory.

CODE

+ 1 2 3 4 5 7 8 9 10 11 12 13 basiliskplotter.m x MRK.m X rk4calc.m S008.m X Q function MRK) clear all; close all; fun=@(t,y)

function MRK()
clear all; close all;
fun=@(t,y)(y*(1+t));
h = 0.01;
t0 = 0;
tn = 1;
t = t0:h:tn;
n = ((tn - t0)/h) +1 ;
y=zeros(n,1);
y(1)=1;
% 4th Runga Kutta Method
for i=1:3
   k1=fun(t(i),y(i));
   k2=fun((t(i)+0.5*h),(y(i)+0.5*k1));
    k3=fun((t(i)+0.5*h),(y(i)+0.5*k2));  
   k4=fun((t(i)+h),(y(i)+k3));
   y(i+1)=y(i)+(h*(k1+2*k2+2*k3+k4)/6);
end
%4th Milne Method
for i=4:n-1
fi = fun(t(i),y(i));
fi1 = fun(t(i-1),y(i-1));
fi2 = fun(t(i-2),y(i-2));
  
y_bar = y(i-3) + ( 4*h*(2*fi - fi1 + 2*fi2) /3);
fbari1 = fun(t(i) + h,y_bar);
y(i+1) = y(i-1) + (h*(fbari1 + 4*fi + fi1)/3);
end
plot(t,y,'b-');
end

OUTPUT

5 4.5 4. - 3.5 2.5 2 1.5 1 - 1 1 0 0.1 0.2 0.3 0.4 0.5 0.6. 0.7 0.8 10.9 1

If my answer helped you, please consider leaving an upvote. Thank you! :)

Add a comment
Know the answer?
Add Answer to:
ME 32200 Programming course (MATLAB) 4. Please finish the following Matlab code for solving the ODE:...
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