Why does my function give no outputs?

10 views (last 30 days)
function [A]=AccGold()
n = 4;
while Gold(n)-Gold(n-1) > 0.00000001
n = n+1;
A = Gold(n)
end
end
I want to find the first value of Gold(n)-Gold(n-1) such that it is < 0.0000001

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jan 2016
Edited: Walter Roberson on 25 Jan 2016
If the condition is immediately false you never assign to A.
  2 Comments
Joshua Hall
Joshua Hall on 25 Jan 2016
I want the loop to run until n is such that Gold(n)-Gold(n-1)<0.0000001, and then I want the value of Gold(n) at this n. Is there an easy way to change my function to do this?

Sign in to comment.

More Answers (0)

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!