I can't plot a function I created with respect for time

1 次查看(过去 30 天)
Hello, I created this function "x(t)" with the given variables. Now I want to plot this function "x(t)" with respect to time and its not letting me.
%% 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= (4*m*k)^0.5;
Cc= (2*m*Wn);
Zeta= c/Cc
%% Solution Part B
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)
Please help

回答(1 个)

Star Strider
Star Strider 2020-2-22
You need to code it as an anonymous function. See Anonymous Functions for details.
Specifically:
x = @(t) X.*(exp(-Zeta.*Wn.*t)).* cos((Wd.*t)-phi)
Also, use element-wise operations just to be safe, unless you want to do matrix operations. See Array vs. Matrix Operations for those details.
Unfortunately, when I tried to plot it, it was Inf everywhere. You need to solve that problem. Note that ‘X’ is Inf as well, so that is likely the reason. .

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by