16. Chapter 2: Solving a Problem Specifying the For Loo To obtain the additional 24 points, use a for loop. a for loop repeatedly executes a sequence of Maple commands entered between the for and end commands of the loop, that is, in the loop body. It executes the commands as the value of a numeric variable, called an index, varies from its specified initial value to its specified final value. The value of the index is incremented after each execution of the commands in the body of the loop. The iteration stops when the value of the index is greater than the specified final value. For information on other programming structures in Maple, refer to the Maple Introductory Programming Guide To start the for loop At the prompt, enter the following and press ENTER. for i from 1 to 24 do Note: After you press ENTER, Maple returns the message: "Warning, premature end of input. " It is simply reminding you that the for statement is not complete. To continue entering your input without receiving this warning, use SHIFT+ENTER to go to the next line The next commands comprise the body of the for loop. These commands find the skier's position at the end of each time step. To construct the 3-D normalized negative of the gradient vectors At the prompt, enter the following and press ENTER route 3d[i]: LinearAlgebra[ Normalize](eval(<-gx,-gy, 0> P=point3d[i])) To find the next point in the skier's path At the prompt, enter the following and press ENTER. point3d[i+1]: eval(<P[l], P[2], g>, P=point3d[i]+timestep*routed[i]); To complete the for loop At the prompt, enter the following and press ENTER. Remember to end the line with a colon to suppress the output This command ends the for loop. After you press ENTER, the five commands in the loop body are repeated 24 times. At the end of each iteration, the value of i is increased by 1. That is, for the first iteration, the value of i is its initial value 1. for the second 2, and so on for the last iteration the value of i is 24 Maple exits at the end of the 24th iteration once i is set to 25(since 25 is outside of the bounds of the loop16 • Chapter 2: Solving a Problem Specifying the For Loop To obtain the additional 24 points, use a " loop. A " loop repeatedly executes a sequence of Maple commands entered between the " and commands of the loop, that is, in the loop body. It executes the commands as the value of a numeric variable, called an index, varies from its specified initial value to its specified final value. The value of the index is incremented after each execution of the commands in the body of the loop. The iteration stops when the value of the index is greater than the specified final value. For information on other programming structures in Maple, refer to the Maple Introductory Programming Guide. To start the loop: • At the prompt, enter the following and press ENTER. "") ,- Note: After you press ENTER, Maple returns the message: “Warning, premature end of input.” It is simply reminding you that the " statement is not complete. To continue entering your input without receiving this warning, use SHIFT+ENTER to go to the next line. The next commands comprise the body of the " loop. These commands find the skier’s position at the end of each time step. To construct the 3-D normalized negative of the gradient vectors: • At the prompt, enter the following and press ENTER. (!#&'= !A:#/>3 3 %? <' (!#$ To find the next point in the skier’s path: • At the prompt, enter the following and press ENTER. (!*)#&' /><!)#<!,# ?<' (!#* . (!#$ To complete the loop: • At the prompt, enter the following and press ENTER. Remember to end the line with a colon to suppress the output. & This command ends the " loop. After you press ENTER, the five commands in the loop body are repeated 24 times. At the end of each iteration, the value of is increased by 1. That is, for the first iteration, the value of is its initial value 1, for the second 2, and so on. For the last iteration the value of is 24. Maple exits at the end of the 24th iteration once is set to 25 (since 25 is outside of the bounds of the loop).