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

📄 test_quartic.c

📁 快速傅立叶变换程序代码,学信号的同学,可要注意了
💻 C
字号:
#include "../newansi/r.h" /* #include "../newansi/mynr.h" */#include "../newansi/macopt.h"/*    test program for macopt solution of equation A x = b + quartic stuff.    this equation is solved by minimizing the function 1/2 xAx - bx  + quartic stuff   example usage:   22 1 1 21 11.01.3 2.31.0 1.0can we do 1-d?   1211.01.31.0*/   #include "test.h"void state_printer ( double *w, int its, void *arg ) ;void main(int argc, char *argv[]){  gq_args param;  macopt_args a ;  double *x ;  int n , status ;  double epsilon=0.001 ;  /* Load up the parameters of the function that you want to optimize */  printf("============================================================\n");  printf("= Demonstration program for macoptIIc                      =\n");  printf("= Solves A x = b + quartic stuff                           =\n");  printf("= A must be positive definite (e.g. 2 1 1 2)               =\n");  printf("\n  Dimension of A (eg 2)?\n");  inputi(&(param.n));  n=param.n;   param.A=dmatrix(1,n,1,n);  param.b=dvector(1,n);  /* the metric! : */  a.m=dvector(1,n);  x=dvector(1,n);  typeindmatrix(param.A,1,n,1,n);  printf("  b vector?\n");  typeindvector(param.b,1,n);  printf("  q4?\n");  inputd(&(param.q4)) ;   printf("  Initial condition x?\n");  typeindvector(x,1,n);  printf("  Metric m?\n");  typeindvector(a.m,1,n);  /* Check that the gradient_function is the gradient of the function  */  /* You don't have to do this, but it is a good idea when debugging ! */  maccheckgrad (  x , param.n , epsilon , 		quartic , (void *)(&param) , 		vgrad_quartic , (void *)(&param) , 		0		) ;  /* initialize the arguments of the optimizer */  macopt_defaults ( &a ) ;   /* modify macopt parameters from their default values */  a.do_newitfunc = 1 ; /* this means that I want to have an auxiliary			  subroutine executed each iteration of the 			  optimization */  a.newitfunc = &state_printer ; /* setting the function to be performed to				  T_return */  a.newitfuncarg = (void *)(&param) ;  a.metric = 1 ; /* we have put in the metric and want to use it */  a.verbose = 2 ; /* verbosity */  a.rich = 0 ; /* verbosity */  a.lastx = 10.0 ; /* typical step size expected */  a.lastx_default = 10.0 ; /* typical step size expected */    /* Do an optimization */  status = macoptIIc ( x , param.n , 	    vgrad_quartic , (void *)(&param) , &a	    ) ;  printf("(%d) Solution:\n", status);  quartic(x,&param);}void state_printer ( double *w, int its, void *arg )                     /* this routine is called by the			macopt optimizer ; it reports parameter			values during the optimization */{  int i ;   gq_args *param = ( gq_args * ) arg ;  printf ( "\n----------------------\n");  printf ( "      state_printer:\n");  printf ( "Line minimization %d is starting, and the latest params are\n" , its );  for ( i = 1 ; i <= param->n ; i++ ) printf ( "%g " , w[i] ) ;  printf ( "\n" ) ;  printf ( "----------------------\n");}

⌨️ 快捷键说明

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