MATLAB Answers

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

1 view (last 30 days)
Areg Arzoomanian
Areg Arzoomanian on 22 Feb 2020
Answered: Star Strider on 22 Feb 2020
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


Sign in to comment.

Answers (1)

Star Strider
Star Strider on 22 Feb 2020
You need to code it as an anonymous function. See Anonymous Functions for details.
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. .


Sign in to comment.




Community Treasure Hunt

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

Start Hunting!