Trying to use Stem() - Error message
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm trying to plot an output using Stem(). I solved for my transfer function symbolically, from my expected output in the time domain. I'm not sure how to go back to doing things numerically once I have all of my functions figured out.
I keep getting the errors:
Error using stem (line 40)
DOUBLE cannot convert the input expression into a double array.
Error in prog (line 30)
stem(t,y)
Ideally this should spit out a dirac comb with a period of omega. I'm still relatively new to Matlab, so any help would be appreciated! This is also a very rough version of the hopefully final code.
close all; clear all; clc;
syms t omega n A s lambda;
func = dirac(t - n*((2*pi)/omega));
y = symsum(func,n,0,10);
Y = laplace(y);
x = A*cos(omega*t)*exp(-lambda*t);
X = laplace(x);
H = piecewise(omega < 0, ((lambda + s)^2 + omega^2)/(A*(lambda + s)), 0 <= omega, (((lambda + s)^2 +...
omega^2)*(exp(-(2*pi*s)/omega) + exp(-(4*pi*s)/omega) + exp(-(6*pi*s)/omega) + exp(-(8*pi*s)/omega) +...
exp(-(10*pi*s)/omega) + exp(-(12*pi*s)/omega) + exp(-(14*pi*s)/omega) + exp(-(16*pi*s)/omega) +...
exp(-(18*pi*s)/omega) + exp(-(20*pi*s)/omega) + 1))/(A*(lambda + s)));
h = ilaplace(H);
y = ilaplace(X*H);
A = 5;
omega = 5;
lambda = 1;
t = linspace(0,20);
idx = y == Inf;
y(idx) = 1;
stem(t,y)
ylim([-.02 1.5])
xlabel('time')
ylabel
0 comentarios
Respuestas (1)
Elizabeth Reese
el 4 de Dic. de 2017
You can use the subs function in the Symbolic Math Toolbox to get the numerical values of y and t. Here is the link to the documentation for that function.
For example, take the y from the following line:
y = ilaplace(X*H);
Then you can evaluate:
tEval = linspace(0,20);
yEval = subs(y,{A,omega,lambda,t},{5,5,1,tEval})
yEval(yEval == Inf) = 1
stem(tEval,yEval)
ylim([-.02 1.5])
xlabel('time')
ylabel('y')
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!