Basically you want your code to look something like this pseudocode:
1) initialize variables
2) while (the approximation is not close enough to the known value)
2a) add another term to your approximation
There's awhile loop in step 2, but the condition is not 1. There is nofor loop in the pseudocode. I can't say much more without simply giving you the code.
In general, if you're still unsure about howwhile loops work, I think one way you can understand them better is to walk through the first example (calculatingfactorial(10)) on itsdocumentation page yourself, with you playing the role of MATLAB. Take a piece of paper and a pencil and "execute" each line yourself, recording the values of variables as they change on that paper. [When you reach theend statement, return to thewhile statement. If thewhile condition is not satisfied, go to the statement immediately after theend.]
Best Answer