Calculating the gradient of a function

조회 수: 2 (최근 30일)
amine&&
amine&& 2017년 1월 5일
편집: Marco Morganti 2017년 1월 6일
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
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
amine&&
amine&& 2017년 1월 5일
Hi Walter, even typing :
f = @(x)mseFunction(x(1),x(2),y,yS)
g = gradient(f)
I get :
Undefined operator '.'' for input arguments of type 'function_handle'.
Error in gradient>parse_inputs (line 146)
f = f.';
Error in gradient (line 48)
[f,ndim,loc,rflag] = parse_inputs(f,varargin);
Walter Roberson
Walter Roberson 2017년 1월 5일
syms parameters;
f = mseFunction(parameters);
g = gradient(f);
gfun = matlabFunction(g); %rather than eval()
g_xc = gfun(xc);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by