




已閱讀5頁,還剩28頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第四章 MATLAB 的數(shù)值計(jì)算功能Chapter 4: Numerical computation of MATLAB一、多項(xiàng)式(Polynomial)1多項(xiàng)式的表達(dá)與創(chuàng)建(Expression and Creating of polynomial)(1) 多項(xiàng)式的表達(dá)(expression of polynomial)_Matlab用行矢量表達(dá)多項(xiàng)式系數(shù)(Coefficient),各元素按變量的降冪順序排列,如多項(xiàng)式為:P(x)=a0xn+a1xn-1+a2xn-2an-1x+an則其系數(shù)矢量(Vector of coefficient)為:P=a0 a1 an-1 an如將根矢量(Vector of root)表示為:ar= ar1 ar2 arn則根矢量與系數(shù)矢量之間關(guān)系為:(x-ar1)(x- ar2) (x- arn)= a0xn+a1xn-1+a2xn-2an-1x+an(2)多項(xiàng)式的創(chuàng)建(polynomial creating)a)系數(shù)矢量的直接輸入法利用poly2sym函數(shù)直接輸入多項(xiàng)式的系數(shù)矢量,就可方便的建立符號(hào)形式的多項(xiàng)式。例:創(chuàng)建多項(xiàng)式x3-4x2+3x+2poly2sym(1 -4 3 2)ans =x3-4*x2+3*x+2POLY Convert roots to polynomial. POLY(A), when A is an N by N matrix, is a row vector with N+1 elements which are the coefficients of the characteristic polynomial, DET(lambda*EYE(SIZE(A) - A) . POLY(V), when V is a vector, is a vector whose elements are the coefficients of the polynomial whose roots are the elements of V . For vectors, ROOTS and POLY are inverse functions of each other, up to ordering, scaling, and roundoff error.b) 由根矢量創(chuàng)建多項(xiàng)式通過調(diào)用函數(shù) p=poly(ar)產(chǎn)生多項(xiàng)式的系數(shù)矢量, 再利用poly2sym函數(shù)就可方便的建立符號(hào)形式的多項(xiàng)式。注:(1)根矢量元素為n ,則多項(xiàng)式系數(shù)矢量元素為n+1;(2)函數(shù)poly2sym(pa) 把多項(xiàng)式系數(shù)矢量表達(dá)成符號(hào)形式的多項(xiàng)式,缺省情況下自變量符號(hào)為x,可以指定自變量。(3)使用簡單繪圖函數(shù)ezplot可以直接繪制符號(hào)形式多項(xiàng)式的曲線。例 1:由根矢量創(chuàng)建多項(xiàng)式。將多項(xiàng)式(x-6)(x-3)(x-8)表示為系數(shù)形式 a=6 3 8 %根矢量pa=poly(a) %求系數(shù)矢量ppa=poly2sym(pa) %以符號(hào)形式表示原多項(xiàng)式ezplot(ppa,-50,50)pa = 1 -17 90 -144ppa =x3-17*x2+90*x-144注:含復(fù)數(shù)根的根矢量所創(chuàng)建的多項(xiàng)式要注意:(1)要形成實(shí)系數(shù)多項(xiàng)式,根矢量中的復(fù)數(shù)根必須共軛成對(duì); (2)含復(fù)數(shù)根的根矢量所創(chuàng)建的多項(xiàng)式系數(shù)矢量中,可能帶有很小的虛部,此時(shí)可采用取實(shí)部的命令(real)把虛部濾掉。進(jìn)行多項(xiàng)式的求根運(yùn)算時(shí),有兩種方法,一是直接調(diào)用求根函數(shù)roots,poly和 roots 互為逆函數(shù)。另一種是先把多項(xiàng)式轉(zhuǎn)化為伴隨矩陣,然后再求其特征值,該特征值即是多項(xiàng)式的根。例 3: 由給定復(fù)數(shù)根矢量求多項(xiàng)式系數(shù)矢量。r=-0.5 -0.3+0.4i -0.3-0.4i;p=poly(r)pr=real(p)ppr=poly2sym(pr)p = 1.0000 1.1000 0.5500 0.1250pr = 1.0000 1.1000 0.5500 0.1250ppr =x3+11/10*x2+11/20*x+1/8c) 特征多項(xiàng)式輸入法用poly函數(shù)可實(shí)現(xiàn)由矩陣的特征多項(xiàng)式系數(shù)創(chuàng)建多項(xiàng)式。條件:特征多項(xiàng)式系數(shù)矢量的第一個(gè)元素必須為一。例 2: 求三階方陣A的特征多項(xiàng)式系數(shù),并轉(zhuǎn)換為多項(xiàng)式形式。a=6 3 8;7 5 6; 1 3 5Pa=poly(a) %求矩陣的特征多項(xiàng)式系數(shù)矢量Ppa=poly2sym(pa)Pa = 1.0000 -16.0000 38.0000 -83.0000Ppa =x3-17*x2+90*x-144注:n 階方陣的特征多項(xiàng)式系數(shù)矢量一定是n +1階的。注:(1)要形成實(shí)系數(shù)多項(xiàng)式,根矢量中的復(fù)數(shù)根必須共軛成對(duì); (2)含復(fù)數(shù)根的根矢量所創(chuàng)建的多項(xiàng)式系數(shù)矢量中,可能帶有很小的虛部,此時(shí)可采用取實(shí)部的命令(real)把虛部濾掉。進(jìn)行多項(xiàng)式的求根運(yùn)算時(shí),有兩種方法,一是直接調(diào)用求根函數(shù)roots,poly和 roots 互為逆函數(shù)。另一種是先把多項(xiàng)式轉(zhuǎn)化為伴隨矩陣,然后再求其特征值,該特征值即是多項(xiàng)式的根。例 4: 將多項(xiàng)式的系數(shù)表示形式轉(zhuǎn)換為根表現(xiàn)形式。求 x3-6x2-72x-27的根a=1 -6 -72 -27r=roots(a)r = 12.1229 -5.7345 -0.3884MATLAB約定,多項(xiàng)式系數(shù)矢量用行矢量表示,根矢量用列矢量表示。1. 多項(xiàng)式的乘除運(yùn)算(Multiplication and division of polynomial)多項(xiàng)式乘法用函數(shù)conv(a,b)實(shí)現(xiàn), 除法用函數(shù)deconv(a,b)實(shí)現(xiàn)。例1:a(s)=s2+2s+3, b(s)=4s2+5s+6,計(jì)算 a(s)與 b(s)的乘積。a=1 2 3; b=4 5 6;c=conv(a,b)cs=poly2sym(c,s)c = 4 13 28 27 18cs =4*s4+13*s3+28*s2+27*s+18例2: 展開(s2+2s+2)(s+4)(s+1) (多個(gè)多項(xiàng)式相乘)c=conv(1,2,2,conv(1,4,1,1)cs=poly2sym(c,s) %(指定變量為s)c = 1 7 16 18 8cs =s4+7*s3+16*s2+18*s+8例2:求多項(xiàng)式s4+7*s3+16*s2+18*s+8分別被(s+4),(s+3)除后的結(jié)果。c=1 7 16 18 8;q1,r1=deconv(c,1,4) %q商矢量, r余數(shù)矢量q2,r2=deconv(c,1,3)cc=conv(q2,1,3) %對(duì)除(s+3)結(jié)果檢驗(yàn)test=(c-r2)=cc)q1 = 1 3 4 2r1 = 0 0 0 0 0q2 = 1 4 4 6r2 = 0 0 0 0 -10cc = 1 7 16 18 18test = 1 1 1 1 11. 其他常用的多項(xiàng)式運(yùn)算命令(Other computation command of polynomial)pa=polyval(p,s) 按數(shù)組運(yùn)算規(guī)則計(jì)算給定s時(shí)多項(xiàng)式p的值。pm=polyvalm(p,s) 按矩陣運(yùn)算規(guī)則計(jì)算給定s時(shí)多項(xiàng)式p的值。r,p,k=residue(b,a) 部分分式展開,b,a分別是分子分母多項(xiàng)式系數(shù)矢量,r,p,k分別是留數(shù)、極點(diǎn)和直項(xiàng)矢量p=polyfit(x,y,n) 用n階多項(xiàng)式擬合x,y矢量給定的數(shù)據(jù)。polyder(p) 多項(xiàng)式微分。注: 對(duì)于多項(xiàng)式b(s)與不重根的n階多項(xiàng)式a(s)之比,其部分分式展開為: 式中:p1,p2,pn稱為極點(diǎn)(poles),r1,r2,rn 稱為留數(shù)(residues),k(s)稱為直項(xiàng)(direct terms),假如a(s)含有m重根pj,則相應(yīng)部分應(yīng)寫成:RESIDUE Partial-fraction expansion (residues). R,P,K = RESIDUE(B,A) finds the residues, poles and direct term of a partial fraction expansion of the ratio of two polynomials B(s)/A(s). If there are no multiple roots,B(s) R(1) R(2) R(n) - = - + - + . + - + K(s) A(s) s - P(1) s - P(2) s - P(n)Vectors B and A specify the coefficients of the numerator and denominator polynomials in descending powers of s. The residuesare returned in the column vector R, the pole locations in column vector P, and the direct terms in row vector K. The number of poles is n = length(A)-1 = length(R) = length(P). The direct term coefficient vector is empty if length(B) n 可求出最小二乘解*欠定系統(tǒng):(Underdetermind system) m n, then only the first n columns of Q are computed.4. 特征值與特征矢量(Eigenvalues and eigenvectors).MATLAB中使用函數(shù)eig計(jì)算特征值和 特征矢量,有兩種調(diào)用方法:*e=eig(a), 其中e是包含特征值的矢量;*v,d=eig(a), 其中v是一個(gè)與a相同的nn階矩陣,它的每一列是矩陣a的一個(gè)特征值所對(duì)應(yīng)的特征矢量,d為對(duì)角陣,其對(duì)角元素即為矩陣a的特征值。例:計(jì)算特征值和特征矢量。a=34 25 15; 18 35 9; 41 21 9e=eig(a)v,d=eig(a)a = 34 25 15 18 35 9 41 21 9e = 68.5066 15.5122 -6.0187v = -0.6227 -0.4409 -0.3105 -0.4969 0.6786 -0.0717 -0.6044 -0.5875 0.9479d = 68.5066 0 0 0 15.5122 0 0 0 -6.0187EIG Eigenvalues and eigenvectors.E = EIG(X) is a vector containing the eigenvalues of a square matrix X.V,D = EIG(X) produces a diagonal matrix D of eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that X*V = V*D.V,D = EIG(X,nobalance) performs the computation with balancing disabled, which sometimes gives more accurate results for certain problems with unusual scaling. If X is symmetric, EIG(X,nobalance) is ignored since X is already balanced.5. 奇異值分解.( Singular value decomposition).如存在兩個(gè)矢量u,v及一常數(shù)c,使得矩陣A滿足:Av=cu, Au=cv稱c為奇異值,稱u,v為奇異矢量。 將奇異值寫成對(duì)角方陣,而相對(duì)應(yīng)的奇異矢量作為列矢量則可寫成兩個(gè)正交矩陣U,V, 使得: AV=U, AU=V 因?yàn)閁,V正交,所以可得奇異值表達(dá)式: A=UV。一個(gè)m行n列的矩陣A經(jīng)奇異值分解,可求得m行m列的U, m行n列的矩陣和n行n列的矩陣V.。奇異值分解用svd函數(shù)實(shí)現(xiàn),調(diào)用格式為;u,s,v=svd(a) SVD Singular value decomposition.U,S,V = SVD(X) produces a diagonal matrix S, of the same dimension as X and with nonnegative diagonal elements in decreasing order, and unitary matrices U and V so that X = U*S*V.S = SVD(X) returns a vector containing the singular values.U,S,V = SVD(X,0) produces the economy size decomposition. If X is m-by-n with m n, then only the first n columns of U are computed and S is n-by-n.例: 奇異值分解。a=8 5; 7 3;4 6;u,s,v=svd(a) % s為奇異值對(duì)角方陣u = -0.6841 -0.1826 -0.7061 -0.5407 -0.5228 0.6591 -0.4895 0.8327 0.2589s = 13.7649 0 0 3.0865 0 0v = -0.8148 -0.5797 -0.5797 0.8148 五 數(shù)據(jù)分析(Data Analyaia)MATLAB對(duì)數(shù)據(jù)分析有兩條約定:(1) 若輸入量X是矢量,則不論是行矢量還是列矢量,運(yùn)算是對(duì)整個(gè)矢量進(jìn)行的; (2)若輸入量X是數(shù)組,(或稱矩陣),則命令運(yùn)算是按列進(jìn)行的。即默認(rèn)每個(gè)列是有一個(gè)變量的不同“觀察“所得的數(shù)據(jù)組成。 1. 基本統(tǒng)計(jì)命令 (表4-1)例: 做各種基本統(tǒng)計(jì)運(yùn)算。A=5 -10 -6 0;2 6 3 -3;-9 5 -10 11;-22 17 0 -19;-1 6 -4 4Amax=max(A) %找A各列的最大元素Amin=min(A) %找A各列的最小元素Amed=median(A) %找A各列的中位元素Amean=mean(A) %找A各列的平均值A(chǔ)std=std(A) %求A各列的標(biāo)準(zhǔn)差A(yù)prod=prod(A) %求A各列元素的積Asum=sum(A) %求A各列元素的和S=cumsum(A) %求A各列元素的累積和P=cumprod(A) %求A各列元素的累積j積I=sort(A) %使A的各列元素按遞增排列A = 5 -10 -6 0 2 6 3 -3 -9 5 -10 11 -22 17 0 -19 -1 6 -4 4Amax = 5 17 3 11Amin = -22 -10 -10 -19Amed = -1 6 -4 0Amean = -5.0000 4.8000 -3.4000 -1.4000Astd = 10.8397 9.6281 5.0794 11.1490Aprod = -1980 -30600 0 0Asum = -25 24 -17 -7S = 5 -10 -6 0 7 -4 -3 -3 -2 1 -13 8 -24 18 -13 -11 -25 24 -17 -7P = 5 -10 -6 0 10 -60 -18 0 -90 -300 180 0 1980 -5100 0 0 -1980 -30600 0 0I = -22 -10 -10 -19 -9 5 -6 -3 -1 6 -4 0 2 6 0 4 5 17 3 11求矩陣元素的最大值、最小值可用: Amax=max(maxA) 或 Amax=max(A(:), Amin=min(min(A) 或 Amin=min(A(:) 2協(xié)方差陣和相關(guān)陣(Covariance matrix and Correlation coefficients).(表 42)例: 計(jì)算協(xié)方差和相關(guān)陣。x=rand(10,3); y=rand(10,3);cx=cov(x) %求協(xié)方差陣cy=cov(y)cxy=cov(x,y) %求兩隨機(jī)變量的協(xié)方差px=corrcoef(x) %求相關(guān)陣pxy=corrcoef(x,y) %求兩隨機(jī)變量的(22)相關(guān)系數(shù)cx = 0.0483 -0.0066 0.0146 -0.0066 0.0283 0.0154 0.0146 0.0154 0.0978cy = 0.1177 0.0073 -0.0127 0.0073 0.0239 -0.0230 -0.0127 -0.0230 0.0772cxy = 0.0550 0.0023 0.0023 0.0697px = 1.0000 -0.1783 0.2118 -0.1783 1.0000 0.2934 0.2118 0.2934 1.0000pxy = 1.0000 0.0372 0.0372 1.0000COV Covariance matrix.COV(X), if X is a vector, returns the variance. For matrices, where each row is an observation, and each column a variable, COV(X) is the covariance matrix. DIAG(COV(X) is a vector of variances for each column, and SQRT(DIAG(COV(X) is a vector of standard deviations. COV(X,Y), where X and Y are vectors of equal length, is equivalent to COV(X(:) Y(:). COV(X) or COV(X,Y) normalizes by (N-1) where N is the number of observations. This makes COV(X) the best unbiased estimate of the covariance matrix if the observations are from a normal distribution.CORRCOEF Correlation coefficie
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度專業(yè)車庫租賃與物業(yè)管理合同
- 服裝批發(fā)市場(chǎng)垃圾清運(yùn)合同
- 2025年度多人共同經(jīng)營網(wǎng)店借款及利潤分配合同
- 二零二五年度玉器珠寶市場(chǎng)拓展與區(qū)域代理合同
- 2025年度安全無憂型個(gè)人租房合同
- 2025年度企業(yè)節(jié)能減排改造補(bǔ)貼協(xié)議書
- 2025年度員工心理健康關(guān)懷上班協(xié)議合同全新版
- 2025年度文化場(chǎng)館設(shè)施維護(hù)勞務(wù)協(xié)議書
- 2025年度影視演員場(chǎng)記助理職業(yè)素養(yǎng)培訓(xùn)聘用合同
- 2025年佳木斯職業(yè)學(xué)院單招職業(yè)技能測(cè)試題庫新版
- 2025年施工項(xiàng)目部《春節(jié)節(jié)后復(fù)工復(fù)產(chǎn)》工作實(shí)施方案 (3份)-75
- 礦山安全生產(chǎn)工作總結(jié)
- 小學(xué)教師培訓(xùn)課件:做有品位的小學(xué)數(shù)學(xué)教師
- U8UAP開發(fā)手冊(cè)資料
- 監(jiān)護(hù)人考試20241208練習(xí)試題附答案
- 證券公司裝修施工合同工程
- 人教版PEP三年級(jí)到六年級(jí)單詞以及重點(diǎn)句型
- 2024-2024年上海市高考英語試題及答案
- 中建總承包項(xiàng)目高支模專項(xiàng)施工方案含計(jì)算書
- 酒店住宿服務(wù)合同三篇
- 學(xué)校疫情防控學(xué)校傳染病疫情及突發(fā)公共衛(wèi)生事件報(bào)告制度
評(píng)論
0/150
提交評(píng)論