Error using plot Data must be numeric, datetime, duration or an array convertible to double.
116 views (last 30 days)
Show older comments
Commented: Walter Roberson on 6 Jan 2022
WHY PLOT GIVE ME THIS ERROR???: Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
syms s t
Gs=0.98/(s.^2 +0.5*s +0.49);
Looks like plot can't handle symbolic variables. (Note that plotting anything requires you to specify the range of the independent variable, and you haven't done so anywhere in your code snippet.) fplot may work better for you.
Sorry about that. I don't actually use symbolics, so I may not be able to help you. There's probably a special plotting function just for symbolic variables. Have you tried browsing the help for the symbolic toolbox to look for examples?
You cannot plot that, at least not in any straight forward way
Just because you can construct an arbitrary transfer function does not mean that there is a known inverse laplace transform of it.
You cannot even do the simple part
Us = exp(s*50);
If you examine this, you will see that exp(s*50) is the transform for a delay of -50 (negative 50) -- but a delay of -50 is a forecast of what will happen 50 in the future, which you cannot do with laplace transform.
You gave us a problem statement in https://www.mathworks.com/matlabcentral/answers/1623710-error-using-plot-data-must-be-numeric-datetime-duration-or-an-array-convertible-to-double#comment_1922090 that has nothing to do with Us, only with Gs. I showed you how to plot the response of an input signal and a transfer function. It does not matter how complex the transfer function is or how you build it up, the plotting mechanism is the same.
If you need to include that particular Us... then you cannot. Your Us requires future prediction. But if you were using a positive delay instead of a negative delay:
T = 100;
t = 0:0.01:3*T;
u = cos(t*2*pi/T).^2; %your signal
plot(t, u); xlim([-10 3*T+10]); ylim([-1.1 1.1])
s = tf('s');
Us = (1/(s^2+1))*(2-exp(-7*s))
Gs = sqrt(2)/ (s^3 + 2*s^2 + 3*s^1 + 4*s^0) %your transfer function
Y = Us * Gs
response = lsim(Y, u, t);
Note: it is deliberate that I used different transfer functions than in your homework. I am showing you the method, not giving you the answer to your homework.
Find more on Get Started with Symbolic Math Toolbox 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!