While loop and previous values
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 :)
0 Kommentare
Antworten (1)
KL
am 26 Nov. 2017
Bearbeitet: KL
am 26 Nov. 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?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!