1 / 20

计算方法第二次上机实习

计算方法第二次上机实习. 问题提出: 1. 在 [0,4] 上求解 e^(-x*x)=cos(x)+1 的根,从 x=0 或 x=1 开始,用牛顿法和割线法求。. 2. 求 f(x)=x*(x*(x+2)+10)-20 的根,从 x=2 和 x=1 开始利用牛顿法,割线法,迭代法和埃肯金法求。. 第一题: 问题分析: 先利用作图工具绘出方程草图. 方程 e^(-x*x)=cos(x)+1 在定义域内的值在 3 附近。利用牛顿法求时 F(x)=(cos(x)-exp(-x*x)+1);

Download Presentation

计算方法第二次上机实习

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 计算方法第二次上机实习 • 问题提出: • 1.在[0,4]上求解 • e^(-x*x)=cos(x)+1的根,从x=0或x=1开始,用牛顿法和割线法求。 • 2. 求f(x)=x*(x*(x+2)+10)-20的根,从x=2和x=1开始利用牛顿法,割线法,迭代法和埃肯金法求。

  2. 第一题: • 问题分析: 先利用作图工具绘出方程草图

  3. 方程e^(-x*x)=cos(x)+1在定义域内的值在3附近。利用牛顿法求时方程e^(-x*x)=cos(x)+1在定义域内的值在3附近。利用牛顿法求时 • F(x)=(cos(x)-exp(-x*x)+1); • F’(x)=(2*x*( exp(-x*x))-sin(x)) ; • 根据题意代入x=1或x=0均得x*=9.424778不合题意。代入x=2时x*=3.131081 符合题意 • 算法设计 如下

  4. #include "stdio.h" • #include <math.h> • float F( float b) • { float a; • a=(cos(b)-exp(-b*b)+1); • return(a);} • float dao( float b) • {double a; • a=(2*b*( exp(-b*b))-sin(b)); • return(a);} • void main() • { double m,b[30];int i; • m=0; • for(i=1;i<30;i++) • {b[0]=2; • b[i]=(b[i-1]-F(b[i-1])/dao(b[i-1])); • m=b[i]; • printf(" %f\n ",m); • } • }

  5. 测试结果

  6. 方程e^(-x*x)=cos(x)+1在定义域内的值在3附近。利用割线法求时方程e^(-x*x)=cos(x)+1在定义域内的值在3附近。利用割线法求时 • F(x)=(cos(x)-exp(-x*x)+1) • F(x)’=(F(x)-F(x-1))/(x-(x-1)) • 算法设计 如下

  7. #include "stdio.h" • #include <math.h> • float F( float b) • { float a; • a=(cos(b)-exp(-b*b)+1); • return(a);} • float dao( float b,float c) • {double a; • a=(F(b)-F(c))/(b-c); • return(a);} • void main() • {double m,b[30];int i; • m=0; • for(i=2;i<30;i++) • {b[0]=0;b[1]=1; • b[i]=(b[i-1]-F(b[i-1])/dao(b[i-1],b[i-2])); • m=b[i]; • printf(" %f\n ",m); • } • }

  8. 测试结果

  9. 第二题: • 问题分析: 先利用作图工具绘出方程草图

  10. 牛顿法 • 分析:如函数的图像所示:根在1到2 之间。使用牛顿法,取x=1作为初值。收敛至x(k)与x(k+1)的差别满足精度要求即可求出它的根。 • Newton法是收敛速度较快的方法。 • 算法设计如下

  11. #include "stdio.h" • #include <math.h> • float F( float b) • { float a; • a=(b*(b*(b+2)+10)-20); • return(a);} • float dao( float b) • {double a; • a=(b*(3*b+4)+10); • return(a);} • void main() • {double m,b[30];int i; • m=0; • for(i=1;i<20;i++) • {b[0]=1; • b[i]=(b[i-1]-F(b[i-1])/dao(b[i-1])); • m=b[i]; • printf(" %f\n ",m); • } • }

  12. 测试结果

  13. 割线法 • #include "stdio.h" • #include <math.h> • float F( float b) • { float a; • a=(b*(b*(b+2)+10)-20); • return(a);} • float dao( float b,float c) • {double a; • a=(F(b)-F(c))/(b-c); • return(a);} • void main() • {double m,b[30];int i; • m=0; • for(i=2;i<20;i++) • {b[0]=2;b[1]=1; • b[i]=(b[i-1]-F(b[i-1])/dao(b[i-1],b[i-2])); • m=b[i]; • printf(" %f\n ",m); • } • }

  14. 测试结果

  15. 埃特金法 • #include "stdio.h" #include <math.h> • float F( float b) • { float a; • a=(b*(b*(b+2)+10)-20); • return(a);} • void main() • {double m,n,b[30];int i; • m=0;n=0; • for(i=1;i<20;i++) • {b[0]=1; • n=F(b[i-1]); • m=F(n); • b[i]=m-(m-n)*(m-n)/(m-2*n+b[i-1]); • m=b[i]; • printf(" %f\n ",m); • } • }

  16. 测试结果

  17. 迭代法 • 分析:用迭代法,本题可构造多种不同的迭代公式。但通过规整的移项来构造迭代公式得到的都是发散的。于是,试着拆开一些项进行移项构造。经过尝试,得到这样一个方程是收敛的: • F(x)=((x*x*x-4*x*x+10*x-20) / (-6))^(1/ 2) • -1<F’(x)<1

  18. 算法如下: • #include "stdio.h" • #include <math.h> • float F( float b) • { float a; • a=sqrt((b*b*b-4*b*b+10*b-20)/(-6)); • return(a);} • void main() • {double m,b[30];int i; • m=0; • for(i=1;i<20;i++) • {b[0]=2; • b[i]=F(b[i-1]); • m=b[i]; • printf(" %f\n ",m); • } • }

  19. 测试结果

  20. 班级: 土木0702班 • 组员: • 魏珏 U200715243 • 张建刚 U200715344 • 王杰 U200715314 • 周虎 U200715260 • 雷蕾 U200715298 • 陆静 U200715302

More Related