机械优化设计黄金分割法 外推法(6)

时间:2026-01-17

#include<math.h> #include<stdio.h> #include<stdlib.h> float f(float x,float y) {

float z;

z=(x-2)*(x-2)+(y-1)*(y-1); return z; }

float g1(float x,float y) {

float z; z=x*x-y; return z; }

float g2(float x,float y) {

float z; z=x+y-2; return z; }

void main() {

int i,j; float

k=8,c=0.000001,a0=-3,b0=3,a1=-3,b1=3; float

x[10],x0[10],xl[10],e[10],r[10],d[10],h,fl,f0,fx;

while(g1(x0[0],x0[1])>0||g2(x0[0],x0[1])>0) {

x0[0]=a0+(rand()/32767.00)*(b0-a0); x0[1]=a1+(rand()/32767.00)*(b1-a1); }

fl=f(x0[0],x0[1]); f0=f(x0[0],x0[1]); while(1) { h=0.01; j=1;

r[0]=-1+(rand()/32767.00)*(1-(-1)); r[1]=-1+(rand()/32767.00)*(1-(-1)); e[0]=r[0]/sqrt(r[0]*r[0]+r[1]*r[1]); e[1]=r[1]/sqrt(r[0]*r[0]+r[1]*r[1]); x[0]=x0[0]+h*e[0];

x[1]=x0[1]+h*e[1];

if(g1(x[0],x[1])<=0&&g2(x[0],x[1])<=0)

{ fx=f(x[0],x[1]); if(fx<fl) { fl=fx;

for(i=0;i<2;i++) {d[i]=e[i];xl[i]=x[i];} } }

while(j<=k) { j++;

r[0]=-1+(rand()/32767.00)*(1-(-1));

r[1]=-1+(rand()/32767.00)*(1-(-1));

e[0]=r[0]/sqrt(r[0]*r[0]+r[1]*r[1]);

e[1]=r[1]/sqrt(r[0]*r[0]+r[1]*r[1]); x[0]=x0[0]+h*e[0]; x[1]=x0[1]+h*e[1];

if(g1(x[0],x[1])<=0&&g2(x[0],x[1])<=0) { fx=f(x[0],x[1]); if(fx<fl) { fl=fx;

for(i=0;i<2;i++) {d[i]=e[i];xl[i]=x[i];} } } }

x[0]=xl[0]; x[1]=xl[1]; while(1) {

h=1.3*h;

x[0]=x[0]+h*d[0]; x[1]=x[1]+h*d[1];

if(g1(x[0],x[1])>0||g2(x[0],x[1])>0) break;

fx=f(x[0],x[1]); if(fx<fl) fl=fx; else break; } do

机械优化设计黄金分割法 外推法(6).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:4.9 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:19元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219