1 / 6100%
MAT 275 MATLAB Assignment #4 NAME:____Allison Liaiga ______
LAB DAY and TIME:_ F @ 8:25_
Instructor: ______ England _____
Exercise 1a
type('LAB04ex1.m')
function LAB04ex1
t0=0; tf=50; y0=[-0.5,0.5];
[t,Y]=ode45(@f,[t0,tf],y0,[]);
y=Y(:,1);
v=Y(:,2);
figure(1);
plot(t,y,'b'); ylabel('y');
hold on
plot(t,v,'r'); ylabel('v');
ylim([-1.2,1.2]);
grid on
legend('y(t)','v(t)=y"(t)');
figure(2);
plot(y,v,'k');xlabel('y');ylabel('v=y"');
grid on
ylim([-1.5,1.5]);
xlim([-0.5,1]);
end
function [ dYdt ] = f( t,Y )
y=Y(1); v=Y(2);
dYdt=[v;sin(t)-7*v-5*y];
end
Exercise 1c
%As y goes to infinity it will keep oscillating as there seems to be no
%evidence of dampening. The amplitude and frequency seem to remain
%relatively consistent.
Exercise 1d
type('LAB04ex1d.m')
LAB04ex1d
%The long term behavior of the solution stays the same. The first plot
%still oscillates to infinity with the same values and consistency. The
%second plot still encircles itself as t goes to infinity. So for both
%graphs the solution will remain the same in
%the long term.
function LAB04ex1d
t0=0;tf=50;y0=[2,3];
[t,Y]=ode45(@f,[t0,tf],y0,[]);
y=Y(:,1); v=Y(:,2);
figure(3);
plot(t,y,'b'); ylabel('y');
hold on
plot(t,v,'r'); ylabel('v');
ylim([-1.2,1.2]);
grid on
legend('y(t)','v(t)=y"(t)');
Students also viewed