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

1 visualización (últimos 30 días)
Nick Haufler
Nick Haufler el 9 de Oct. de 2015
Respondida: Matthew Eicholtz el 10 de Oct. de 2015
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.

Respuestas (1)

Matthew Eicholtz
Matthew Eicholtz el 10 de Oct. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by