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

1 vue (au cours des 30 derniers jours)
Nick Haufler
Nick Haufler le 9 Oct 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.

Réponses (1)

Matthew Eicholtz
Matthew Eicholtz le 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by