1 / 10100%
Jacob Derr
MAT 275 Lab 4
Exercise 1
Part a)
function LAB04ex1
t0=0;
tf=40; %defines timespan
y0= [-1;0];
[t,Y]= ode45(@f,[t0,tf],y0); %defines ode function
y=Y(:,1);
v=Y(:,2); %2 columns relating to y and v
figure(1);
plot(t,y,'b-+',t,v,'ro-') %plots the phase plot
legend('y(t)','v(t)'); %creates legend
grid on;
ylim([-1.5,1.5]); %sets limits for both plots
figure(2);
plot(y,v); axis square; xlabel('y'); ylabel('v');
%labels plot
grid on;
ylim([-1.5,1.5]);
xlim([-1,1]); %changes limits for both plots
end
function dYdt=f(t,Y)
y=Y(1);
v=Y(2);
dYdt=[v;cos(t)-4*v-3*y];
end
Part b)
-0.0147 0.2288
0.0063 0.2283
-0.0036 0.2236
0.0171 0.2230
-0.0137 0.2232
0.0086 0.2235
-0.0131 0.2232
0.0090 0.2235
-0.0131 0.2232
0.0090 0.2235
-0.0131 0.2232
0.0090 0.2235
Part c)
The Long-Term behavior follows the Lotka-Volterra model
Part d)
Altered initial condition
function LAB04ex1
t0=0;
tf=40; %defines timespan
y0= [1.5;5];
The Long_Term behavior is the same as the example above
Exercise 2
Part a)
function dYdt=f(t,Y)
y=Y(1);
v=Y(2);
dYdt=[v;cos(t)-4*y^2*v-3*y];
end
Part b)
The differences in short term between the example above and the graph in Example
one, are that this one is much more spread out, and it also follows Lotka-Volterra
model much better.
Part c)
The Long-Term difference of L4.4 and L4.7 is that the amplitude of oscillations is
much greater in figure L4.7. Also, in L4.7, it takes longer to create a constant
amplitude of oscillations.
Part d)
function LAB04ex2_1
t0=0;
tf=40; %defines timespan
y0= [-1;0];
[t,Y]=ode45(@f,[t0,tf],y0) %defines ode function
y=Y(:,1);
v=Y(:,2); %2 columns relating to y and v
[te,Ye] = euler(@f,[t0,tf],y0,400) %first change,
addition of eulers method
ye=Ye(:,1);
ve=Ye(:,2); %output of eulers mthod
figure(1);
plot(t,Y,'k-+',te,ye,'ro-') %plot of the yt solution
legend('Y(t)','v(t)'); %creates legend
grid on;
ylim([-1.5,1.5]); %sets limits for both plots
figure(2);
plot(Y,v); axis square; xlabel('Y'); ylabel('v');
%labels plot
grid on;
ylim([-1.5,1.5]);
xlim([-1,1]); %changes limits for both plots
end
function dYdt=f(t,Y)
y=Y(1);
v=Y(2);
dYdt=[v;cos(t)-4*y^2*v-3*y];
end
The solutions are the same
Exercise 3
Part a)
function LAB04ex3
t0=0;
tf=40; %creates interval
y0=[-1;0];
[t,Y]=ode45(@f,[t0,tf],y0) %define ode function
v=Y(:,1);
v=Y(:,2);
figure(1);
plot(t,Y,'b-+',t,v,'ro-'); %plots phase plot
legend('y(t)','v(t)'); %sets legend
grid on;
ylim([-1.5,1.5]) %sets limits
figure(2);
plot(Y,v); axis square; xlabel('Y'); ylabel('v=Y''');
grid on;
ylim([-1.5,1.5]);
xlim([-1,1])
end
function dYdt=f(t,Y)
y=Y(1);
v=Y(2);
dYdt=[v;cos(t)-4*y*v-3*y];
end
Warning: Failure at t=3.774765e+00. Unable to meet
integration
tolerances without reducing the step size below the
smallest value
allowed (7.105427e-15) at time t.
The behavior of the solution is significantly different from that of L4.7. In the first
graph, the oscillations have stopped, and the second graph no longer follows the
Lotka-Volterra model like the previous ones. MATLAB is giving a warning message
that is shown above. The message means that the graph is not defined at the stated
point.
Exercise 4
Part a)
function LAB04ex4
t0=0;
tf=40; %creates interval
y0=[-1;0;4];
[t,Y]=ode45(@f,[t0,tf],y0); %define ode function
y=Y(:,1);
v=Y(:,2);
w=Y(:,3);
figure(1);
plot(t,y,'b-+',t,v,'ro-',t,w,'k.-'); %plots three
values
legend('y(t)','v(t)','w(t)'); %sets legend
grid on;
ylim([-1.5,1.5]); %sets limits
figure(2);
plot3(y,v,w,'k.-');
grid on; view([-40,60]);
xlabel('Y'); ylabel('v=Y'''); zlabel('w=Y''''');
grid on;
ylim([-1.5,1.5]);
xlim([-1,1]);
end
function dYdt=f(t,Y)
y=Y(1);
v=Y(2);
w=Y(3);
dYdt=[v;w;-sin(t)-4*y^2*w-8*v^2-3*v];
end
Part b)
The behavior of the two graphs is different. L4i doesn’t have constant oscillations
like the L4h graph. The ‘w’ plot doesn’t oscillate with ease like the ‘v’ plot. The Long
Term behavior is similar, though
Part c)
Part d)
When t=0 and the initial conditions are plugged into L4.7, the solution is 4. The
initial conditions we’re left with are -1,0, and 4, which satisfy the initial conditions of
L4.8.
Students also viewed