中西贯通:matlab如何求解待定系数的问题

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 05:44:12
matlab怎么用待定系数法?
如:已知:2*x^3+3*x^2+21*x+4=a*x^3+b*x^2+c*x+d
利用待定系数法可以很容易的得出abcd的值,如何用matlab实现呢?
谢谢

If all coefficients are numerical, use function: sym2poly()

>> syms x
>> f=2*x^3+3*x^2+21*x+4;
>> sym2poly(f)

ans =

2 3 21 4

If there is any symbolic coefficient, use function: coeffs()

>> syms x a;
>> f=3*a*x^2+2*x^3+21*x+4;
>> [c,l]=coeffs(f,'x')

c =

[ 4, 21, 2, 3*a]

l =

[ 1, x, x^3, x^2]

Function expand() is sometimes useful.

>> syms x a
>> [c l]=coeffs(expand((a+x)^2),'x')

c =

[ a^2, 2*a, 1]

l =

[ 1, x, x^2]