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
Error using indexing
Not enough inputs to inline function.
fprintf('optimal solution x =[%f, %f] \n' , x0(1), x0(2));
fprintf('optimal value f(x) = %f \n' , fobj (x0));v
  1 个评论
Jan
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 CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by