1
我想在MATLAB中创建一个函数,它将展开一个括号给n的幂,其中n是一个自然数。这是我到目前为止有:数组中的2个变量
??? 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个变量数组:
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;
当我运行它,我得到这个错误?
应该'expandb'是一个象征性的变量或多项功能? – Jacob 2010-12-12 01:27:52
它应该是2个变量的函数。假设我必须展开(2x + 3y)^ 4我会写expandb(2x,3y,4)并且答案将是(2x)^ 4 + ... – Mobix 2010-12-12 02:17:00
的答案是否有原因您不需要想要使用函数[EXPAND](http://www.mathworks.com/help/toolbox/symbolic/expand.html),即展开((2 * x + 3 * y)^ 4);? – gnovice 2010-12-12 03:04:35