matlabch01

Loops There are two types of explicit loops in MATLAB; ? the for loop, used when the number of passes is known ahead of time, and ? the while loop, used when the looping process must terminate when a specified condition is satisfied, and thus the number of passes is not known in advance. 1-50 A simple example of a for loop is m = 0; x(1) = 10; for k = 2:3:11 m = m+1; x(m+1) = x(m) + k^2; end k takes on the values 2, 5, 8, 11. The variable m indicates the index of the array x. When the loop is finished the array x will have the values x(1)=14,x(2)=39,x(3)=103,x(4)=224. 1-51 A simple ex

文档评论(0)

1亿VIP精品文档

相关文档