Filter löschen
Filter löschen

value in each iteration

3 Ansichten (letzte 30 Tage)
saja mk
saja mk am 19 Sep. 2020
Kommentiert: Walter Roberson am 19 Sep. 2020
f=@(x) 0.5*(x(1)-1).^2+10*(x(2)+2).^2-2
miter=10000
and i have loop
for i=1:miter
then,who i can to calculate f(i)-f(i-1)?
  6 Kommentare
saja mk
saja mk am 19 Sep. 2020
@Walter Roberson
so how can i implement it ?
Walter Roberson
Walter Roberson am 19 Sep. 2020
You cannot. Your gradient descent formula is only valid for functions of one variable.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

saja mk
saja mk am 19 Sep. 2020
but i get the optimal in GDA
x0=[2 2]';
% tol=1e-6;
miter=10000;
% dxmin=1e-6;
alpha=0.01;
% gnorm=inf;
x=x0;
niter=1;
% dx=inf;
for i=1:miter
g=[(x(1)-1); 20*(x(2)+2)];
f=@(x) 0.5*(x(1)-1).^2+10*(x(2)+2).^2-2 ;
xnew = x - alpha*g;
fnew=f(xnew);
if abs(xnew-x)<=0.00001
break
end
% niter=niter+1;
x=xnew;
end
xopt=x;
niter=niter+1;
after run :
xopt =
1.0010
-2.0000
  1 Kommentar
Walter Roberson
Walter Roberson am 19 Sep. 2020
this does not use the epsilon formula from https://www.mathworks.com/matlabcentral/answers/596404-value-in-each-iteration#comment_1015369

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by