#include <std.h>
#include <matrix.h>
#include <assert.h>
#include <libc.h>	/* for exit() */
#include <math.h>	/* for sqrt() */
#include <mnewt.h>
#include <assert.h>

matrix jacobian(C matrix& xm, C double *c, int nc)
{
 matrix rv =  matrix::identity(2);
 rv(0, 0) = -3.1415926535*sin(xm(0, 0)*3.1415926535);
 return rv;
}

matrix fejacobian(C matrix&, C double *, int, mnewt_function,
						C abstract_matrix&)
{return matrix();}

matrix testf(C matrix& x, C double *c, int nc)
{

 cout << "function evaluated at" << x << endl;
 matrix r(2, 1);
 r(0, 0) = cos(x(0, 0)*3.1415926535);
 r(1, 0) = x(1, 0)-1.0;
 cout << "the value is:" << r << endl;
 return r;
}

main()
{
 matrix start;
 mnewt_trace = TRUE;
 cout << "Starting position" << endl;
 if(!(cin >> start) || start.size()!=gdoublet(unsigned)(2, 1))	{
	cerr << "Matrix must be 2*1\n";
	exit(1);
	}
 cout << "solution:"
		<< mnewtL(testf, (double *)0, 0, start, matrix::identity(2)*0.0001,
				  	diag_matrix::identity(2)*0.0001, jacobian);
 exit(0);
}
