Finding the gradient and the hessian of the same function

If I have the function
fv = @(x) x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
What would be the best way to find the hessian of said function?

 Respuesta aceptada

KSSV
KSSV el 7 de Nov. de 2022
Read about gradient, hessian.

7 comentarios

Howie
Howie el 7 de Nov. de 2022
Editada: Howie el 7 de Nov. de 2022
When I try computing the hessian, I get the following
fv = @(x) x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
hessian(fv,[x(1),x(2)])
Unrecognized function or variable 'x'.
jacobian(gradient(fv))
syms x y
fv = x^2 + x*y + (3/2)*y^2 - 2*log(x) - log(y);
hessian(fv,[x,y])
If you want x(1) and x(2) like:
syms x [1 2]
fv = x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
hessian(fv,x)
And how would we find the gradient?
In the same way...read the doc.
syms x [1 2]
fv = x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
%hessian(fv,x)
[x(1),x(2)] = gradient(fv)
Error using sym/gradient
Too many output arguments.
I get an error when trying to use gradient function
Same way means:
syms x [1 2]
fv = x(1)^2 + x(1)*x(2) + (3/2)*x(2)^2 - 2*log(x(1)) - log(x(2));
g = gradient(fv,x)
g = 

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2022a

Preguntada:

el 7 de Nov. de 2022

Comentada:

el 7 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by