Calculating the gradient of a function
이전 댓글 표시
Hello. I want to calculate the gradient of this function at the point xc:
function MSE=mseFunction(alpha,beta,y,yS)
MSE = [alpha beta; y yS];
end
xc = [100; 102];
y = 20;
yS = 50;
how I should proceed. Thanks!
답변 (1개)
Marco Morganti
2017년 1월 5일
편집: Marco Morganti
2017년 1월 6일
Hi Amine,
you could use gradient() along with symbolic variables to find the gradient of your function MSE().
syms parameters;
f = mseFunction(parameters);
g = gradient(f);
at this point you can evaluate g() at the desired point:
g_xc = eval(subs(g,xc));
I hope this helps
댓글 수: 4
Walter Roberson
2017년 1월 5일
You should never eval() a symbolic expression. Symbolic expressions are in a language that is slightly different than MATLAB. You can matlabFunction the result of gradient() and pass c to that.
amine&&
2017년 1월 5일
Walter Roberson
2017년 1월 5일
syms parameters;
f = mseFunction(parameters);
g = gradient(f);
gfun = matlabFunction(g); %rather than eval()
g_xc = gfun(xc);
카테고리
도움말 센터 및 File Exchange에서 General PDEs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!