Question

MATLAB CODE:Task 2 8y dt Solve the above ordinary differential equation (ODE) using Eulers method with step sizes of: 2. h 0.75 3. h 0.5

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

Note: Script is written for h=1. In the same script you can just replace the value of h inorder to get the results. The results have been posted of all h:

clc;clear all;
f=@(t,y) 3*exp(t)-(8*y)/3;
fact=@(t) (9/11)*exp(t)+(24/11)*exp(-8*t/3);
t0=0;
tf=3;
y0=3;
h=1;
t=t0:h:tf;
n=length(t);
t(1)=t0;
y(1)=y0;
yana(1)=y0;
for i=2:n
         y(i)=y(i-1)+h*f(t(i-1),y(i-1));
         yana(i)=fact(t(i));
         err=abs(yana-y);
                    
end
plot(t,y)
hold on
plot(t,yana,'r')
legend('eulers','analytical')
title(['h=',num2str(h)])
err=err(n);
fprintf('For step size of h= %.4f, the error is =%.5f\n',h,err);

1) for h=1

For step size of h= 1.0000, the err r 13 =13.41415 fx >>Figure 1 File Edit View Insert Tools Desktop Window Help h=1 18 16 14 12 10 eulers analytical 4 -2 2.5 1.5 0.5

2) for h=0.75

Command Window For step size of h= 0.7500, the error is =0.34250 ft >>Figure 1 File Edit View Insert Tools Desktop Window Help h 0.75 18 16 14 12 10 eulers analytical 0.5 1.5 2.5

3) for h=0.5

Command Window For step size of h= 0.5000, the error is =1.23073 fs >Figure 1 File Edit View nsert Tools Desktop Window Help h=0.5 18 eulers -analytical 16 14 12 10 2 2.5 1.5 0.5

4) for h=0.001

ommand Window For step size of h- 0.0010, the error is 0.00225Figure 1 File Edit View Insert Tools Desktop Window Help 稳 h=0.001 18 eulers analytical 16 14 12 10 2.5 1.5 0.5

Add a comment
Know the answer?
Add Answer to:
MATLAB CODE: Task 2 8y dt Solve the above ordinary differential equation (ODE) using Euler's method with step sizes of: 2. h 0.75 3. h 0.5 4. h 0.001 a) For each step size, plot the results at eac...
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