欢迎来到天天文库
浏览记录
ID:59203264
大小:2.39 MB
页数:4页
时间:2020-09-10
《工程常用算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、哈尔滨工程大学机电工程学院综合实践大作业学年学期:2015-2016学年春季学期课程代号:[1]课程名称:工程常用算法授课教师:郭健副教授小组成员班级学号姓名成绩郭俊杰凌泽宇张明旺2016年6月15日《工程常用算法》综合实践作业一作业名称:非线性方程求根完成日期:2015年3月26日组号:8班级学号姓名主要工作说明自评成绩郭俊杰程序流程图A凌泽宇C语言算法编程张明旺总结排版知方程,请分别用二分法、牛顿法和割线法求此方程的根。误差限取:。注意先确定出方程的有根区间。二、程序流程图二分法牛顿迭代法割线法三、完整的程序及简要的注释1.牛顿法#include2、h>#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidNewtonRoot(doublex0,doubleex){doublex1,fx1,fdx0;intk=1;printf("牛顿法求根");while(1){fdx0=fd(x0);if(fdx0==0){printf("重新输入初始值!");break;}else{x1=x0-f(x0)/fdx0;fx1=f(x1);printf("k=%-3d3、x=%.12ff(x)=%.12f",k,x1,fx1);if(fabs(x1-x0)#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidBiPartition(doublea,doubleb,doubleex){4、printf("二分法求根");if(f(a)*f(b)>0){printf("区间内无根!");return;}doublex,fx;intk=1;while(1){x=(a+b)/2;fx=f(x);printf("k=%-3dx=%.12ff(x)=%.12f",k,x,fx);if((b-a)5、分法计算BiPartition(-2,-1,1e-12);return0;}3.割线法#include#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidNewton(doublex0,doublex1,doubleex){printf("割线法求根");doublex2,fx;intk=1;while(1){x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));fx=f(6、x2);printf("k=%-3dx2=%.12ff(x)=%.12f",k,x2,fx);if(fabs(x2-x1)
2、h>#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidNewtonRoot(doublex0,doubleex){doublex1,fx1,fdx0;intk=1;printf("牛顿法求根");while(1){fdx0=fd(x0);if(fdx0==0){printf("重新输入初始值!");break;}else{x1=x0-f(x0)/fdx0;fx1=f(x1);printf("k=%-3d
3、x=%.12ff(x)=%.12f",k,x1,fx1);if(fabs(x1-x0)#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidBiPartition(doublea,doubleb,doubleex){
4、printf("二分法求根");if(f(a)*f(b)>0){printf("区间内无根!");return;}doublex,fx;intk=1;while(1){x=(a+b)/2;fx=f(x);printf("k=%-3dx=%.12ff(x)=%.12f",k,x,fx);if((b-a)5、分法计算BiPartition(-2,-1,1e-12);return0;}3.割线法#include#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidNewton(doublex0,doublex1,doubleex){printf("割线法求根");doublex2,fx;intk=1;while(1){x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));fx=f(6、x2);printf("k=%-3dx2=%.12ff(x)=%.12f",k,x2,fx);if(fabs(x2-x1)
5、分法计算BiPartition(-2,-1,1e-12);return0;}3.割线法#include#includedoublef(doublex){returnx*x*x+2*x*x-exp(x);}doublefd(doublex){return3*x*x+4*x-exp(x);}voidNewton(doublex0,doublex1,doubleex){printf("割线法求根");doublex2,fx;intk=1;while(1){x2=x1-f(x1)*(x1-x0)/(f(x1)-f(x0));fx=f(
6、x2);printf("k=%-3dx2=%.12ff(x)=%.12f",k,x2,fx);if(fabs(x2-x1)
此文档下载收益归作者所有