MATLAB:如何在给定数字数组的情况下评估符号函数,并返回结果数组?

时间:2014-11-26 22:47:45

标签: matlab

我的代码在MATLAB中看起来像这样:

nn = 0:50;
syms n z X H Y
X = 1/(1+1/z);
H = (2+2/z)/(1-0.8/z);
Y = X*H;
x = iztrans(X,z,n);
y = iztrans(Y,z,n);
xx = subs(X, n, nn);
yy = subs(Y, n, nn);

但是,我收到了这个错误:

Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input
expression into a double array.
If the input expression contains a symbolic variable,
use the VPA function instead.

正确的方法是什么,以便根据nn返回整个数组?

1 个答案:

答案 0 :(得分:2)

matlabFunction是你的朋友!这是一个非常有用的功能,我建议您查看文档,以便在其他情况下应用它。它将符号表达式转换为匿名函数,该函数执行元素操作,因此您可以输入矩阵。

nn = 0:50;
syms n z X H Y
X = 1/(1+1/z);
H = (2+2/z)/(1-0.8/z);
Y = X*H;
x = iztrans(X,z,n);
y = iztrans(Y,z,n);
Xfunc=matlabFunction(X);
Yfunc=matlabFunction(Y);
xx=Xfunc(nn)
yy=Yfunc(nn)