Question

4. * Using your calculations from 3., plot the exact solution to dy = 1-y, dt y(0) = 1/2, for 0 <ts1, along with the numerica

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

Matlab code for (i)

clear t % Clears old time steps and
clear y % y values from previous runs
a=0;
b=1;
y0=0.5; % Initial value y(a)
h=0.1; % Time step
N=(b-a)/h;
t(1)=a;
y(1)=y0;
f=@(t,y)(1-y^2);
%while (norm(v,2))>10^-4 % For loop, sets next t,y values
for n=1:N
t(n+1)=t(n)+h;
y(n+1)=y(n)+h*f(t(n),y(n)); % Calls the function f(t,y)=dy/dt
end
y
plot(t(end),y(end),'*')

Output

y =

Columns 1 through 6

0.500000000000000 0.575000000000000 0.641937500000000 0.700729124609375 0.751626994001793 0.795132680190576

Columns 7 through 11

0.831909082279871 0.862701810161897 0.888276368836236 0.909372878092947 0.926676974951842

2 1.5 米 0.5 -0.5 0 0.2 0.4 0.6 0.8 11.214 1.6 1.8 2

Trapezoid rule

tspan =0:0.1:1;
y0 = 0.5;
[t,y] = ode23t(@(t,y) 1-y^2, tspan, y0)
plot(t(end),y(end),'square')

Output

t =

0
0.100000000000000
0.200000000000000
0.300000000000000
0.400000000000000
0.500000000000000
0.600000000000000
0.700000000000000
0.800000000000000
0.900000000000000
1.000000000000000

y =

0.500000000000000
0.570980566474321
0.634534816080768
0.690558579148676
0.739387374705229
0.781534279817847
0.817603838846551
0.848245447862247
0.874112554393215
0.895832147232664
0.913968745956985

2 1.5 0.5 -0.5 0 0.2 0.4 0.6 0.8 11.214 1.6 1.8 2

solation -Wj -) ..ヲ ヲヲヲラヲ ge

iii Matlab Code

t=0:0.1:1;
y=(3*exp(2*t)-1)./(3*exp(2*t)+1);
plot(t,y)

Output

0.95 n 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0 0.1 0.2 0.3 04 0.5 0.6 0.7 0.8 0.9 1

Add a comment
Know the answer?
Add Answer to:
4. * Using your calculations from 3., plot the exact solution to dy = 1-y, dt y(0) = 1/2, for 0 <ts1, along with the numerical solution given by Euler's method and the trapezoid method, both w...
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