Error using plot Data must be numeric, datetime, duration or an array convertible to double.
77 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
WHY PLOT GIVE ME THIS ERROR???: Error using plot
Data must be numeric, datetime, duration or an array convertible to double.
%TAREA 5
close all
clear all
syms s t
T=100;
%w=2*pi*1/T;
tf=0:0.01:3*T;
Gs=0.98/(s.^2 +0.5*s +0.49);
%ut=square(2*pi*1/T*tf,50)
Us=(1/s)*(1-exp(s*50));
Ys=Gs*Us;
yt=ilaplace(Ys)
plot(t,yt)
2 comentarios
Star Strider
el 6 de En. de 2022
%TAREA 5
close all
clear all
syms s t
T=100;
%w=2*pi*1/T;
tf=0:0.01:3*T;
Gs=0.98/(s.^2 +0.5*s +0.49);
%ut=square(2*pi*1/T*tf,50)
Us=(1/s)*(1-exp(s*50));
Ys= Gs*Us;
Ys = partfrac(Ys)
Ys = collect(Ys,exp(50*s))
yt=ilaplace(Ys,s,t)
yt = vpa(yt, 5)
figure
fplot(yt, [min(tf) max(tf)])
grid
However, the exponential is what is causing the problems. That is simply a delay anyway, so go without it and perhaps use heaviside to simulate it on the plot.
Alternatively, do all this with the Control System Toolbox since it has the ability to deal with the exponential. (I have not tried that with this transfer function.)
.
Respuestas (2)
Ilya Gurin
el 6 de En. de 2022
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.
4 comentarios
Ilya Gurin
el 6 de En. de 2022
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?
Walter Roberson
el 6 de En. de 2022
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
syms s
Us = exp(s*50);
ilaplace(Us)
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.
4 comentarios
Walter Roberson
el 6 de En. de 2022
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);
plot(t, response)
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.
Ver también
Categorías
Más información sobre Get Started with Symbolic Math Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!