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