⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex_3qn3.c

📁 an quasi-newton method used in non-linear programming and especially in optimization
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include "math_util.h"int n_fun;main(){    clock_t time_0, time_1;    long double dtime;    long double tol, *x;    int n;    long double ex3_fun( long double * );    void q_newton_3( long double(*)(),                 long double *, int, long double );    	n_fun = 0;	n = 4;	x = a1d_allo_dbl( n );	vec_null( x, n );	tol = 1.0e-4;	    time_0 = clock();    q_newton_3( ex3_fun, x, n, tol );    time_1 = clock();    dtime = (long double)(time_1-time_0)/((long double)CLOCKS_PER_SEC);        printf("Solution x: ");print_vec_dbl( x, n );    printf("\n # of function evaluations: %d\n",n_fun);    printf(" Solution time: %Le",dtime);}/*	Wood function*/long double ex3_fun( x )long double *x;{   long double f, t1, t3, t5, t6, t8, t10, t11, t12, t13, t14,                x1, x2, x3, x4;      n_fun++;      x1 = x[0];   x2 = x[1];   x3 = x[2];   x4 = x[3];   t1 = x1*x1;   t3 = pow(x2-t1,2.0);   t5 = pow(1.0-x1,2.0);   t6 = x3*x3;   t8 = pow(x4-t6,2.0);   t10 = pow(1.0-x3,2.0);   t11 = x2-1.0;   t12 = t11*t11;   t13 = x4-1.0;   t14 = t13*t13;   f = 100.0*t3+t5+90.0*t8+t10+0.101E2*t12+0.101E2*t14+0.198E2*t11*t13;        return( f );}/****  Norm( h ) <= epsSolution x:  1.000000e+00  9.999999e-01  1.000001e+00  1.000002e+00 # of function evaluations: 1272 Solution time: 6.833333e+00 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -