This is a Matlab assignment for MAT275 (differential equation class). Please hel
ID: 3757045 • Letter: T
Question
This is a Matlab assignment for MAT275 (differential equation class). Please help me with the script I need to turn in for the assignment! Thank you all! :)
2. Consider the IVP for 0 (t+dt, t+dy) % adjust look ; grid of values in t and y direction quiver(T,Y,dT,dY.) axis tight hold on After running these c s you should get the graph of the slope field. (b) Use linspace to generate a vector of 100 t-values between 0 and 5. Evaluate the analyt- ical solution y at these t-values and plot it in black together with the direction field (use 'linewidth',2) (c) Enter the function defining the ODE as anonymous Use euler.m with N 10 to determine the approximation to the solution. Plot the approxi- mated points in red (use 'ro-', 'linezidth',2 as line-style in your plot), together with the exact solution and the direction field. Type hold off to end plotting in this figure window You should get Figure L3b. Based on the slope field and the geometrical meaning of Euler's method explain why the approximations are so inaccurate for this particular value of the stepsize. (d) Open a new figure by typing figure. Plot again the direction field but in a different window: t-0:.3:5; y --1:.4:2Repeat part (b) and repeat part (c) but this time with N 20 You should get Figure L3c. Comment on the result from a geometrical point of view Note: Brief explanations of the commands quiver and meshgrid are included in Appendix A. In Appendix B we describe the Graphical User Interface dfield8 for plotting slope fields.Explanation / Answer
Matlab Code :
clc;
clear all;
figure(1)
[t,y]=meshgrid(0:.3:5,-3:.5:3);
dy = -4*y;
dt = ones(size(t));% dt=1
quiver(t,y,dt,dy)
title('-4y')
axis tight
hold on
t=linspace(0,5,100);
y=2*exp(-4*t);
plot(t,y,'k','linewidth',2)
hold on
a=0;
b=5;
f=@(t,y)-4*y;
N=10;
h=(b-a)/N;
Y(1)=2;
T=a:h:b;
for i=1:N
Y(i+1)=Y(i)+h*f(T(i),Y(i));
end
plot(T,Y,'ro-','linewidth',2)
hold off
figure(2)
[t,y]=meshgrid(0:.3:5,-3:.5:3);
dy = -4*y;
dt = ones(size(t));
quiver(t,y,dt,dy)
title('-4y')
axis tight
hold on
t=linspace(0,5,100);
y=2*exp(-4*t);
plot(t,y,'k','linewidth',2)
hold on
f=@(t,y)-4*y;
N1=20;
h=(b-a)/N1;
Y1(1)=2;
T1=a:h:b;
for i=1:N1
Y1(i+1)=Y1(i)+h*f(T1(i),Y1(i));
end
plot(T1,Y1,'ro-','linewidth',2)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.