where
is solved. An initial guess (-1.2, 1.0) is supplied, as well as the analytic Jacobian. The residual at the approximate solution is returned.
using System; using Imsl.Math; public class BoundedLeastSquaresEx2 : BoundedLeastSquares.IJacobian { public void F(double[] x, double[] f) { f[0] = 10.0 * (x[1] - x[0] * x[0]); f[1] = 1.0 - x[0]; } public void Jacobian(double[] x, double[] fjac) { fjac[0] = - 20.0 * x[0]; fjac[1] = 10.0; fjac[2] = - 1.0; fjac[3] = 0.0; } public static void Main(String[] args) { int m = 2; int n = 2; int ibtype = 0; double[] xlb = new double[]{- 2.0, - 1.0}; double[] xub = new double[]{0.5, 2.0}; BoundedLeastSquares.IJacobian rosbck = new BoundedLeastSquaresEx2(); BoundedLeastSquares zf = new BoundedLeastSquares(rosbck, m, n, ibtype, xlb, xub); zf.SetGuess(new double[]{- 1.2, 1.0}); zf.solve(); new PrintMatrix("Solution").Print(zf.GetSolution()); new PrintMatrix("Residuals").Print(zf.GetResiduals()); } }
Solution 0 0 0.5 1 0.25 Residuals 0 0 0 1 0.5Link to C# source.