File: examples6.c

package info (click to toggle)
libwn6 6.0-17
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 6,012 kB
  • ctags: 3,903
  • sloc: ansic: 45,078; makefile: 960; csh: 274; sh: 17
file content (70 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include <math.h>

#include <wn/wnlib.h>
#include <wn/wnconj.h>
#include <wn/wnmem.h>

local double function(double x)
{
  double ret;

  ret = 1.0/x + x;

  printf("x = %20.20f,f = %20.20f\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.20f,f = %20.20f\n",x,ret);

  return(ret);
}
*/


int 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,0.,
		     &function,100);

  printf("code = %d,f0=%f,f1=%f,f2=%f,x0=%f,x1=%f,x2=%f\n",
	 code,f0,f1,f2,x0,x1,x2);
  return 0;
}