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

1 次查看(过去 30 天)
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.

回答(1 个)

Matthew Eicholtz
Matthew Eicholtz 2015-10-10
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.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by