aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2012-02-15 15:39:13 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2012-02-15 15:39:13 +0000
commit3b2ea2fcbc7ea22506fd82015937a7f93d8dbc34 (patch)
tree09ce4b82461baa6ab116c7b12bb121ba72411aed
parentcd463edb6e95e7b5eab8848e3438a8b07a6681b5 (diff)
downloadopt-utilities-3b2ea2fcbc7ea22506fd82015937a7f93d8dbc34.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@221 ed2142bd-67ad-457f-ba7c-d818d4011675
-rw-r--r--interface/c_example.cc16
-rw-r--r--interface/fortran_example.f9017
2 files changed, 33 insertions, 0 deletions
diff --git a/interface/c_example.cc b/interface/c_example.cc
new file mode 100644
index 0000000..0fb6d43
--- /dev/null
+++ b/interface/c_example.cc
@@ -0,0 +1,16 @@
+#include "opt.h"
+#include <iostream>
+using namespace std;
+
+double foo(const double* p)
+{
+ return p[0]*p[0]+(p[1]-1)*(p[1]-1);
+}
+
+int main()
+{
+ double p[2]={1000,1000};
+ optimize_powell(foo,2,p,1e-40);
+ optimize_powell(foo,2,p,1e-40);
+ cout<<p[0]<<"\t"<<p[1]<<endl;
+}
diff --git a/interface/fortran_example.f90 b/interface/fortran_example.f90
new file mode 100644
index 0000000..3b0d7b0
--- /dev/null
+++ b/interface/fortran_example.f90
@@ -0,0 +1,17 @@
+function foo(p)
+ double precision foo
+ double precision p(2)
+ foo=p(1)**2+p(2)**2;
+ return
+end function foo
+
+
+program main
+ double precision foo
+ double precision p(2)
+ p(1)=4
+ p(2)=5
+ write(*,*) p,foo(p)
+ call optimize_powell(foo,2,p,1E-10)
+ write(*,*) p,foo(p)
+end program main