Simple minimization algorithm in a while loop?
Show older comments
Hello,
I have a program (call it blackbox) and I give this program a value (zo) and it does a calculation and checks if the result (diff) is within a certain tolerance (tol).
What I would like to do is to have it minimize in as few iterations as possible. It would be ideal to have the steps increase/decrease dynamically. Anyone have suggestions?
Here is what I was thinking.
%input value to start
zo = 15;
% +/- tolerance
tol = 0.1;
% start while loop
diff = 1;
count = 0;
while abs(diff) > tol
% black box algorithm
diff = zo/2 - 2
% check if value is within the tolerance
% is there a better way to do this in less iterations?
if diff > tol
zo = zo - 0.1;
elseif diff < -tol
zo = zo + 0.1;
end
count = count +1
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!