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

135 visualizzazioni (ultimi 30 giorni)
Pablo Álvarez García il 6 Gen 2022
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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Pablo Álvarez García il 6 Gen 2022
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?

Accedi per commentare.

### Risposte (2)

Ilya Gurin il 6 Gen 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 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Ilya Gurin il 6 Gen 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?

Accedi per commentare.

Walter Roberson il 6 Gen 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)
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 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Walter Roberson il 6 Gen 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;
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.

Accedi per commentare.

### Categorie

Scopri di più su Spectral Measurements in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!