Proper usage of dlgradient
이전 댓글 표시
I have two 10×1 dlarrays, namely y and x.
I am trying to find gradient of (y,x) by running dlgradient command inside a for-loop.
Inside the for-loop, I execute dlgradient(y(i),x). But the loop always returns 0 as output of dlgradient(dx(i),x). So, as output, I get zero matrix of order 10×10.
After a thorough internet search, my understanding is that dlgradient requires y to be a function of x and if we provide constant values for y, it differentiates the constant and returns 0.
Is my understanding correct or is there a way to find dlgradient with numerical values as input?
The code and its output are below:
y = dlarray( [ -12000; -12000; 40973; 0; 0; 0; 0; 0; 2199.1; -4084.1 ] )
x = dlarray( [ 10; 10; 1100; 0; 0; 0; 563; 0; 10; 10 ] )
grad = dlfeval(@dlJacobian,y,x)
function [Jac] = dlJacobian(y,x)
for i = 1 : length(y)
Jac(i,:) = dlgradient(y(i),x);
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Just for fun에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!