




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
反反复复二分法:#include#includemath.h#define E 0.01void main() float a,b,x,erfen(float a,float b); printf(Enter a,bn); scanf(%f,%f,&a,&b); x=erfen(a,b); printf(x=%fn,x); float erfen(float a,float b) float c,df(float x); while (fabs(a-b)E) c=(a+b)/2; if(df(c)=0) break; else if(df(a)*df(c)0) b=c; else a=c; return c; float df(float x)return 2*x-6;黄金分割法:#include#includemath.h#define E 0.001#define H 0.618void main() float a,b,x; float goldcut(float a,float b); printf(Enter a,bn); scanf(%f,%f,&a,&b); x=goldcut(a,b); printf(x*=%fn,x); float goldcut(float a,float b) float x1,x2,y1,y2; float f(float x); x2=a+H*(b-a); x1=a+b-x2; y1=f(x1); y2=f(x2); while(fabs(y1-y2)=E) if(y1y2) a=x1; x1=x2; y1=y2; x2=a+H*(b-a); y2=f(x2); else b=x2; x2=x1; y2=y1; x1=a+(1-H)*(b-a); y1=f(x1); return (x1+x2)/2; float f(float x) return x*x-6*x+2;进退法:#include#includemath.hvoid main() float x0,h,x1,jintui(float x0, float h); printf(Enter x0,h:n); scanf(%f,%f,&x0,&h); x1=jintui(x0, h); printf(%f,%f)n,x0,x1);float jintui(float x0,float h) float f(float x),x1,march(float x0,float h); if(f(x0)f(x0+h) x1=march(x0,h); else h=-h; x1=march(x0,h); return x1; float f(float x) return x*x-6*x+2; float march(float x0,float h) float x1=x0+h; while(f(x0)f(x1) x0=x1; h=2*h; x1=x0+h; return x1; 牛顿法:#include#includemath.h#define E 0.0001void main() float x,x0,f(float x); float newton(float x); printf(Enter xn); scanf(%f,&x); x0=newton(x); printf(%f,%f)n,x0,f(x0);float newton(float x) float x1; float f(float x),df(float x),ddf(float x); while (fabs(df(x)E) x1=x-df(x)/ddf(x); x=x1; return x; float f(float x) return x*x-6*x+2; float df(float x) return 2*x-6; float ddf(float x) return 0*x+2;进退法与二分法结合:#include#includemath.h#define E 0.001void main() float x0,h,x1,x2; float jintui(float x0,float h); float erfen(float x0,float x1); printf(Enter x0,hn); scanf(%f,%f,&x0,&h);x1=jintui(x0,h); printf(%f,%f)n,x0,x1);x2=erfen(x0,x1); printf(%fn,x2);float jintui(float x0,float h)float x1;float f(float x);float march(float x0,float h);if(f(x0)f(x0+h) x1=march(x0,h);else h=-h; x1=march(x0,h); return x1;float f(float x) return x*x-6*x+2;float march(float x0,float h) float x1=x0+h;while(f(x0)f(x1) x0=x1; h=2*h; x1=x0+h; return x1;float erfen(float x0,float x1)float c,df(float x);while(fabs(x0-x1)E) c=(x0+x1)/2; if(df(c)=0) break; else if(df(x0)*df(c)0) x1=c; else x0=c; return c;float df(float x)return 2*x-6;进退与黄金法结合:#include#includemath.h#define H 0.618#define E 0.001void main() float x0,h,a,b,x1,x2; float jintui(float x0,float h); float goldcut(float a,float b); printf(Enter x0,hn); scanf(%f,%f,&x0,&h);x1=jintui(x0,h); printf(%f,%f)n,x0,x1);x2=goldcut(x0,x1); printf(x2*=%fn,x2); float jintui(float x0,float h) float x1,f(float x),march(float x0,float h); if(f(x0)f(x0+h) x1=march(x0,h); else h=-h;x1=march(x0,h); return x1;float march(float x0,float h) float x1=x0+h; while(f(x0)f(x1) x0=x1; h=2*h; x1=x0+h; return x1; float goldcut(float a,float b) float x1,x2,y1,y2; float f(float x); x2=a+H*(b-a); x1=a+b-x2; y1=f(x1); y2=f(x2); while(fabs(y1-y2)=E
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 铜陵市建筑安全员c证考试题库及答案解析
- 护理常规试题库及答案解析
- 内河船员安全生产题库及答案解析
- 材料作文“人际关系”(2014年浙江杭州中考满分作文7篇)
- 银行从业考试中级个人贷款及答案解析
- 中医护理学题库选择题及答案解析
- 全面综合能力2025年乡村全科执业助理医师试题及答案
- 2025年镇村级后备干部考核考试卷(附答案)
- 公司安全协议书范本8篇
- 韶关社工考试试题及答案
- 零星维修工程施工组织设计方案方案
- 2025年汽车驾驶员(技师)考试试题及答案(含答案)
- 2025大连国际机场招聘25人笔试历年参考题库附带答案详解
- 2025年浙江铁塔招聘笔试备考题库(带答案详解)
- 2025年上海市(秋季)高考语文真题详解
- 《秘书文档管理第三版》课件第七章
- 电力工程电缆设计课件
- 施工班组驻地管理制度
- 城投公司成本控制管理制度
- 中国磷化工行业市场规模及发展前景研究报告(智研咨询)
- 万亨工业科技(台州)股份有限公司年产500万套逆变器及配件、800万套新能源汽车控制器配件技改项目环评报告
评论
0/150
提交评论