You are on page 1of 8

MATLAB PLOTS

b=[0:0.001:10];
a=sqrt(4*b);
plot(b,a,b,-a);
hold on;
rectangle('Position',[-10,-10,20,20]);
hold on;

Case 1, Aperiodic Decay

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=100;

m=1;
k=1;
c=7;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 -1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 2, Aperiodic Decay (On the parabola)

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=50;

m=1;
k=1;
c=2;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 3, Periodic Decay

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=100;

m=1;
k=1;
c=0.1;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 4, Pure Oscillations

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=50;

m=1;
k=1;
c=0;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 5, Oscillatory Divergence

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=100;

m=1;
k=1;
c=-0.1;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 -1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 6, Aperiodic Divergence (Below the parabola in 4th quadrant)

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=105;

m=1;
k=0.001;
c=-0.06;
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

Case 7, Aperiodic Divergence (2nd and 3rd quadrant)

function dx= smd(t,x)


x1=x(1);
x2=x(2);

clc;
clear all;
close all;
tf=105;

m=1;
k=-0.001;
c=-0.01; %or +0.01
dx1=x2;
dx2=-((c/m)*x2)-((k/m)*x1);
dx=[dx1;dx2];

[time,x]=ode45(@smd,[0:0.1:tf], [0 -1]);
y1=x(:,1);
y2=x(:,2);
plot (time,y1,'b-')
hold on
%plot (time,y2,'r-')

You might also like