Plot all four functions
Show older comments
I need help. I have my four functions and if I run my code it only plots the first response not all four. Furthermore I don't know how to have all four plots on the same frame.
Thank you.
%% Givens
m=2; %kg
k=200; %N/m
x0=0.05; %meters
x_dot=2; %m/s
%% Solution Part A
Wn= (k/m)^0.5;
c= (2*m*Wn);
Cc= (2*m*Wn);
Zeta= c/Cc
%% Solution Part B
if Zeta==1
C1=x0;
C2=x_dot+Wn*x0;
x = @(t) (C1+C2*t)*exp(-Wn*t)
fplot(x,[0,1])
end
if 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 = @(t) X*(exp(-Zeta*Wn*t))* cos((Wd*t)-phi)
fplot(x,[0,1])
end
if 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 = @(t) X*(exp(-Zeta*Wn*t))* cos((Wd*t)-phi)
fplot(x,[0,1])
end
if Zeta==2
C1=x0;
C2=x_dot+Wn*x0;
x= @(t) C1*exp(-Zeta+sqrt(Zeta^2-1)*Wn*t)+C2*exp(-Zeta-sqrt(Zeta^2-1)*Wn*t)
fplot(x,[0,1])
end
%% Solution Part C
Accepted Answer
More Answers (1)
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!