【发布时间】:2011-05-24 02:37:13
【问题描述】:
我正在尝试在 MATLAB 中创建一个函数,它将括号扩展为 n 的幂,其中 n 是自然数。这是我目前所拥有的:
function expandb = expandb(x,y,n)
z = my_bincoeff1(n);;
syms v x y
v=1:n+1
for i=1:n+1
v(i)=z(i)*x.^(n-i+1)*y.^(i-1);
end
a=0
for i=1+n+1
a=a+v(i)
end
expandb = a;
当我运行它时出现这个错误:
??? 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 ==> expandb at 6
v(i)=z(i)*x.^(n-i+1)*y.^(i-1);
那么如何在一个数组中存储 2 个变量呢?
【问题讨论】:
-
expandb应该是符号变量还是数字的函数? -
应该是2个变量的函数。假设我必须扩展 (2x+3y)^4 我会写 expandb(2x,3y,4) 并且答案的形式是 (2x)^4+...
-
有什么理由不想使用函数EXPAND,即expand((2*x+3*y)^4);?
标签: arrays function variables matlab binomial-coefficients