Name: Derick Tangap
Instructor: Richard Ruedemann
Assignment: Mat275_LabIV
Excerise (I)
Part (a)
function LAB04ex1a
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
Y1 = Y(:,1); Y2 = Y(:,2);
figure(1); %displays first figure to plot first graph
plot(t,Y1,'b-',t,Y2,'r-'); %plots the graph aganist the time axis
grid on; legend('y(t)','v(t)=y''(t)'); ylim([-1.2,1.2]) %adds grids and
%legend and adjust ylimts
figure(2) %opens second figure to plot second graph
plot(Y1,Y2); axis square; xlabel('Y_1'); ylabel('Y_2'); % plot the phase plot
grid on
xlim([-0.5,1])%ajust the window
ylim([-1.2,1.2])
[t,Y];
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2);
dYdt = [v; sin(t)-7*v-5*y];
end
0.8
—yit)
with=y'(t)|
5
10 15
2 2
3 3
40 45
1
0s
0
05
a
08
05
1
50
Part (b)
function LAB04ex1b
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
Y1 = Y(:,1); Y2 = Y(:,2);
[t,Y];
end
Time y(t) y’(t)
3.0925 0.0801 -0.0316
8.9339 0.1237 -0.0033
18.3610 0.1240 0.0038
24.6355 0.1240 0.0027
34.0250 0.1240 0.0042
46.5714 0.1240 0.0041
This table displays the time function y(t) at its local max every period. y’(t) is
the corresponding points.
Part (c)
The long term behavior of this wave appears to be periodic, without knowing
the equation however, it is impossible to know if this waveform is a sin or cosine.
Part (d)
function LAB04ex1d
t0 = 0;
tf = 50; %sets time interval
Y0 = [2;3];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
Y1 = Y(:,1); Y2 = Y(:,2);
figure(1); %displays first figure to plot first graph
plot(t,Y1,'b-',t,Y2,'r-'); %plots the graph aganist the time axis
grid on; legend('y(t)','v(t)=y''(t)'); ylim([-1.2,1.2]) %adds grids and
%legend and adjust ylimts
figure(2) %opens second figure to plot second graph
plot(Y1,Y2); axis square; xlabel('Y_1'); ylabel('Y_2'); % plot the phase plot
grid on
xlim([-0.5,1])%ajust the window
ylim([-1.2,1.2])
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2);
dYdt = [v; sin(t)-7*v-5*y];
end
From these graphs, we can see that they do not change over a period of
time. What do observe, shows how the function appears different. This is because,
the initial, conditions have been changed. But, the wave will follow simialar path.
Excerise (II)
Part (a)
% (a)
function LAB04ex2a
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
y = Y(:,1); v = Y(:,2);
figure(1); %displays first figure to plot first graph
plot(t,y,'b',t,v,'r'); %plots the graph aganist the time axis
grid on;xlim([0,50]); ylim([-1.2,1.2]) %adds grids and
%legend and adjust ylimts
legend('y(t)','v(t)=y''(t)');
figure(2); %opens second figure to plot second graph
plot(y,v);grid on; axis square;
xlabel('y'); ylabel('v=y''(t)');%labels the axis
xlim([-0.5,1]);%ajust the window
ylim([-1.2,1.2]);
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2);
dYdt = [v; sin(t)-7*y^2*v-5*y];
end
Part (b)
Looking at the graph, we can attest our solution has an enmorous applitude
that is very unstable fo rthe first few seconds. This graph dosen’t start to show
trend untill 20 seconds.
Part (c)
Comparing exerises 1 and 2 graphs, we notice both functions behaving
alike. Both, of these plots have a period of 6.25. The main difference we can see is
the amplitue in ex. 2. It appears to be twice the magnitude of the first plot.
Part (d)
% (d)
function LAB04ex2d
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
y = Y(:,1); v = Y(:,2);
h = 0.1; N= round((tf-t0)/h);
[tE,YE] = euler(@f, [t0,tf],[Y0],N);%Euler
yE = YE(:,1); ve = YE(:,2);
figure(1); %displays first figure to plot first graph
plot(t,y,'k.-',tE,yE,'r.-'); ylim([-1.2,1.2]) %plots given solution with Euler's on smae
%graph
%adds grids and
%legend and adjust ylimts
legend('y(t)','Euler Approximation'); %Legend
grid on; xlabel('time');
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2);
dYdt = [v; sin(t)-7*y^2*v-5*y];
end
Looking at the graph we can conclude bothe solutions aren’t identical but
Euler’s method also contains slight erros which could impact the graph above.
Excercis (III)
%%Exercise (2)
% Solution II
% (d)
function LAB04ex2
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
y = Y(:,1); v = Y(:,2);
figure(1); %displays first figure to plot first graph
plot(t,y,'bo-',t,v,'r'); %Time axis plot
legend('y(t)','v(t)=y''(t)');%Legend
grid on;
figure(2)
plot(y,v);
axis square;
grid on;xlabel('y');ylabel('v=y'''); %perform labeling
ylim([-1.2,1.2]); xlim([-0.5,1]);
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2);
dYdt = [v; sin(t)-7*y*v-5*y];
end
Warning: Failure at t=5.840631e+00. Unable to meet integration tolerances
without reducing the step size below the smallest value allowed (1.421085e-14)
at time t.
The error was given as a result of out of step size indicates the graph shown
are not true representationof the function.
0.8
0s
Exercise #4
Part (a)
function LAB04ex4a
t0 = 0;
tf = 50; %sets time interval
Y0 = [-0.5;.5;1.625];
[t,Y] = ode45(@f,[t0,tf],Y0,[]);%solves the differential equation
y = Y(:,1);
v = Y(:,2);
w = Y(:,3);
figure(1); %displays first figure to plot first graph
plot(t,y,'b-',t,v,'r',t,w,'m-'); %Time axis plot
legend('y(t)','v(t)=y''(t)','w=y''''(t)');%Legend
grid on; %turn grid on
ylim([-1.2,1.2]) %set win size
figure(2)
plot3(y,v,w,'k-'); %plot 3D graph
view([-40,60]);
axis square;
grid on;xlabel('y');ylabel('v=y''');zlabel('w=y''''')%perform labeling
ylim([-1.2,1.2]); xlim([-0.5,1]); zlim([-4,4]);
end
%----------------------------------------------------------------------
function dYdt = f(t,Y)
y = Y(1); v=Y(2); w=Y(3);
dYdt = [ v; w; cos(t)-7*y^2*w-14*y*v^2-5*v ];
end
0.8
10 15
20 25
30 35
40
45
50
Part (b)
Looking at the graph, we see that all the waveforms appear periodic. In both
graphs we can see that time 0 the initial conditions have the greatest impact. The
functions have same amplitude but the max of each other function occur at
different times. Thisis cause the L4h being L4h being sin function and L4i a cosine
function.
Part (c)
Differentitiating the function in ex2 we see that this function becomes a
since function. This makes this the same function that is used in ex.4
Part (d)
The intial conditions used in exercise 2 work in this ex. Because the eqaution
L40 is the derivative of the function that was used.