已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 全国研究生入学考试英语科目历年真题解析题库及参考答案
- 小学语文教师数字能力评价反馈与阅读教学策略研究教学研究课题报告
- 2026年重庆财经学院校园招聘备考题库及一套答案详解
- 基于生成式AI的情境化化学实验课堂教学模式构建教学研究课题报告
- 初中化学气体收集方法环境友好型创新设计课题报告教学研究课题报告
- 小学生对医疗AI系统伦理风险评估的参与度研究课题报告教学研究课题报告
- 小学英语教学中绘本教学法的创新应用与效果评估课题报告教学研究课题报告
- 2025年应用心理学硕士研究生入学考试试题及答案
- 2025年应急预案教育培训试题及答案
- 2025年应急救援安全应知应会考试题库及答案
- 中医护理病情观察
- 船员劳务派遣管理制度
- vte防治宣传管理制度
- 2025年中考数学二轮复习专题系列圆与无刻度直尺作图
- 《直肠癌NCCN治疗指南》课件
- 预防老年人失能
- 百色市2024-2025学年高二上学期期末考试英语试题(含答案详解)
- 福建省龙岩市连城一中2025届高考英语五模试卷含解析
- 耳聋护理学习
- 幼儿园入学准备指导要点试题
- 《机械常识(第2版)》中职技工全套教学课件
评论
0/150
提交评论