Thank you for your fast response.
Howerver, I'm not familiar with the alglib yet. Can you elaborate it more?
Below is my example. As you can see, the method Getvalue() contains the array. The method fvec1() will get the first 3 of this array, and the next 3 value is for fvec2(), etc. And the fvec1 and fvec2 are the same template, just different from the value of array.
So, how to create a for loop for calculate the result in Main() which method fvec() can automatic realize the of array's value corresponding with step of the for loop? I just want to use only 1 fvec, not creating the second one.
Thanks again!
---------------------------------------------------------------------------------------------------- public static double[,] GetValue() { double[,] L = { { 806, 806, 806 }, { 607, 607, 607 }, {702, 702, 702} }; return L; }
public void function_fvec1(double[] p, double[] fi, object obj) { // Set static value double[] a1 = { (-435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a2 = { (435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a3 = { 0, 435, 0 };
// Array of value double[,] L = GetValue(); double[] l = { L[0, 0], L[0, 1], L[0, 2] };
// This is call back calculation fi[0] = Math.Pow(a1[0] - p[0] + 35 * Math.Cos(Math.PI / 6), 2) + Math.Pow(a1[1] - p[1] + 35 * Math.Sin(Math.PI / 6), 2) + Math.Pow(a1[2] - p[2], 2) - Math.Pow(l[0], 2);
fi[1] = Math.Pow(a2[0] - p[0] - 35 * Math.Cos(Math.PI / 6), 2) + Math.Pow(a2[1] - p[0] + 35 * Math.Sin(Math.PI / 6), 2) + Math.Pow(a2[2] - p[2], 2) - Math.Pow(l[1], 2);
fi[2] = Math.Pow(a3[0] - p[0], 2) + Math.Pow(a3[1] - p[1] - 35, 2) + Math.Pow(a3[2] - p[2], 2) - Math.Pow(l[2], 2); }
public void function_fvec2(double[] p, double[] fi, object obj) { // Set static value double[] a1 = { (-435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a2 = { (435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a3 = { 0, 435, 0 };
// Array of value double[,] L = GetValue(); double[] l = { L[1, 0], L[1, 1], L[1, 2] };
// This is call back calculation fi[0] = Math.Pow(a1[0] - p[0] + 35 * Math.Cos(Math.PI / 6), 2) + Math.Pow(a1[1] - p[1] + 35 * Math.Sin(Math.PI / 6), 2) + Math.Pow(a1[2] - p[2], 2) - Math.Pow(l[0], 2);
fi[1] = Math.Pow(a2[0] - p[0] - 35 * Math.Cos(Math.PI / 6), 2) + Math.Pow(a2[1] - p[0] + 35 * Math.Sin(Math.PI / 6), 2) + Math.Pow(a2[2] - p[2], 2) - Math.Pow(l[1], 2);
fi[2] = Math.Pow(a3[0] - p[0], 2) + Math.Pow(a3[1] - p[1] - 35, 2) + Math.Pow(a3[2] - p[2], 2) - Math.Pow(l[2], 2); }
static void Main(string[] args) { // Set static value double[] a1 = { (-435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a2 = { (435 * Math.Cos(Math.PI / 6)), (-435 * Math.Sin(Math.PI / 6)), 0 }; double[] a3 = { 0, 435, 0 };
double[] plow; double[] phigh;
double[] p = new double[] { 0, 0, -710 }; double[] s = new double[] { 1, 1, 1 }; double epsx = 0.0000000001; int maxits = 0; alglib.minlmstate state;
determine_bc(a1, a2, a3, out plow, out phigh);
alglib.minlmcreatev(3, p, 0.0001, out state); alglib.minlmsetbc(state, plow, phigh); alglib.minlmsetcond(state, epsx, maxits); alglib.minlmsetscale(state, s);
// Optimize alglib.minlmoptimize(state, function_fvec1, null, null);
// Test result alglib.minlmreport rep; alglib.minlmresults(state, out p, out rep); Console.WriteLine("\n This is result: \n {0}", alglib.ap.format(p, 5));
}
|