example for solving a system of n non-linear equations with n unkowns using the powell hybrid method.
- Author
- MIP
#include <Base/Common/BIASpragma.hh>
#include <MathAlgo/Minpack.hh>
#include <Base/Math/Random.hh>
#include <Base/Math/Vector.hh>
#include <Base/Math/Matrix3x3.hh>
#include <Base/Math/Vector3.hh>
using namespace BIAS;
using namespace std;
int num;
int myfunc(void *p, int n, const double *x, double *fvec, int iflag)
{
cerr << setw(3)<< num<<" : "<<x[0]<<"\t"<<x[1]<<"\t"<<x[2]<<" :: \t";
fvec[0]=m2[0]-sin(x[0])*m1[0];
fvec[1]=m2[1]-cos(x[1])*m1[1];
fvec[2]=m2[2]-sin(x[2])*m1[2];
cerr << fvec[0]<<"\t"<<fvec[1]<<"\t"<<fvec[3]<<endl;
num++;
return 0;
}
int main()
{
int res=0;
num=0;
mat[0][0]=sin(groundtruth[0]);
mat[1][1]=cos(groundtruth[1]);
mat[2][2]=sin(groundtruth[2]);
cout << "mat: "<<mat<<endl;
if (
Powell(myfunc,NULL, InitialGuess, Result)!=0){
BIASERR("error in Powell ");
return -1;
}
cout << "ground truth : "<<groundtruth
<<"\nnon linear estimate : "<<Result<<endl;
return res;
}