while command in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
while using the while command in matlab how can I determine the no. of terms needed so that the product 2x4x6...x2n exceeds a given number N ?
x is multliplication
댓글 수: 0
채택된 답변
Jordan Monthei
2013년 5월 8일
편집: Jordan Monthei
2013년 5월 8일
A while statement operates as follows:
while (condition)
{
perform action
}
end
As such, if you were to have a while loop with a condition that your product is less than your maximum N, it will run the loop until the product exceeds N at which point the condition is met.
Within the loop then, you would want to have the number continue to multiply as long as it is running. This would leave you with something as follows:
n = 1;
Product = 1;
while( Product < N )
{
Product = Product * (2*n);
n = n + 1;
}
end
with that you could have some variable that increments every time the while statement goes through in order to count how many iterations occur until you exceed your maximum.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!