1 / 6100%
MAT 275 Lab #4
Exercise 1
Part A
function LAB04ex1
t0 = 0; tf = 40; y0 = [-1,0];
[t,Y] = ode45(@f,[t0,tf],y0,[]);
y = Y(:,1); v = Y(:,2); % y in output has 2 columns corresponding to y and
v
figure(1);
plot(t,y, ,t,v, )'b-' 'r-' %Plotting both sides of equation
legend( , )'y(t)' 'v(t)=y''t(y)'
ylim([-1.5,1.5])
grid on
figure(2)
plot(y,v, ); axis ; xlabel( ); ylabel( ); 'k' square 'y' 'v' %phase plot
ylim([-1.5,1.5])
xlim([-1,1])
grid on
end
dYdt = f(t,Y) function %Define the ODE
y = Y(1); v = Y(2);
dYdt = [ v; cos(t)-4*v-3*y ];
end
Part B
At t=38.7814, y is a local max
At t=32.4983, y is a local max
At t=26.2125, y is a local max
At t=19.9324, y is a local max
At t=13.6632, y is a local max
At t=07.3958, y is a local max
Part C
The Long term behavior of y oscillates between
.25 and -.25 infinitely
Part D
function LAB04ex1d
t0 = 0; tf = 40; y0 = [1.5;5];
a = .8; b = .01; c = .6; d = .1;
[t,Y] = ode45(@f,[t0,tf],y0,[]);
[t,Y]
y = Y(:,1); v = Y(:,2); % y output has 2 columns corresponding to y and v
figure(1);
plot(t,y, ,t,v, )'r-' 'b-' %Plotting both sides of equation
legend( , )'y(t)' 'v(t)=y''t(y)'
Students also viewed