While loop and previous values
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
KL
on 26 Nov 2017
Edited: KL
on 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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!