diff options
-rw-r--r-- | interface/c_example.cc | 16 | ||||
-rw-r--r-- | interface/fortran_example.f90 | 17 |
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 |