1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <stdio.h>
#include <math.h>
#include "wnlib.h"
#include "wnsll.h"
#include "wnasrt.h"
#include "wnhash.h"
#include "wnrndd.h"
#include "wnswap.h"
#include "wnsqr.h"
#include "wnvect.h"
#include "wnconj.h"
local double function(double x)
{
double ret;
ret = 1.0/x + x;
printf("x = %20.20lf,f = %20.20lf\n",x,ret);
return(ret);
}
/*
local double function(double x)
{
double ret;
ret = x-1.6666;
if(ret > 0)
{
ret *= 20.0;
}
else
{
ret *= -1.0;
}
ret += 1.5555;
printf("x = %20.20lf,f = %20.20lf\n",x,ret);
return(ret);
}
*/
void main(void)
{
double f0,f1,f2,x0,x1,x2;
int code;
wn_gpmake("no_free");
x0 = 0.001;
f0 = function(x0);
x1 = 1.5;
f1 = function(x1);
x2 = 2.0;
f2 = function(x2);
wn_minimize_1d_raw(&code,
&f0,&f1,&f2,&x0,&x1,&x2,
&function);
printf("code = %d,f0=%lf,f1=%lf,f2=%lf,x0=%lf,x1=%lf,x2=%lf\n",
code,f0,f1,f2,x0,x1,x2);
}
|