⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch4_1_4.htm

📁 一个不错的matlab工程实际问题的解决方法
💻 HTM
字号:
<HTML>

<HEAD>

<TITLE> 多项式函数 </TITLE>



<META NAME="GENERATOR" CONTENT="Internet Assistant for Microsoft Word 2.0z">

</HEAD>

<BODY BACKGROUND="bg0000.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/bg0000.gif">

<H1><FONT SIZE=6 COLOR=#0000FF>4.1.4 多项式函数 </FONT></H1>

<HR>

<P>

在工程及科学分析上,多项式常被用来模拟一个物理现象的解析函数,我们在第九章所介绍的「曲线契合」

即是一个这方面的应用。之所以采用多项式,是因为它很容易计算。在这章中我们将说明如何做多项式的计

算及解多项式的根。 <BR>

<P>

令<I>p</I>(<I>x</I>) 代表一个多项式如下

<P>

<IMG SRC="img00008.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00008.gif">

<P>

MATLAB 以一最简便方式代表上述的多项式 <FONT COLOR=#FF0000>p=[1

4 -7 -10]</FONT>,其中的数值是多项式的各阶项(从高到低)的 各个系数,其实<FONT COLOR=#FF0000>p</FONT>

也是一个阵列不过是用以代表这个多项式。 <BR>

<P>

有了多项式的表示式后,我们即可来计算其函数值。假设要计算一组数据<FONT COLOR=#FF0000>x</FONT>对应的多项式值,依照一般的函数

计算须以下列式子计算:

<P>

<FONT COLOR=#FF0000>&gt;&gt; p=x.^3+4*x.^2-7*x-10</FONT>

<P>

为了能直接运用多项式,可以用函数 <FONT COLOR=#FF0000>polyval</FONT>直接做运算,语法为

<FONT COLOR=#FF0000>polyval(p,x)</FONT>,其中<FONT COLOR=#FF0000>p</FONT>

即是代表多项式各阶系数 的阵列。因此

<P>

<FONT COLOR=#FF0000>&gt;&gt; x=linspace(-1,3);</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; p=[1 4 7 -10];</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; v=polyval(p,x);<BR>

</FONT>

<P>

我们接著说明如何对二个多项式做加减乘除运算,以及对多项式微分。当二个多项式间要做加减乘除时,加

减运算可以直接进行。假设有二个多项式<IMG SRC="img00009.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00009.gif">

和 <IMG SRC="img00010.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00010.gif"> 定义如下:

<P>

<IMG SRC="img00011.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00011.gif">

<P>

如果多项式 <IMG SRC="img00012.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00012.gif"> 为上述二多项式相加,即

<IMG SRC="img00013.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00013.gif">,因此

<P>

<IMG SRC="img00014.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00014.gif">

<P>

如果是二多项式相减得到的多项式为 <IMG SRC="img00015.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00015.gif">

<P>

<IMG SRC="img00016.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00016.gif"><BR>

<P>

而将两个多项式相乘可以得到一新的多项式<IMG SRC="img00017.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00017.gif">:

<P>

<IMG SRC="img00018.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00018.gif">

<P>

如果是两个多项式相除,即<IMG SRC="img00019.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00019.gif">:

<P>

<IMG SRC="img00020.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00020.gif">

<P>

上述二个运算式不能直接运算,须要另外定义函数<FONT COLOR=#FF0000>conv</FONT>做乘法运算以及函数<FONT COLOR=#FF0000>deconv</FONT>做除法运算。当二多项式

相乘,在数学上等于二个阵列做旋积(convolution)运算(因为我们是以阵列来代表一个多项式的各阶系数),

因此可利用<FONT COLOR=#FF0000>conv</FONT>函数做乘法运算,其语法为<FONT COLOR=#FF0000>conv(a,b)</FONT>,其中<FONT COLOR=#FF0000>a</FONT>,<FONT COLOR=#FF0000>

b</FONT>代表二个多项式的阵列。而二多项式相除就相 当于反旋积(de-convolution)

运算,因此有 <TT>deconv</TT> 函数,其语法稍有不同 <FONT COLOR=#FF0000>[q,r]=deconv(a,b)</FONT>,其中<FONT COLOR=#FF0000>q</FONT>,<FONT COLOR=#FF0000>r</FONT>分别代表整

除多项式及余数多项式。<BR>

<P>

以下就介绍相关范例,来说明二个多项式的加减乘除运算:

<P>

<FONT COLOR=#FF0000>&gt;&gt; a=[1 2 3 4]; b=[1 4 9 16];</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; c=a+b</FONT>

<P>

<FONT COLOR=#FF0000>c =</FONT>

<P>

<FONT COLOR=#FF0000>2 6 12 20</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; d=a-b</FONT>

<P>

<FONT COLOR=#FF0000>d =</FONT>

<P>

<FONT COLOR=#FF0000>0 -2 -6 -12</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; e=conv(a,b)</FONT>

<P>

<FONT COLOR=#FF0000>e =</FONT>

<P>

<FONT COLOR=#FF0000>1 6 20 50 75 84 64</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; g=e+[0 0 0 c]</FONT>

<P>

<FONT COLOR=#FF0000>g =</FONT>

<P>

<FONT COLOR=#FF0000>1 6 20 52 81 96 84</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; [f,r]=deconv(e,b)</FONT>

<P>

<FONT COLOR=#FF0000>f =</FONT>

<P>

<FONT COLOR=#FF0000>1 2 3 4</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>0 0 0 0 0 0 0 % 因为是整除所以余数多项式的各系数皆为零</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; [h,r]=deconv(g,a)</FONT>

<P>

<FONT COLOR=#FF0000>f =</FONT>

<P>

<FONT COLOR=#FF0000>1 4 9 18</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>0 0 0 0 2 6 12 % 余数多项式为 2*x^2 + 6*x

+ 12<BR>

</FONT>

<P>

一个多项式视其阶数而定,它的根可以有一个到数个,可能为实数也可能是复数。要求一高阶多项式的根

往往须借助数值方法,所幸MATLAB已将这些数值方法写成一函数<FONT COLOR=#FF0000>roots(p)</FONT>,我们只要输入多项式的各阶系

数(以<FONT COLOR=#FF0000>p</FONT>代表)即可求解到对应的根。

<P>

<FONT COLOR=#FF0000>&gt;&gt; p=[1 3 2];</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; r=roots(p)</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>-2</FONT>

<P>

<FONT COLOR=#FF0000>-1</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; p=[1 -12 0 25 116]; % 注意二阶项系数为零须要输入,否则多项式的阶数就不对</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; r=roots(p) % 有实数根及复数根</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>11.7473</FONT>

<P>

<FONT COLOR=#FF0000>2.7028</FONT>

<P>

<FONT COLOR=#FF0000>-1.2251 + 1.4672i</FONT>

<P>

<FONT COLOR=#FF0000>-1.2251 - 1.4672i<BR>

</FONT>

<P>

与 <FONT COLOR=#FF0000>roots</FONT> 相关的函数尚有 <FONT COLOR=#FF0000>poly</FONT>,

<FONT COLOR=#FF0000>real</FONT>,这二个函数的用途是要验算求解的根展开能求得原多项式。

例如有一个二次方程式的根为 2, 1,则以下式计算原多项式

<P>

<IMG SRC="img00021.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img4/img00021.gif">

<P>

<FONT COLOR=#FF0000>poly</FONT>函数就是在求出多项式的各阶系数,其语法为

<FONT COLOR=#FF0000>poly(r)</FONT>,其中 <FONT COLOR=#FF0000>r

</FONT>是代表根的阵列。而 <FONT COLOR=#FF0000>real</FONT>则是用来去除因计算时产生的假虚部系数,为何会有此种情形请参考以下的例子。

<P>

<FONT COLOR=#FF0000>&gt;&gt; r=[-2 -1];</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; pp=poly(r) % pp=(x+2)(x+1)=x^2+3x+2</FONT>

<P>

<FONT COLOR=#FF0000>pp =</FONT>

<P>

<FONT COLOR=#FF0000>1 3 2</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; p=[1 -4 6 -4];</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; r=roots(p)</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>2.0000 1.0000 + 1.0000i 1.0000 - 1.0000i </FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; pp=poly(r) % 这个多项式的系数与原多项式

p 相同</FONT>

<P>

<FONT COLOR=#FF0000>pp =</FONT>

<P>

<FONT COLOR=#FF0000>1 -4 6 -4</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; pp=[1 7 12 9]; % 再看另一个多项式</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; r=roots(pp)</FONT>

<P>

<FONT COLOR=#FF0000>r =</FONT>

<P>

<FONT COLOR=#FF0000>-4.9395 </FONT>

<P>

<FONT COLOR=#FF0000>-1.0303 + 0.8721i</FONT>

<P>

<FONT COLOR=#FF0000>-1.0303 - 0.8721i</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; pp=poly(r) % 注意因计算的误差会有假虚部产生</FONT>

<P>

<FONT COLOR=#FF0000>pp =</FONT>

<P>

<FONT COLOR=#FF0000>1.0000 7.0000 12.0000 9.0000 + 0.0000i</FONT>

<P>

<FONT COLOR=#FF0000>&gt;&gt; pp=real(pp) % 可以real将假虚部去除,将原多项式还原</FONT>

<P>

<FONT COLOR=#FF0000>pp =</FONT>

<P>

<FONT COLOR=#FF0000>1.0000 7.0000 12.0000 9.0000<BR>

</FONT>

<HR>

<P>

<A HREF="ch4_1_3.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch4_1_3.htm"><IMG SRC="lastpage.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/lastpage.gif" BORDER=0></A>

<A HREF="ch4_2.htm" tppabs="http://166.111.167.223/computer/cai/matlabjc/ch4_2.htm"><IMG SRC="nextpage-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/nextpage.gif" BORDER=0 HSPACE=10></A>

<A HREF="index.html" tppabs="http://166.111.167.223/computer/cai/matlabjc/index.html"><IMG SRC="outline-1.gif" tppabs="http://166.111.167.223/computer/cai/matlabjc/img/outline.gif" BORDER=0 HSPACE=6></A>

<BR>

<FONT SIZE=2 COLOR=#FF00FF>上一页 下一页 讲义大纲 </FONT>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -