求 min f=4x2-x12+x2-42 选择初始点x011写出matlab代码
syms x1 x2 f = 4*(x2-x1)^2 + (x2-4)^2; x0 = [1;1]; grad_f = gradient(f); H_f = hessian(f); tol = 1e-6; k = 0; while norm(subs(grad_f, [x1;x2], x0))>=tol k = k+1; pk = -inv(subs(H_f, [x1;x2], x0))subs(grad_f, [x1;x2], x0); alpha = 0.5; beta = 0.5; while subs(f, [x1;x2], x0+alphapk) > subs(f, [x1;x2], x0)+alphabetasubs(grad_f, [x1;x2], x0)'pk alpha = alphabeta; end x0 = x0+alpha*pk; end k x0
原文地址: https://www.cveoy.top/t/topic/fqYF 著作权归作者所有。请勿转载和采集!