1、数值分析上机报告 数力系 级数值分析实验报告姓名 学号: 专业: 学院: 成绩:2010年 6 月 25 日 1.第二章上机练习1.1实验一1、分别用不动点迭代与Newton法求解方程x-+2=0的正根与负根。2、use the following method to find a solution in 0.1,1 accurate to within for a. Bisection method ; b. Newton method ; c.Secant method ; d. method of False Position ; e.Mllers method1.1.1 迭代公式(简单
2、原理)1.Bisection MethodThe method calls for a repeated halving of subintervals of a, b and, at each step, locating the half containing the root of equation.Suppose f(x) is a continuous function defined on the interval a, b, with f(a) and f(b) of opposite sign. set al = a and b1 = b, and let p1 be the
3、midpoint of a, b; That is p1 =(a+b)/2, If f(p1) = 0, then set p = p1, p1是f(x)=0的实根p. If f(a1)f(p1)0, then p (a1, p1), set a2=a1,b2=p1; otherwise p (p1,b1), set a2=p1,b2=b1. We then repeat the process to the interval a2, b2. The length of interval ak , bk is bk-ak=2.Fixed-Point IterationThe basic ide
4、a:Step1. Constructing the fixed-point equation: x=g(x) ,let f(x)=0 x=g(x); g(x) is called Iteration functionStep2. Setting up iteration scheme:pk+1= g(pk) (1)We choose an initial approximation p0 and generate the sequence by (1), for each k 1.3. Newton methodSuppose that f a, b ,let pk a, b be an ap
5、proximation to root of the equation f(x)=0.Consider the first Taylor polynomial for f(x) about pk to approximate f(x): We have , Let f(pk) 0 , Solving for pk+1 gives, which starts with an initial approximation P0 and generates the sequence 4. Secant method如所求问题不便求导,用过点xk 的割线的斜率来代替切线的f( xk), 即, Subst
6、ituting it into Newton Method, we have, This technique is called the Secant method .5. method of False Position(1) 提供两个初始值:p0, p1,满足f(p0) f(p1)0 ;(2)利用割线法求出p2,; (3) 检查f(p2) f(p1),若f(p2) f(p1)tol i=i+1; x1=x0-d; x0=x1; d=feval(func,x0)/feval(dfunc,x0);endres=x0,i;func.mfunction fx1=func(x)fx1=x-10x+2
7、;dfunc.mfunction fx2=dfunc(x)fx2=1-10x*(log(10);实验结果1.2Fixed-Point Iterationfixedpoint.mfunction res=fixedpoint(func1,x,tol)x0=x;d=feval(func1,x0);x1=d;i=0;while abs(x1-x0)tol x0=x1; i=i+1; d=feval(func1,x1); x1=d;endres=x1,i;func1.mfunction fx1=func1(x)fx1=log10(x+2);实验结果将func1做更改func2.mfunction fx
8、=func2(x)fx=10(x)-2;实验结果:2.1 Bisection methodbisection.mfunction res=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); if fc*fatol i=i+1; x1=x0-d; x0=x1; d=feval(func,x0)/feval(dfunc,x0);endres=x0,i;func.mfunction fx1=func(x)fx1=60
9、0*(x4)-550*(x3)+200*(x2)-20*x-1;dfunc.mfunction fx2=dfunc(x)fx2=1-10x*(log(10);实验结果2.3Secant methodsecant.mfunction res=secant(func,x,y,tol)x0=x;x1=y;d=feval(func,x1)*(x1-x0)/(feval(func,x1)-feval(func,x0);i=0;while abs(d)tol i=i+1; d=feval(func,x1)*(x1-x0)/(feval(func,x1)-feval(func,x0);x0=x1; x1=x
10、1-d;endres=x0,i;func.mfunction fx1=func(x)fx1=600*(x4)-550*(x3)+200*(x2)-20*x-1;实验结果2.4 method of False Positionfalseposition.mfunction res=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;while abs(d)tol i=i+1; f=feval(func,x1); d=feval(func,
11、x1)*(x1-x0)/(feval(func,x1)-feval(func,x0); x2=x1-d; if x2*ftol i=i+1; b=m2+h2*d; p=(b2-4*d*feval(func,x2)(0.5); if abs(b-p)abs(b+p) e=b+p; else e=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); endres=q,i;func.mfunction fx1=func(x)fx1=600*(x4)-550*(x3)+200*(x2)-20*x-1;实验结果1.1.3结果分析1.经过实验结果比较我们可以看到,Newton法只需选取不同的初值,便可求出他全部的解,即Newton法对于他全部的解都是收敛的。而使用不动点法,我们首先要选取合适的g(x),因为对于不同的解,g(x)不一定收敛,而对于不同的g(x)收敛的速度也都不同。而
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1