a problem with implementing Gradient descent

조회 수: 4 (최근 30일)
Maria Sargsyan
Maria Sargsyan 2015년 11월 21일
댓글: Walter Roberson 2015년 11월 22일
Hi
I wrote the following programm implementation of gradient descent. But when I run the programm it works really slow . I guess it is because of the symbolic differentiation or maybe there is another problem in the implementaion . Can, you tell me what is wrong ?
function y = grad(x0,y0,z0,f,m1,m2)
syms a;
symsb;
symc c;
n=0;
if (length(symvar(diff(f,a))==3)&& length(symvar(diff(f,b))==3) && length(symvar(diff(f,c))==3))
f_a = matlabFunction(diff(f,a),[a,b,c]);
f_b=matlabFunction(diff(f,b),[a,b,c]);
f_c=matlabFunction(diff(f,c),[a,b,c]);
else
y= 0;
return;
end
delta = -1*[f_a(x0,y0,z0), f_b(x0,y0,z0), f_c(x0,y0,z0)];
phi = @(t) ( f(x0+t*delta(1), y0+t*delta(2), z0+t*delta(3)) );
min = GRSMethod( phi,m1,m2 );
while ( abs ( min * ( delta(1)^2+delta(2)^2+delta(3)^2 ))> 10^ (-5) || n<100)
x0=x0+min*delta(1);
y0= y0+min*delta(2);
z0=z0+min*delta(3);
delta = -1*[f_a(x0,y0,z0), f_b(x0,y0,z0), f_c(x0,y0,z0)];
min = GRSMethod( phi,m1,m2 );
n=n+1;
end
y = [ x0,y0,z0];
end
Sincerely, Maria
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 11월 22일
Do not use "min" as the name of a variable: it interferes with using "min" as the name of the MATLAB and MuPAD routine.

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

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by