matlab多项式7M文件举例.doc_第1页
matlab多项式7M文件举例.doc_第2页
matlab多项式7M文件举例.doc_第3页
matlab多项式7M文件举例.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

M文件举例本章说明了在精通MATLAB工具箱 中两个函数。这些函数说明了本章所论述的多项式概念和如何写M文件函数。关于M文件的更多信息,参阅第8章。在讨论M文件函数的内部结构之前,我们考虑这些函数做些什么。 n%earlier datan =0.000010.000020.0000 b%earlier datab =-20-140-320-260 mmpsim(n)%strip away negligible leading termans =10.000020.0000 mmp2str(b)%convert polynomial to stringans =-20s3 - 140s2 - 320s1 - 260 mmp2str(b , x )ans =-20x3 - 140x2 - 320x1 - 260 mmp2str(b , , 1)ans =-20*(s3 + 7s2 + 16s1 + 13) mmp2str(b , x , 1)ans =-20*(x3 + 7x2 + 16x1 + 13)这里函数mmpsim删除在多项式n中近似为零的第一个系数。函数mmp2str把数值多项式变换成等价形式的字符串表达式。该两个函数的主体是:function y=mmpsim(x,tol)%MMPSIM Polynomial Simplification,Strip Leading Zero Terms.%MMPSIM(A) Delets leading zeros and small coefficients in the %polynomial A(s). Coefficients are considered small if their %magnitude is less than both one and norm(A)*1000*eps.%MMPSIM(A,TOL) uses TOL for its smallness tolerance.%Copyright (c) 1996 by Prentice-Hall,Inc.if nargin2, tol=norm(x)*1000*eps; endx=x(:). ;%make sure input is a row i=find(abs(x).99&abs(x)tol) ;%find insignificant indicesx(i)=zeros(1, length(i) ;%set them to zeroi=find(x=0) ;%find significant indicesif isempty(i)y=0 ;%extreme case: nothing left!elsey=x(i(1) : length(x) ;%start with first termend%and go to end of polynomialfunction s=mmp2str(p,v,ff)%MMP2STR Polynomial Vector to String Conversion.%MMP2STR(P) converts the polynomial vector P into a string.%For example: P = 234 becomes the string 2s2 + 3s + 4 %MMP2STR(P,V) generates the string using the variable V%instead of s. MMP2STR(234, z ) becomes 2z2 + 3z + 4 %MMP2STR(P,V,1) factors the polynomial into the product of a%constant and a monic polynomial.%MMP2STR(234,1) becomes 2(s2 + 1.5s + 2) %Copyright (c) 1996 by Prentice-Hall,Inc.if nargin3, ff=0; end%factored form is Falseif nargin 2, v= s ; end%default variable is s if isempty(v), v= s ; end%default variable is s v=v(1) ;%variable must be scalar p=mmpsim(p) ;%strip insignificant termsn=length(p) ;if ff%put in factored formK=p(1) ; Ka=abs(K) ; p=p/K;if abs(K-1)1e-4pp=; pe= ;elseif abs(K+1)1e-4pp= -( ; pe= ) ;elseif abs(Ka-round(Ka)=1e-5*Kapp=sprintf( %.0f , K) *( ; pe= ) ;elsepp=sprintf( %.4g , K) *( ; pe= ) ;endelse%not factored formK=p(1);pp=sprintf( %.4g , K) ;pe=;endif n=1%polynomial is just a constants=sprintf( %.4g ,K);returnends=pp v sprintf( %.0f ,n-1);%begin string constructionfor i=2:n-1%catenate center terms in polynomialif p(i)0, pm= - ;else,if p(i)0,pm= ;endif p(i)= =1,pp= ; else,pp=sprintf( %.4g , abs(p(i) ;endif p(i) =0,s=spmppv sprint

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论