Error using plot Data must be numeric, datetime, duration or an array convertible to double.

조회 수: 124 (최근 30일)
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
Star Strider
Star Strider 2022년 1월 6일
Try using fplot instead for symbolic plots —
%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 = 
Ys = collect(Ys,exp(50*s))
Ys = 
yt=ilaplace(Ys,s,t)
yt = 
yt = vpa(yt, 5)
yt = 
figure
fplot(yt, [min(tf) max(tf)])
grid
Warning: Error updating FunctionLine.

The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing remaining symbolic function calls into double array. Argument must be expression that evaluates to number.
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.)
.
Pablo Álvarez García
Pablo Álvarez García 2022년 1월 6일
The exercise asks me to represent the response to a square wave of amplitude 1 and period 100 of the transfer function: Gs=0.98/(s^2 +6.55*s +0.49);
Do you know how to do it?

댓글을 달려면 로그인하십시오.

답변 (2개)

Ilya Gurin
Ilya Gurin 2022년 1월 6일
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
Pablo Álvarez García
Pablo Álvarez García 2022년 1월 6일
Warning: Error updating ParameterizedFunctionLine.
The following error was reported evaluating the function in FunctionLine update: Unable to convert expression containing remaining
symbolic function calls into double array. Argument must be expression that evaluates to number.
Ilya Gurin
Ilya Gurin 2022년 1월 6일
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
Walter Roberson 2022년 1월 6일
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)
ans = 
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
Pablo Álvarez García
Pablo Álvarez García 2022년 1월 6일
but it isnt the response Ys=Gs*Us. That is what i want to represent
Walter Roberson
Walter Roberson 2022년 1월 6일
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))
Us = A = x1 x2 x1 0 -1 x2 1 0 B = u1 x1 1 x2 0 C = x1 x2 y1 0 1 D = u1 y1 0 (values computed with all internal delays set to zero) Internal delays (seconds): 7 Continuous-time state-space model.
Gs = sqrt(2)/ (s^3 + 2*s^2 + 3*s^1 + 4*s^0) %your transfer function
Gs = 1.414 --------------------- s^3 + 2 s^2 + 3 s + 4 Continuous-time transfer function.
Y = Us * Gs
Y = A = x1 x2 x3 x4 x5 x1 0 -1 0 0 0.7071 x2 1 0 0 0 0 x3 0 0 -2 -1.5 -2 x4 0 0 2 0 0 x5 0 0 0 1 0 B = u1 x1 0 x2 0 x3 1 x4 0 x5 0 C = x1 x2 x3 x4 x5 y1 0 1 0 0 0 D = u1 y1 0 (values computed with all internal delays set to zero) Internal delays (seconds): 7 Continuous-time state-space model.
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by