当前位置:天才代写 > tutorial > Matlab教程 > Matlab多项式

Matlab多项式

2017-11-02 08:00 星期四 所属: Matlab教程 浏览:619


MATLAB暗示多项式为包括由下降幂分列的系数的行向量。 譬喻,方程式
Matlab多项式
可以暗示为 –

p = [1 7 0 -5 9];

评预计较多项式

多值函数用于评预计较指定值的多项式。 譬喻,要评估前面的多项式p,在x = 4,可利用以下代码 –

p = [1 7 0  -5 9];
polyval(p,4)

MATLAB执行上述语句返回以下功效 –

ans = 693

MATLAB还提供polyvalm函数用于评估矩阵多项式。 矩阵多项式是以矩阵为变量的多项式。

譬喻,下面建设一个方阵X并评估求值多项式p,在X

p = [1 7 0  -5 9];
X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8];
polyvalm(p, X)

MATLAB执行上述代码语句返回以下功效 –

ans =
        2307       -1769        -939        4499
        2314       -2376        -249        4695
        2256       -1892        -549        4310
        4570       -4532       -1062        9269

计较多项式的根

roots函数计较多项式的根。 譬喻,要计较多项式p的根,可参考以下语法 –

p = [1 7 0  -5 9];
r = roots(p)

MATLAB执行上述代码语句返回以下功效 –

r =
  -6.8661 + 0.0000i
  -1.4247 + 0.0000i
   0.6454 + 0.7095i
   0.6454 - 0.7095i

poly函数是roots函数的逆,并返回到多项式系数。 譬喻 –

p = [1 7 0  -5 9];
r = roots(p)
p2 = poly(r)

MATLAB执行上述代码语句返回以下功效 –

Trial>> p = [1 7 0  -5 9];
r = roots(p)
p2 = poly(r)

r =

  -6.8661 + 0.0000i
  -1.4247 + 0.0000i
   0.6454 + 0.7095i
   0.6454 - 0.7095i


p2 =

    1.0000    7.0000    0.0000   -5.0000    9.0000

多项式曲线拟合

polyfit函数用来查找一个多项式的系数,它切合最小二乘法中的一组数据。 假如xy包括要拟合到n度多项式的xy数据的两个向量,则获得通过拟合数据的多项式,参考代码 –

p = polyfit(x,y,n)

示例

建设剧本文件并键入以下代码 –

x = [1 2 3 4 5 6]; y = [5.5 43.1 128 290.7 498.4 978.67];  %data
p = polyfit(x,y,4)   %get the polynomial
% Compute the values of the polyfit estimate over a finer range, 
% and plot the estimate over the real data values for comparison:
x2 = 1:.1:6;          
y2 = polyval(p,x2);
plot(x,y,'o',x2,y2)
grid on

MATLAB执行上述代码语句返回以下功效 –

Trial>> x = [1 2 3 4 5 6]; y = [5.5 43.1 128 290.7 498.4 978.67];  %data
p = polyfit(x,y,4)   %get the polynomial
% Compute the values of the polyfit estimate over a finer range, 
% and plot the estimate over the real data values for comparison:
x2 = 1:.1:6;          
y2 = polyval(p,x2);
plot(x,y,'o',x2,y2)
grid on

p =

    4.1056  -47.9607  222.2598 -362.7453  191.1250

同时还输出一个图形 –

Matlab多项式

 

    关键字:

天才代写-代写联系方式