How to get each iteration to be outputted in a while loop?

2 views (last 30 days)
In the attached document, I cant get each iteration of the taylor series to display until the difference is so close to zero where it stops. There are a series of sections in the equation, but i cant get each one to display. My 'estimate' variable is where the equation lies.

Answers (1)

Matthew Eicholtz
Matthew Eicholtz on 10 Oct 2015
A few things:
1. I think your variable Estimate is defined incorrectly. Check to make sure it matches the equation in your pdf.
2. No need for the line of code Previous = count.
3. You are not summing the terms in the series. So when you define Estimate, it should be something like:
Estimate = Estimate + ...
4. Now to display the current value so you can watch it as it converges, I suggest putting something like fprintf inside your while loop:
fprintf('%d\t%0.3f\n',count,Estimate);
Make sure to put semicolons at the end of each variable definition so they do not print to the Command Window.
Hope this helps.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!