How can I use while or for in first gradient method?

1 visualizzazione (ultimi 30 giorni)
syms x1;
syms x2;
f = 2*x1^2 + 3*x2^2 - 5*x1*x2 + 10*x1 + 5*x2
gr1=diff(f, x1);
x0=[2;2];
gr1=subs(gr1, x1, x0(1));
gr1=subs(gr1, x2, x0(2));
gr2=diff(f, x2);
gr2=subs(gr2, x1, x0(1));
gr2=subs(gr2, x2, x0(2));
gr=[gr1; gr2]
D=(gr)/(sqrt(gr1^2 + gr2^2));
D=[8*113^(1/2)/113; 7*113^(1/2)/113]
S=1;
x01=x0-S*D
fx01= 2*x01(1)^2 + 3*x01(2)^2 - 5*x01(1)*x01(2) + 10*x01(1) + 5*x01(2)
prm=sqrt(D(1)^1 + D(2)^2)
fx0=2*x0(1)^2 + 3*x0(2)^2 - 5*x0(1)*x0(2) + 10*x0(1) + 5*x0(2);
doa=fx0-fx01
epsilon=0.1;
  1 Commento
Jan
Jan il 8 Gen 2021
The question is not clear, because you did not mention the purpose of the loop. Then it is impossible to guess reliably, where it has to be inserted with which conditions. Please edit the question an add the details.

Accedi per commentare.

Risposte (0)

Tag

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by