public void RunLorenzian() { int npts=100; //produce test data - a is a vecor with exact solution double[] x = new double[npts]; for (int i = 0; i < npts; i++) { x[i] = -5 + 0.1 *i; // NR always counts from 1 } double[] a = {1,0}; LMAFunction f = new LorenzianFunction(); double[][] dataPoints = f.GenerateData(a,x); //initial guess should be close enough LMA algorithm = new LMA(f,new double[] {5, 5}, dataPoints, null, new GeneralMatrix(2,2),1d-20,100); algorithm.Fit(); for (int i=0; i<a.Length; i++) { Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i]-a[i])<0.0001); Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString()); } Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString()); }
public void RunLorenzian() { int npts = 100; //produce test data - a is a vecor with exact solution double[] x = new double[npts]; for (int i = 0; i < npts; i++) { x[i] = -5 + 0.1 * i; // NR always counts from 1 } double[] a = { 1, 0 }; LMAFunction f = new LorenzianFunction(); double[][] dataPoints = f.GenerateData(a, x); //initial guess should be close enough LMA algorithm = new LMA(f, new double[] { 5, 5 }, dataPoints, null, new GeneralMatrix(2, 2), 1d - 20, 100); algorithm.Fit(); for (int i = 0; i < a.Length; i++) { Assert.IsTrue(System.Math.Abs(algorithm.Parameters[i] - a[i]) < 0.0001); Trace.WriteLine("Parameter" + i.ToString() + " " + algorithm.Parameters[i].ToString()); } Trace.WriteLine("# of iterations =" + algorithm.Iterations.ToString()); }