please assist in line 18 , where " H = Hx (x0); " the error its giving me it says 'untitled' i am using steepest descent method for a school project
조회 수: 4 (최근 30일)
이전 댓글 표시
syms x1 x2
f1 = x1 ^2 * x2 + x1 *x2^2 - 3 *x1 *x2 ;
fx = inline (f1) ;
fobj = @ (x) fx (x (:,1 ), x(: ,2));
grad = gradient (f1);
G = inline(grad);
gradx = @ (x) G (x(: , 1),x(:,2));
H1 = hessian (f1);
Hx = inline (H1);
x0= [1 2];
maxiter = 4;
tol = 1e-3 ;
iter = 0;
X = [];
while norm(gradx(x0)) > tol && iter < maxiter
X = [X ; x0];
d = -gradx(x0);
H = Hx (x0) ;
lam = d' * d./ d' * H * d ;
Xnew = x0 + lam.* d' ;
x0 = Xnew;
iter = iter + 1;
end
fprintf('optimal solution x =[%f, %f] \n' , x0(1), x0(2));
fprintf('optimal value f(x) = %f \n' , fobj (x0));v
댓글 수: 1
Jan
2022년 10월 27일
편집: Jan
2022년 10월 27일
I let your code run to get the error message and inserted in in your question. This does not match your vague description "it says 'unitled'".
Please post a copy of the complete message, if you see another error. A rough paraphrasation is not useful to explain, what the error is.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!