📄 matlabexa.c
字号:
/* **************************************************************************** *//* user functions *//* **************************************************************************** */#include "o8para.h"main() { void donlp2(void); donlp2(); exit(0);}/* example from matlab newgroup , showing error of fmincon *//* Change donlp's parameter smalld in order to see it! *//* **************************************************************************** *//* donlp2 standard setup *//* **************************************************************************** */void setup0(void) { #define X extern #include "o8comm.h" X DOUBLE epsfcn,taubnd; X INTEGER difftype; #undef X static INTEGER j; strcpy(name,"matlabex"); x[1] = 1.0e0; x[2] = 1.0e0; n = 2; nh = 0; ng = 2; del0 = 1.00e0; tau0 = 1.0e4; tau = .1e0; for (j = 0 ; j <= 2 ; j++) { gunit[1][j] = -1; gunit[2][j] = 0; gunit[3][j] = 0; } analyt = FALSE; epsdif = 1.e-8; nreset = 4; silent = FALSE; difftype = 3 ; epsfcn = 1.e-16; taubnd=1.0e0; return;}/* **************************************************************************** *//* special setup *//* **************************************************************************** */void setup(void) { #define X extern #include "o8comm.h" #undef X te2=TRUE; return;}/* **************************************************************************** *//* the user may add additional computations using the computed solution here *//* **************************************************************************** */void solchk(void) { return;}/* **************************************************************************** *//* objective function *//* **************************************************************************** */void ef(DOUBLE x[],DOUBLE *fx) { #define X extern #include "o8fuco.h" #undef X icf = icf+1; *fx = (x[1]+1.0e0/x[1])*(pow((x[2]-1.0e0),2)+1.0e0); return;}/* **************************************************************************** *//* gradient of objective function *//* **************************************************************************** */void egradf(DOUBLE x[],DOUBLE gradf[]) { return;}/* **************************************************************************** *//* compute the i-th equality constaint, value is hxi *//* **************************************************************************** */void eh(INTEGER i,DOUBLE x[],DOUBLE *hxi) { return;}/* **************************************************************************** *//* compute the gradient of the i-th equality constraint *//* **************************************************************************** */void egradh(INTEGER i,DOUBLE x[],DOUBLE gradhi[]) {}/* **************************************************************************** *//* compute the i-th inequality constaint, bounds included *//* **************************************************************************** */void eg(INTEGER i,DOUBLE x[],DOUBLE *gxi) { #define X extern #include "o8fuco.h" #undef X cres[i] +=1 ; if ( i == 1 ) { *gxi = x[1]+x[2]-4.0e0; } if ( i == 2 ) { *gxi = 1.0e0-pow(x[1]-3.0e0,2)-pow(x[2]-2.0e0,2); } 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[]) { return;}/* **************************************************************************** *//* user functions (if bloc == TRUE) *//* **************************************************************************** */void eval_extern(INTEGER mode) { return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -