Question

MATLAB help please!!!!!

1. Use the forward Euler method Vi+,-Vi + (ti+1-tinti , yi) for i=0.1, 2, , taking yo-y(to) to be the initial condition, to a

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clc
clear all
k=1:20;
N=2.^k;
f=@(t,y) y-t^2+1;
err=[];
ex=(3)^2-exp(2)/2;
for i=1:length(N)
t=linspace(0,2,N(i));
h(i)=t(2)-t(1);
y=[0.5];
for j=2:length(t)
y(j)=y(j-1)+h(i)*f(t(j-1),y(j-1));
end
err(i)=abs(ex-y(end));
end
plot(h,err)
xlabel('Step size');
ylabel('Error');

Figure 1 File Edit View srt Iools Desktop Window Help 1.8 1.6 0.8 0.6 0.4 0.2 0.2 0.4 0.6 0.8 1.2 1.6 1.8 Step size O Type he​​​​​​​

2)

close all
clear
clc
tspan = [0 2];
y0 = 0.5;
dydt = @(t,y) y - t^2 + 1;
y_exact = @(t) (t + 1)^2 - exp(t)/2;
[t, y] = ode45(dydt, tspan, y0);
fprintf('Approximate y(2): %.8f\n', y(end))
fprintf('Number of timesteps: %d\n', length(t))
fprintf('Error in the Approx. y(2): %.8f\n', y(end) - (y_exact(2)))

MATLAB R2018a Search Documentation Log In EDITOR Find Files Compare Print Run Section New Open Save Advance Run and Find Inde

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
MATLAB help please!!!!! 1. Use the forward Euler method Vi+,-Vi + (ti+1-tinti , yi) for i=0.1, 2, , taking yo-y(to) to be the initial condition, to approximate the solution at 2 of the IVP y'=y-t...
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