《数值分析》实验报告.doc_第1页
《数值分析》实验报告.doc_第2页
《数值分析》实验报告.doc_第3页
《数值分析》实验报告.doc_第4页
《数值分析》实验报告.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

数值分析实验报告实验序号:实验三 题目名称: 解非线性方程学号: 20101104200 姓名:葛广帅任课教师: 马季骕 专业班级:10计算机科学与技术(非师范)1. 实验目的:理解并掌握二分法、迭代法、牛顿法、弦线法解非线性方程求根的原理,掌握相应的求根原理,算法原理,通过计算机解决实验问题。2、实验内容:(1)求方程X3-3*X-1=0在X=2附近的根。(2)保留四位有效数字。3实验代码: # include # include # include # include # define exp 1e-5/精度要求 # define Exp 1e-8/判零条件 # define F(x) (x*x*x-x*x-1)/F(x)函数 # define f(x) (3*x*x-2*x)# define Q1(x) ( pow(1+x*x,1.0/3) )/导数为0.30 # define Q2(x) ( 1+1.0/(x*x) )/导数为0.59using namespace std;int menu();void fun1();void fun2();void fun31();void fun32();void fun3();void fun4();void fun5();int main() int oper; while(1) oper=menu(); switch(oper) case 1 : fun1(); break; case 2 : fun2(); break; case 3 : fun3(); break; case 4 : fun4(); break; case 5 : fun5(); break; case 6 : exit(1); return 0;int menu() int oper; cout*endl; cout 实验三 方程(x*x*x-x*x-1=0)求根 endl; cout*endl; cout1 对分区间法 endl; cout2 黄金分割法 endl; cout3 迭代法 endl; cout4 牛顿法 endl; cout5 弦位法 endl; cout6 退出 endl; cout*endl; coutoper; system(cls); return oper;void fun1()/对分区间法 double a,b,c; double Fa,Fb,Fc; int k; cout*endl; cout 对分区间法演示 endl; cout*endl; cout-endl; cout k 根所在区间 F(a) F(b) F(a+b)/2)endl; cout-exp) cout setw(2)k fixedsetprecision(6)a , fixedsetprecision(6)b ; k+; c=(a+b)/2; Fc=F(c); cout fixedsetprecision(6)Fa fixedsetprecision(6)Fb0) cout ; coutfixedsetprecision(6)Fcendl; if(fabs(Fc)Exp) cout setw(2)k fixedsetprecision(6)c0) Fa=Fc; a=c; else Fb=Fc; b=c; system(pause); system(cls); return ;void fun2()/黄金分割法 double a,b,c; double Fa,Fb,Fc; int k; cout*endl; cout 黄金分割法演示 endl; cout*endl; cout-endl; cout k 根所在区间 F(a) F(b) F(a+b)/2)endl; cout-exp) cout setw(2)k fixedsetprecision(6)a , fixedsetprecision(6)b ; k+; c=a+(b-a)*0.618; Fc=F(c); cout fixedsetprecision(6)Fa fixedsetprecision(6)Fb0) cout ; coutfixedsetprecision(6)Fcendl; if(fabs(Fc)Exp) cout setw(2)k fixedsetprecision(6)c0) Fa=Fc; a=c; else Fb=Fc; b=c; system(pause); system(cls); return ;void fun3() int num; cout*endl; cout 迭代法演示 endl; cout*endl; cout1 Q(x) = pow(1+x*x,1.0/3)endl; cout Q(x)= 0.30 endl; cout2 Q(x) = 1+1.0/(x*x) endl; cout Q(x)= 0.59 endl; cout0 返回主界面 endl; cout-endl; coutnum; system(cls); switch(num) case 1: fun31(); break; case 2: fun32(); break; case 0: return ; fun3();void fun31()/迭代法1 int k; double x,xx; k=0; x=1.5; xx=Q1(x); cout*endl; cout 迭代法演示(Q(x)=0.30) endl; cout*endl; cout-endl; cout k X(k) endl; cout-endl; cout setw(2)k fixedsetprecision(6)xexp) x=xx; xx=Q1(x); k+; cout setw(2)k fixedsetprecision(6)xendl; system(pause); system(cls); return ; void fun32()/迭代法2 int k; double x,xx; k=0; x=1.5; xx=Q2(x); cout*endl; cout 迭代法演示(Q(x)=0.59) endl; cout*endl; cout-endl; cout k X(k) endl; cout-endl; cout setw(2)k fixedsetprecision(6)xexp) x=xx; xx=Q2(x); k+; cout setw(2)k fixedsetprecision(6)xendl; system(pause); system(cls); return ; void fun4()/牛顿法 int k; double x,xx; x=1.5; xx=x-F(x)/f(x); k=0; cout*endl; cout 牛顿法演示 endl; cout*endl; cout-endl; cout k X(k) endl; cout-endl; cout setw(2)k fixedsetprecision(6)xexp) x=xx; xx=x-F(x)/f(x); k+; cout setw(2)k fixedsetprecision(6)xendl; system(pause); system(cls); return ; void fun5()/弦位法 int k; double x0,x1,Fx0,Fx1,x2,Fx2; x0=1; x1=2; Fx0=F(x0); Fx1=F(x1); k=0; cout*endl; cout 弦位法演示 endl; cout*endl; cout-endl; cout k X(k) endl; cout-endl; cout setw(2)k fixedsetprecision(6)x0Exp) x2=x1-Fx1*(x1-x0)/(Fx1-Fx0); Fx2=F(x2); x0=x1; Fx0=Fx1; x1=x2; Fx1=Fx2; k+; cout setw(2)k fixedsetprecision(6)x0endl; if(fabs(Fx2)Exp) break; system(pause); system(cls); return ; 4结果分析: 分析:对分区间法简单,有根区间以1/2的比率缩小,所以它是线性收敛的。它的缺点是只能用于求实根,而且不能求偶重根,收敛速度较慢。迭代法需要判断迭代方程的收敛性,即需要满足李氏条件且李氏常数L1,当L越

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论