필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Nick Haufler
Nick Haufler 2015년 10월 9일
답변: Matthew Eicholtz 2015년 10월 10일
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