How to use dlgradient for computing second derivative?
显示 更早的评论
The following code gives me an error.
x0 = dlarray([-1,2]);
[fval,gradval] = dlfeval(@rosenbrock,x0)
function [y,dy2dx] = rosenbrock(x)
y = 100*(x(2) - x(1).^2).^2 + (1 - x(1)).^2;
dydx = dlgradient(y,x);
dy2dx= dlgradient(dydx,x);
end
I am using dlgradient to compute the second derivative but getting the following error:
"Error using dlfeval (line 43)
Value to differentiate must be a traced dlarray scalar."
Any help on what am i doing wrong? Thanks.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!