It only plots the first one because your Zeta is always 1 (c/cc = 1). Moreover, even if you changed Zeta to be other values, it would overwrite your graph since you do not have "hold on" for the figure.
instead of using if statements, why dont you define 4 different functions like this:
clear,clc
m=2;
k=200;
x0=0.05;
x_dot=2;
Wn= (k/m)^0.5;
c= (2*m*Wn);
Cc= (2*m*Wn);
Zeta=1;
C1=x0;
C2=x_dot+Wn*x0;
x_1 = @(t) (C1+C2*t)*exp(-Wn*t);
Zeta=0;
X= (((x0^2)*(Wn^2)+(x_dot^2)+(2*x0*x_dot*Zeta*Wn))^0.5)/(((1-(Zeta^2))^0.5)*Wn);
phi= atan((x_dot+(Zeta*Wn*x0))/(x0*Wn*((1-(Zeta^2))^0.5)));
Wd= ((1-(Zeta^2))^0.5)*Wn;
x_0 = @(t) X*(exp(-Zeta*Wn*t))* cos((Wd*t)-phi);
Zeta=0.5;
X= (((x0^2)*(Wn^2)+(x_dot^2)+(2*x0*x_dot*Zeta*Wn))^0.5)/(((1-(Zeta^2))^0.5)*Wn);
phi= atan((x_dot+(Zeta*Wn*x0))/(x0*Wn*((1-(Zeta^2))^0.5)));
Wd= ((1-(Zeta^2))^0.5)*Wn;
x_05 = @(t) X*(exp(-Zeta*Wn*t))* cos((Wd*t)-phi);
Zeta = 2;
C1=x0;
C2=x_dot+Wn*x0;
x_2= @(t) C1*exp(-Zeta+sqrt(Zeta^2-1)*Wn*t)+C2*exp(-Zeta-sqrt(Zeta^2-1)*Wn*t);
figure(1)
fplot(x_0,[0 1],'b')
hold on
fplot(x_05,[0 1],'r')
fplot(x_1,[0 1],'g')
fplot(x_2,[0 1],'k')
hold off
legend('Zeta = 0','Zeta = 0.5','Zeta = 1','Zeta = 2')
axis([0 1 -0.5 0.5])
This way you can plot them all.
Best Answer