arrays - Matlab中数值数组和符号数组的乘法

标签 arrays matlab symbolic-math

我有以下代码:

a=zeros(1,3);
syms x
y=zeros(1,3);
for j = 1:3
    a = [zeros(1,j-1) 1 zeros(1,3-j)];
    y(1,j)=x*a(1,j);
    display(y(1,j));
end;

我想为每次迭代提供一个像 [0 x 0] 这样的数组。但是,相反,它给了我以下错误:

The following error occurred converting from sym to double:
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.

Error in 
Untitled123 (line 6)
y(1,j)=x*a(1,j);

有什么建议吗?

最佳答案

问题在于您将 y 分配为数字(浮点)数组,而不是符号数组。 a 是数字,但是当您将其乘以 x 时,结果将变为符号。由于 x 是符号变量而不是符号值,因此 Matlab 无法执行自动转换回 double 。您可以像这样分配y:

y = sym(zeros(1,3));

关于arrays - Matlab中数值数组和符号数组的乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21080248/

相关文章:

java - 查找泛型数组中的最大元素及其位置,并返回包含两者的数组

arrays - Vertex和Index数据解析效率低下,寻找更高效的方法

string - MATLAB 是否有字符串的 strip 函数?

matlab 键盘快捷键 : move cursor from editor to command window

python - 有没有一种矢量化的方法来计算 sympy 中的梯度?

c - C语言中如何区分int数组中的空和0?

C-GCC 编译器中的字符数组

python - 如何: CVXPY Matrix Inequality Constraints

java - 设计符号方程求解器

Matlab - 三角函数的乘积简化