机械优化设计编程(C语言).doc_第1页
机械优化设计编程(C语言).doc_第2页
机械优化设计编程(C语言).doc_第3页
机械优化设计编程(C语言).doc_第4页
机械优化设计编程(C语言).doc_第5页
已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论