资源描述:
《流机MATLAB补充程序代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第八章endfunctions=mmp2str(p,v,ff)ifn==1%polynomialisjustaconstant%MMP2STRPolynomialVectortoStringConversion.s=sprintf('%.4g',K);%MMP2STR(P)convertsthepolynomialvectorPintoastring.return%Forexample:P=[234]becomesthestring'2s^2+3s+4'end%MMP2STR(P,V)genera
2、testhestringusingthevariableVs=[ppv'^'sprintf('%.0f',n-1)];%beginstringconstruction%insteadofs.MMP2STR([234],'z')becomes'2z^2+3z+4'%MMP2STR(P,V,1)factorsthepolynomialintotheproductofafori=2:n-1%catenatecentertermsin%constantandamonicpolynomial.polynom
3、ial%MMP2STR([234],[],1)becomes'2(s^2+1.5s+2)'ifp(i)<0,pm='-';else,ifp(i)<0,pm=';end%Copyright(c)1996byPrentice-Hall,Inc.ifp(i)==1,pp=[];else,pp=sprintf('%.4g',abs(p(i)));endifp(i)~=0,s=[spmppv'^'sprintf('%.0f',n-i)];endifnargin<3,ff=0;end%factoredform
4、isFalseendifnargin<2,v='s';end%defaultvariableis's'ifp(n)~=0,pp=sprintf('%.4g',abs(p(n)));else,pp=[];endifisempty(v),v='s';end%defaultvariableis's'ifp(n)<0,pm='-';elseifp(n)>0,pm='+';else,pm=[];v=v(1);%variablemustbescalarendp=mmpsim(p);%stripinsignif
5、icanttermsends=[spmpppe];%addfinaltermsn=length(p);functiony=mmpsim(x,tol)ifff%putinfactoredform%MMPSIMPolynomialSimplification,StripLeadingZeroTerms.K=p(1);Ka=abs(K);p=p/K;%MMPSIM(A)Deletsleadingzerosandsmallcoefficientsintheifabs(K-1)<1e-4%polynomia
6、lA(s).Coefficientsareconsideredsmalliftheirpp=[];pe=[];%magnitudeislessthanbothoneandnorm(A)*1000*eps.elseifabs(K+1)<1e-4%MMPSIM(A,TOL)usesTOLforitssmallnesstolerance.pp='-(';pe=')';%Copyright(c)1996byPrentice-Hall,Inc.elseifabs(Ka-round(Ka))<=1e-5*Ka
7、ifnargin<2,tol=norm(x)*1000*eps;endpp=[sprintf('%.0f',K)'*('];pe=')';x=x(:).';%makesureinputisarowelsei=find(abs(x)<.99&abs(x)8、mi=find(x~=0);%findsignificantindicesK=p(1);ifisempty(i)pp=sprintf('%.4g',K);y=0;%extremecase:nothingleft!pe=[];elsey=x(i(1):length(x));%startwithfirsttermia=sort([nslope;pslope+1]);%putindicesaboveinorderend%andgotoendofpolynomialie=find(equa