




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 山东省烟台龙口市2025届初三下学期第三次阶段检测试题数学试题含解析
- 企业职场礼仪培训
- 枣强中学高一上学期第四次月考地理试题
- 2025合同法中合同解除的若干问题
- 急腹症的观察及急救护理
- 2025建筑项目招标投标合同(合同协议书)
- 培训班停课通知与违规办学治理
- 2025委托加工合同范本下载
- 2025深交所指定交易合同
- 2025商品买卖合同
- 2025年河南交通职业技术学院单招职业技能测试题库审定版
- 政府审计 课件汇 蒋秋菊 第5-12章 金融审计- 政府审计报告
- 三农村合作社应急管理方案
- s7-200smart详细教学教案
- 旅馆业治安管理培训会
- 2025年南阳科技职业学院高职单招职业技能测试近5年常考版参考题库含答案解析
- 2025年共青团考试题库及答案
- 4-2-电商文案开头、结尾、正文的写作
- 2025年广州水务投资集团有限公司招聘笔试参考题库含答案解析
- 合肥滨湖湿地森林公园观光火车项目设计方案
- 2025年福建福州港务集团有限公司招聘笔试参考题库含答案解析
评论
0/150
提交评论