I've included an artificial gradient funtion, i.e. all zeros but one 1 in one of the rows and I get exactly the same solution than with the real gradient function.
The code to generate the matices is quite long but the optimization part is:
alglib.minbleicstate state; alglib.minbleicreport rep; double epsg = 0.000001; double epsf = 0; double epsx = 0; double epso = 0.00001; double epsi = 0.00001; alglib.minbleiccreate(ndivX * ndivY, Press, out state); alglib.minbleicsetlc(state, c, ct); alglib.minbleicsetinnercond(state, epsg, epsf, epsx); alglib.minbleicsetoutercond(state, epso, epsi); alglib.minbleicoptimize(state, func_grad, null, null); alglib.minbleicresults(state, out Press, out rep);
Where func_grad:
public void func_grad(double[] x, ref double func, double[] grad, object obj) { func = prodEsc(AB, x) + 0.5 * BilinealForm(x, T, x); grad = sumVect(AB, ProdMatVect(T, x)); return; }
prodEsc is a dot product funtion BilinealForm makes the xT*A*x operations and sumVect adds two vectors
|