2022年2022年机械优化设计编程 .pdf
《2022年2022年机械优化设计编程 .pdf》由会员分享,可在线阅读,更多相关《2022年2022年机械优化设计编程 .pdf(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、二分法:#include #includemath.h #define E 0.01 void 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; re
2、turn c; float df(float x) return 2*x-6; 黄金分割法:#include #includemath.h #define E 0.001 #define H 0.618 void 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);
3、 x2=a+H*(b-a); x1=a+b-x2; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 6 页 - - - - - - - - - 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; f
4、loat f(float x) return x*x-6*x+2; 进退法:#include #includemath.h void 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(
5、x0,h); else h=-h; x1=march(x0,h); return x1; float f(float x) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 6 页 - - - - - - - - - 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 #in
6、cludemath.h #define E 0.0001 void 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(floa
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年2022年机械优化设计编程 2022 机械 优化 设计 编程
限制150内