机械优化设计大作业用C语言编程,机械优化设计编程(C语言).doc

44cb7578e1df5412b94317daaa3307ba.gif机械优化设计编程(C语言).doc

下载提示(请认真阅读)1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。

2.下载的文档,不会出现我们的网址水印。

3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。

文档包含非法信息?点此举报后获取现金奖励!

下载文档到电脑,查找使用更方便

20

积分

还剩页未读,继续阅读

关 键 词:机械

优化

设计

编程

语言

资源描述:

反反复复二分法:

#include#include"math.h"

#define E 0.01

void main()

{ float a,b,x,erfen(float a,float b);

printf("Enter a,b\n");

scanf("%f,%f",&a,&b);

x=erfen(a,b);

printf("x=%f\n",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#include"math.h"

#define E 0.001

#define H 0.618

void main()

{ float a,b,x;

float goldcut(float a,float b);

printf("Enter a,b\n");

scanf("%f,%f",&a,&b);

x=goldcut(a,b);

printf("x*=%f\n",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(y1>y2)

{ 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#include"math.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(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#include"math.h"

#define E 0.0001

void main()

{ float x,x0,f(float x);

float newton(float x);

printf("Enter x\n");

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#include"math.h"

#define E 0.001

void main()

{ float x0,h,x1,x2;

float jintui(float x0,float h);

float erfen(float x0,float x1);

printf("Enter x0,h\n");

scanf("%f,%f",&x0,&h);

x1=jintui(x0,h);

printf("(%f,%f)\n",x0,x1);

x2=erfen(x0,x1);

printf("%f\n",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#include"math.h"

#define H 0.618

#define E 0.001

void main()

{ float x0,h,a,b,x1,x2;

float jintui(float x0,float h);

float goldcut(float a,float b);

printf("Enter x0,h\n");

scanf("%f,%f",&x0,&h);

x1=jintui(x0,h);

printf("(%f,%f)\n",x0,x1);

x2=goldcut(x0,x1);

printf("x2*=%f\n",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)

{

if(y1>y2)

{ 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;}

展开阅读全文

温馨提示:

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。

2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。

3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。

4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。

5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。

6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。

7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

bb6249c6567dd4384e6ab3556cfc22ed.gif 

人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

关于本文

本文标题:机械优化设计编程(C语言).doc

链接地址:https://www.renrendoc.com/p-39694245.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值