📄 antenna1.c
字号:
/* **************************************************************************** *//* user functions *//* **************************************************************************** */#include "o8para.h"main() { void donlp2(void); donlp2(); exit(0);}static DOUBLE length,dist,pi;static DOUBLE thetaw[164];/* **************************************************************************** *//* donlp2 standard setup *//* **************************************************************************** */void setup0(void) { #define X extern #include "o8comm.h" /* #include "o8fint.h" */ #undef X static INTEGER i,j; n = 7; nh = 0; ng = 333; del0 = 0.01e0; tau0 = 1.e3; tau = 0.1e0; strcpy(name,"antenna1"); length = 3.5e0; dist = 0.4e0; pi = 4.e0*atan(1.e0); x[1] = 10.e0; for (i = 2 ; i <= 7 ; i++) { x[i] = (DOUBLE)(i-1)*length/7.e0; } for (j = 1 ; j <= 163 ; j++) { thetaw[j] = pi*(8.5e0+(DOUBLE)j*0.5e0)/180.e0; } analyt = TRUE; epsdif = 1.e-8; for (i = 2 ; i <= ng ; i++) { gunit[1][i] = -1; gunit[2][i] = 0; gunit[3][i] = 0; } for (j = 1 ; j <= 3 ; j++) { gunit[j][0] = 1; } gunit[1][1] = 1; gunit[2][1] = 2; gunit[3][1] = 1; return;}/* **************************************************************************** *//* special setup *//* **************************************************************************** */void setup(void) { #define X extern #include "o8comm.h" #undef X return;}/* **************************************************************************** *//* the user may add additional computations using the computed solution here *//* **************************************************************************** */void solchk(void) { #define X extern #include "o8comm.h" #undef X #include "o8cons.h" return;}/* **************************************************************************** *//* objective function *//* **************************************************************************** */void ef(DOUBLE x[],DOUBLE *fx) { #define X extern #include "o8fuco.h" #undef X icf = icf+1; *fx = x[1]; return;}/* **************************************************************************** *//* gradient of objective function *//* **************************************************************************** */void egradf(DOUBLE x[],DOUBLE gradf[]) { #define X extern #include "o8fuco.h" #undef X static INTEGER i; icgf = icgf+1; gradf[1] = 1.e0; for (i = 2 ; i <= n ; i++) { gradf[i] = 0.e0; } return;}/* **************************************************************************** *//* compute the i-th equality constaint, value is hxi *//* **************************************************************************** */void eh(INTEGER i,DOUBLE x[],DOUBLE *hxi) { #define X extern #include "o8fuco.h" #undef X return;}/* **************************************************************************** *//* compute the gradient of the i-th equality constraint *//* **************************************************************************** */void egradh(INTEGER i,DOUBLE x[],DOUBLE gradhi[]) { #define X extern #include "o8fuco.h" #undef X return;}/* **************************************************************************** *//* compute the i-th inequality constaint, bounds included *//* **************************************************************************** */void eg(INTEGER i,DOUBLE x[],DOUBLE *gxi) { #define X extern #include "o8fuco.h" #undef X static INTEGER j,k; static DOUBLE cj,fac; if ( i > 1 ) cres[i] = cres[i]+1; if ( i == 1 ) { *gxi = x[2]-dist; return; } else if ( i >= 2 && i <= 6 ) { *gxi = -x[i]+x[i+1]-dist; return; } else if ( i == 7 ) { *gxi = -x[7]+length-dist; return; } else if ( i >= 8 && i <= 170 ) { j = i-7; fac = 2.e0*pi*sin(thetaw[j]); cj = 0.5e0+cos(length*fac); for (k = 1 ; k <= 6 ; k++) { cj = cj+cos(fac*x[k+1]); } cj = cj*2.e0/15.e0; *gxi = x[1]-cj; return; } else { j = i-170; fac = 2.e0*pi*sin(thetaw[j]); cj = 0.5e0+cos(length*fac); for (k = 2 ; k <= 7 ; k++) { cj = cj+cos(fac*x[k]); } cj = cj*2.e0/15.e0; *gxi = cj+x[1]; return; }}/* **************************************************************************** *//* compute the gradient of the i-th inequality constraint *//* not necessary for bounds, but constant gradients must be set *//* here e.g. using dcopy from a data-field *//* **************************************************************************** */void egradg(INTEGER i,DOUBLE x[],DOUBLE gradgi[]) { #define X extern #include "o8fuco.h" #undef X static DOUBLE fac; static INTEGER j,k; if ( i == 1 ) return; cgres[i] = cgres[i]+1; for (j = 1 ; j <= n ; j++) { gradgi[j] = 0.e0; } if ( i >= 2 && i <= 6 ) { gradgi[i] = -1.e0; gradgi[i+1] = 1.e0; return; } else if ( i == 7 ) { gradgi[7] = -1.e0; return; } else if ( i >= 8 && i <= 170 ) { j = i-7; gradgi[1] = 1.e0; fac = 2.e0*pi*sin(thetaw[j]); for (k = 2 ; k <= 7 ; k++) { gradgi[k] = (2.e0/15.e0)*fac*sin(fac*x[k]); } return; } else { j = i-170; gradgi[1] = 1.e0; fac = 2.e0*pi*sin(thetaw[j]); for (k = 2 ; k <= 7 ; k++) { gradgi[k] = (2.e0/15.e0)*fac*(-sin(fac*x[k])); } return; }}/* **************************************************************************** *//* user functions (if bloc == TRUE) *//* **************************************************************************** */void eval_extern(INTEGER mode) { #define X extern #include "o8comm.h" #include "o8fint.h" #undef X #include "o8cons.h" return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -