Question

Numerical Analysis: Make a matlab code that computes the Midpoint rule/method for a given function f'(t,y)...

Numerical Analysis:

Make a matlab code that computes the Midpoint rule/method for a given function f'(t,y) = y' =  t + y from 0 < t < 4 (inclusive) with h=0.5 and with initial condition y(0) = 0.
Please make output display in tabular form and not in a plot, that doesn't help show the actual values.

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

clc;
clear all;
f=@(t,y) t+y;% given function
h=0.5; %step length
a=0; % starting point
b=4; %ending point

N=(b-a)/h; % number of intervals
t=a:h:b;
y_mid(1)=0; %initial point

% Midpoint formula
for i=1:N
k(i)=y_mid(i)+(h/2)*f(t(i),y_mid(i));
y_mid(i+1)=y_mid(i)+h*f(t(i)+h/2,k(i));
end
disp('------------------------------')
disp( 'tn y_Midpoint ')
disp('-----------------------------')
for i=1:N+1
fprintf(' %f \t %15f \n',t(i),y_mid(i))
end

--------------------------------------
tn y_Midpoint
-------------------------------------
0.000000 0.000000
0.500000 0.125000
1.000000    0.640625
1.500000    1.791016
2.000000    3.972900
2.500000    7.830963
3.000000    14.412815
3.500000    25.420825
4.000000    43.621340

y_Midpoint tn 0.000000 0.000000 0.500000 0.125000 1.000000 0.640625 1.500000 1.791016 2.000000 3.972900 2.500000 7.830963 3.0

Add a comment
Know the answer?
Add Answer to:
Numerical Analysis: Make a matlab code that computes the Midpoint rule/method for a given function f'(t,y)...
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