欢迎来到天天文库
浏览记录
ID:34775205
大小:89.68 KB
页数:4页
时间:2019-03-10
《最小二乘法拟合多项式》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、CurveFittingwithMATLABCurvefittingisausefultoolforrepresentingadatasetinalinearorquadraticfashion.MATLABhastwofunctions,polyfitandpolyval,whichcanquicklyandeasilyfitapolynimialtoasetofdatapoints.Afirstorderpolynomialisthelinearequationthatbestfitsthedata.Apolynomia
2、lcanalsobeusedtofitthedatainaquadraticsense.Asareminder,thegeneralformulaforapolynomialis:Thedegreeofapolynomialisequaltothelargestvalueoftheexponentsoftheindependentvariable,x.Forexample:PolyfitandPolyval"Polyfit"isaMATLABfunctionthatcomputesaleastsquarespolynomia
3、lforagivensetofdata.Polyfitactuallygeneratesthecoefficientsofthepolynomial(whichcanbeusedtosimulateacurvetofitthedata)accordingtothedegreespecified."Polyval"evaluatesapolynomialforagivensetofxvalues.So,polyvalactuallygeneratesacurvetofitthedatabasedonthecoefficient
4、sfoundusingpolyfit.MATLAB'sexplanationofpolyfitandpolyvalare:POLYFIT-PolynomialcurvefittingPOLYFIT(x,y,n)findsthecoefficientsofapolynomialp(x)ofdegreenthatfitsthedata,p(x(i))isapproximatelyequaltoy(i),inaleast-squaressense.POLYVAL-PolynomialevaluationIfVisavectorwh
5、oseelementsarethecoefficientsofapolynomial,thenPOLYVAL(V,s)isthevalueofthepolynomialevaluatedats.Ifsisamatrixorvector,thepolynomialisevaluatedatallpointsins.ThefollowingisanexampleMATLABcurvefitsequenceusingpolyfitandpolyval.Hereistheplotreflectingourfirsttryatfitt
6、ingthedatawithafirstdegreepolynomial(orastraightline).ThecoefficientsgivenbyMATLAByieldthefollowingequationfortheline:Tryingahigherpolynomial:Hereistheplotofthecurvegeneratedfromthe5thorderpolynomial.Thiscurvefitsthedataperfectly.ThecoefficientsgivenbyMATLABforthec
7、urveyieldthefollowingequation:
此文档下载收益归作者所有