vb设计-计算方法上机

vb设计-计算方法上机

ID:10817288

大小:185.00 KB

页数:14页

时间:2018-07-08

vb设计-计算方法上机_第1页
vb设计-计算方法上机_第2页
vb设计-计算方法上机_第3页
vb设计-计算方法上机_第4页
vb设计-计算方法上机_第5页
资源描述:

《vb设计-计算方法上机》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、非线性方程数值方法1、固定点迭代:求解方程的近似值,初始值为,迭代式为function[k,x1,err,x]=fixpt(g,x0,tol,maxl)%Input-gistheiterationfunctioninputasastring'g'%-x0istheinitialguessforthefixedpoint%-tolisthetolerance%-maxlisthemaximumnumberofiterations%Output-kisthenumberofiterationthatwereca

2、rriedout%-x1istheapproximationtothefixedpoint%-erristheerrorintheapproximation%-xcontainsthesequence{xn}x(1)=x0;fork=2:maxlx(k)=feval(g,x(k-1));err=abs(x(k)-x(k-1));relerr=err/(abs(x(k))+eps);x1=x(k);if(err

3、(relerr

4、mumnumberofiterationsexceeded')endx=x';例如:求解 g=inline('exp(-x)');[k,p,err,P]=fixpt(g,0.5,0.01,20)x=0.5:0.01:1;y=exp(-x);plot(x,y,'o')holdonplot(x,x,'o')holdonplot(x,x,'r-')2、二分法:求解方程在区间内的一个根。前提条件是是连续的,且与的符号相反。function[c,err,yc]=bisect(f,a,b,delta)%Input-fi

5、sthefunctioninputasastring'f'%-aandbaretheleftandrightendpoint%-deltaisthetolerance%Output-cisthezero%-yc=f(c)%-erristheerrorestimateforcya=feval(f,a),yb=feval(f,b)ifya*yb>0,break,endmaxl=1+round((log(b-a)-log(delta))/log(2))fork=1:maxlc=(a+b)/2;yc=feval(f

6、,c);ifyc==0a=c;b=c;14elseifyb*yc>0b=c;yb=yc;elsea=c;ya=yc;endifb-a0x=0:0.01:0.5*pi;y=x.*sin(x)-1;plot(x,y,'r-')holdonplot(x,0,'g-')f=inline('x*sin(x)-1')[c,err,yc]=bise

7、ct(f,0,2,0.01)3、牛顿-拉夫申迭代:使用初始近似值,利用迭代式,计算函数的根的近似值。function[x0,err,k,y]=newton(f,df,x0,delta,epsilon,maxl)%Input-fistheobjectfunctioninputasastring'f'%-dfisthederivativeoffinputasastring'df'%-x0istheinitialapproximationtoazerooff%-deltaisthetoleranceforx0%-

8、epsilonisthetoleranceforthefunctionvaluesy%-maxlisthemaximumnumberofiterations%Output-xistheNewton-Raphsonapproximationtothezero%-erristheerrorestimateforx0%-kisthenumberofiterations%-yisthefunctionvaluef(x0)fork=1:maxlx1=x0-feval(f,x0)/feval(df,x0);err=ab

9、s(x1-x0);relerr=2*err/(abs(x1)+delta);x0=x1;y=feval(f,x0);if(err

10、(relerr

11、(abs(y)

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。