数值分析上机报告.docx

上传人:b****4 文档编号:1355636 上传时间:2022-10-21 格式:DOCX 页数:54 大小:658.58KB
下载 相关 举报
数值分析上机报告.docx_第1页
第1页 / 共54页
数值分析上机报告.docx_第2页
第2页 / 共54页
数值分析上机报告.docx_第3页
第3页 / 共54页
数值分析上机报告.docx_第4页
第4页 / 共54页
数值分析上机报告.docx_第5页
第5页 / 共54页
点击查看更多>>
下载资源
资源描述

数值分析上机报告.docx

《数值分析上机报告.docx》由会员分享,可在线阅读,更多相关《数值分析上机报告.docx(54页珍藏版)》请在冰豆网上搜索。

数值分析上机报告.docx

数值分析上机报告

数力系级

《数值分析》实验报告

姓名

学号:

专业:

学院:

成绩:

2010年6月25日

 

1.第二章上机练习

1.1实验一

1、分别用不动点迭代与Newton法求解方程x-+2=0的正根与负根。

2、usethefollowingmethodtofindasolutionin[0.1,1]accuratetowithinfor

a.Bisectionmethod;b.Newtonmethod;c.Secantmethod;d.methodofFalsePosition;e.Müller’smethod

1.1.1迭代公式(简单原理)

1.BisectionMethod

Themethodcallsforarepeatedhalvingofsubintervalsof[a,b]and,ateachstep,locatingthehalfcontainingtherootofequation.

Supposef(x)isacontinuousfunctiondefinedontheinterval[a,b],withf(a)andf(b)ofoppositesign.setal=aandb1=b,andletp1bethemidpointof[a,b];Thatisp1=(a+b)/2,Iff(p1)=0,thensetp=p1,p1是f(x)=0的实根p.Iff(a1)f(p1)<0,thenp(a1,p1),seta2=a1,b2=p1;otherwisep∈(p1,b1),seta2=p1,b2=b1.Wethenrepeattheprocesstotheinterval[a2,b2].Thelengthofinterval[ak,bk]isbk-ak=

2.Fixed-PointIteration

Thebasicidea:

Step1.Constructingthefixed-pointequation:

x=g(x),letf(x)=0x=g(x);g(x)iscalledIterationfunction

Step2.Settingupiterationscheme:

pk+1=g(pk)

(1)Wechooseaninitialapproximationp0andgeneratethesequenceby

(1),foreachk≥1.

3.Newtonmethod

Supposethatf∈[a,b],letpk∈[a,b]beanapproximationtorootoftheequationf(x)=0.ConsiderthefirstTaylorpolynomialforf(x)aboutpktoapproximatef(x):

Wehave,Letf’(pk)≠0,Solvingforpk+1gives,whichstartswithaninitialapproximationP0andgeneratesthesequence

4.Secantmethod

如所求问题不便求导,用过点xk的割线的斜率来代替切线的f’(xk),即,SubstitutingitintoNewtonMethod,wehave,ThistechniqueiscalledtheSecantmethod.

5.methodofFalsePosition

(1)提供两个初始值:

p0,p1,满足f(p0)·f(p1)<0;

(2)利用割线法求出p2,;(3)检查f(p2)·f(p1),若f(p2)·f(p1)<0,过点(p1,f(p1))(p2,f(p2))做割线,求出p3;否则若f(p2)·f(p1)>0,过点(p0,f(p0))与(p2,f(p2))做割线,求出p3;依此类推下去…

试位法保证方程f(x)=0的根p,总在相邻的迭代之中,即p∈(pk,pk+1).

6.Müller’smethod

1.1.2程序及实验结果

1.1Newtonmethod

fnewton.m

functionres=fnewton(func,dfunc,x,tol)

x0=x;

d=feval(func,x0)/feval(dfunc,x0);

i=0;

whileabs(d)>tol

i=i+1;

x1=x0-d;

x0=x1;

d=feval(func,x0)/feval(dfunc,x0);

end

res=[x0,i];

func.m

functionfx1=func(x)

fx1=x-10^x+2;

dfunc.m

functionfx2=dfunc(x)

fx2=1-10^x*(log(10));

实验结果

1.2Fixed-PointIteration

fixedpoint.m

functionres=fixedpoint(func1,x,tol)

x0=x;

d=feval(func1,x0);

x1=d;

i=0;

whileabs(x1-x0)>tol

x0=x1;

i=i+1;

d=feval(func1,x1);

x1=d;

end

res=[x1,i];

func1.m

functionfx1=func1(x)

fx1=log10(x+2);

实验结果

将func1做更改

func2.m

functionfx=func2(x)

fx=10^(x)-2;

实验结果:

2.1Bisectionmethod

bisection.m

functionres=bisection(func,xa,xb,tol)

n=0;

xc=0;

fa=0;

fc=0;

while(xb-xa)>tol

n=n+1;

fa=feval(func,xa);

xc=(xa+xb)/2;fc=feval(func,xc);

iffc*fa<0

xb=xc;

elsexa=xc;

end

end

res=[nxaxbxcfc];

func.m

functionfx1=func(x)

fx1=600*(x^4)-550*(x^3)+200*(x^2)-20*x-1;

实验结果

2.2.Newtonmethod

fnewton.m

functionres=fnewton(func,dfunc,x,tol)

x0=x;

d=feval(func,x0)/feval(dfunc,x0);

i=0;

whileabs(d)>tol

i=i+1;

x1=x0-d;

x0=x1;

d=feval(func,x0)/feval(dfunc,x0);

end

res=[x0,i];

func.m

functionfx1=func(x)

fx1=600*(x^4)-550*(x^3)+200*(x^2)-20*x-1;

dfunc.m

functionfx2=dfunc(x)

fx2=1-10^x*(log(10));

实验结果

2.3Secantmethod

secant.m

functionres=secant(func,x,y,tol)

x0=x;

x1=y;

d=[feval(func,x1)]*(x1-x0)/(feval(func,x1)-feval(func,x0));

i=0;

whileabs(d)>tol

i=i+1;

d=feval(func,x1)*(x1-x0)/(feval(func,x1)-feval(func,x0));

x0=x1;

x1=x1-d;

end

res=[x0,i];

func.m

functionfx1=func(x)

fx1=600*(x^4)-550*(x^3)+200*(x^2)-20*x-1;

实验结果

2.4methodofFalsePosition

falseposition.m

functionres=falseposition(func,x,y,tol)

x0=x;

x1=y;

d=[feval(func,x1)]*(x1-x0)/(feval(func,x1)-feval(func,x0));

i=0;

f=0;

x2=0;

whileabs(d)>tol

i=i+1;

f=feval(func,x1);

d=feval(func,x1)*(x1-x0)/(feval(func,x1)-feval(func,x0));

x2=x1-d;

ifx2*f<0

x0=x1;

x1=x2;

elsex1=x2;

end

end

res=[x0,i];

func.m

functionfx1=func(x)

fx1=600*(x^4)-550*(x^3)+200*(x^2)-20*x-1;

实验结果

2.5Müller’smethod

muller.m

functionres=muller(func,x,y,z,tol)

%Tofindtheapproximationrootofapolynomials

%bymullermethod

x0=x;

x1=y;

x2=z;

h1=x1-x0;

h2=x2-x1;

m1=(feval(func,x1)-feval(func,x0))/h1;

m2=(feval(func,x2)-feval(func,x1))/h2;

d=(m2-m1)/(h2+h1);

i=0;

h=100;

b=0;

e=0;

p=0;

q=0;

whileabs(h)>tol

i=i+1;

b=m2+h2*d;

p=(b^2-4*d*feval(func,x2))^(0.5);

ifabs(b-p)

e=b+p;

elsee=b-p;

end

h=(-2)*feval(func,x2)/e;

q=x2+h;

x0=x1;

x1=x2;

x2=q;

h1=x1-x0;

h2=x2-x1;

m1=(feval(func,x1)-feval(func,x0))/h1;

m2=(feval(func,x2)-feval(func,x1))/h2;

d=(m2-m1)/(h2+h1);

end

res=[q,i];

func.m

functionfx1=func(x)

fx1=600*(x^4)-550*(x^3)+200*(x^2)-20*x-1;

实验结果

1.1.3结果分析

1.经过实验结果比较我们可以看到,Newton法只需选取不同的初值,便可求出他全部的解,即Newton法对于他全部的解都是收敛的。

而使用不动点法,我们首先要选取合适的g(x),因为对于不同的解,g(x)不一定收敛,而对于不同的g(x)收敛的速度也都不同。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1