15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 4.2 Control Structures <strong>in</strong> <strong>Matlab</strong> 327<br />

4.2 Answers<br />

1. This for loop will pr<strong>in</strong>t <strong>the</strong> cubes <strong>of</strong> <strong>the</strong> first 10 positive <strong>in</strong>tegers.<br />

for k=1:10<br />

fpr<strong>in</strong>tf(’The cube <strong>of</strong> %d is %d.\n’,k,k^3)<br />

end<br />

This while loop will pr<strong>in</strong>t <strong>the</strong> cubes <strong>of</strong> <strong>the</strong> first 10 positive <strong>in</strong>tegers.<br />

k=1;<br />

while k

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!