While loop and previous values

2 visualizaciones (últimos 30 días)
Una Ib
Una Ib el 26 de Nov. de 2017
Editada: KL el 26 de Nov. de 2017
So, I have a vector x, with the starting values x0=[0;0;0]
while abs(x(1)-y(1))> epsilon || abs(x(2)-y(2))> epsilon || abs(x(3)-y(3))> epsilon
dk = -f_gradient(x);
alphak = (dk' * dk)/(dk' * A * dk);
x = x + alphak * dk;
end
How do I set the starting value here? I can't write x= x0+ alphak * dk for obvious reasons, and I cant use a for loop because I don't know what the endindex in the while loop will be. Is there a possibility to add another while loop inside my loop that adds to x for as long as the first while loop holds? If so, how would I write that? Thanks a lot :)

Respuestas (1)

KL
KL el 26 de Nov. de 2017
Editada: KL el 26 de Nov. de 2017
I suppose y is a constant 3x1 vector and only x is changing in this while loop. So simply assign the intial values of x to x itself,
x = x0;
while any(abs(x-y)>epsilon)
%code
end
I do not understand the "obvious reasons", if the above doesn't make any sense because of your f_gradient function, what value are you assigning to x in the first place?

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by