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 views (last 30 days)
Show older comments
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 Comment
Jan
on 27 Oct 2022
Edited: Jan
on 27 Oct 2022
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.
Answers (0)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!