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.

290 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />

15.<br />

17.<br />

>> P((P20))<br />

ans =<br />

1<br />

1<br />

1<br />

1<br />

1<br />

1<br />

2<br />

3<br />

4<br />

1<br />

3<br />

1<br />

4<br />

35<br />

1<br />

35<br />

70<br />

>> A(mod(A,2)==0)<br />

ans =<br />

16<br />

4<br />

2<br />

14<br />

10<br />

6<br />

8<br />

12<br />

21.<br />

>> A(mod(A,3)==0)<br />

ans =<br />

9<br />

3<br />

6<br />

15<br />

12<br />

>> u=1:100;<br />

>> k=isprime(u);<br />

>> u(k)<br />

ans =<br />

Columns 1 through 4<br />

2 3 5 7<br />

Columns 5 through 8<br />

11 13 17 19<br />

Columns 9 through 12<br />

23 29 31 37<br />

Columns 13 through 16<br />

41 43 47 53<br />

Columns 17 through 20<br />

59 61 67 71<br />

Columns 21 through 24<br />

73 79 83 89<br />

Column 25<br />

97<br />

23. Def<strong>in</strong>e <strong>the</strong> anonymous function.<br />

f=@(x) 2+sqrt(x+5);<br />

19.<br />

Evaluate <strong>the</strong> function on [−10, 10]<br />

and plot <strong>the</strong> result.

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

Saved successfully!

Ooh no, something went wrong!