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
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
372 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />
4.4 Exercises<br />
1. Clear <strong>the</strong> workspace by enter<strong>in</strong>g <strong>the</strong> command clear all at <strong>the</strong> <strong>Matlab</strong><br />
prompt <strong>in</strong> <strong>the</strong> command w<strong>in</strong>dow. Type whos to exam<strong>in</strong>e <strong>the</strong> base workspace<br />
and <strong>in</strong>sure that it is empty. Open <strong>the</strong> editor, enter <strong>the</strong> follow<strong>in</strong>g l<strong>in</strong>es, <strong>the</strong>n save<br />
<strong>the</strong> file as VariableScope.m. Execute <strong>the</strong> cell <strong>in</strong> cell-enabled mode.<br />
%% Exercise #1<br />
clc<br />
P=1000;<br />
r=0.06;<br />
t=10;<br />
I=P*r*t;<br />
fpr<strong>in</strong>tf(’Simple <strong>in</strong>terest ga<strong>in</strong>ed is %.2f.\n’,I)<br />
Exam<strong>in</strong>e <strong>the</strong> base workspace by enter<strong>in</strong>g whos at <strong>the</strong> command w<strong>in</strong>dow<br />
prompt. Expla<strong>in</strong> <strong>the</strong> output.<br />
2. Clear <strong>the</strong> workspace by enter<strong>in</strong>g <strong>the</strong> command clear all at <strong>the</strong> <strong>Matlab</strong> prompt<br />
<strong>in</strong> <strong>the</strong> command w<strong>in</strong>dow. Type whos to exam<strong>in</strong>e <strong>the</strong> base workspace and <strong>in</strong>sure<br />
that it is empty. At <strong>the</strong> command prompt, enter and execute <strong>the</strong> follow<strong>in</strong>g command.<br />
>> P=1000; r=0.06; t=10;<br />
Exam<strong>in</strong>e <strong>the</strong> workspace:<br />
>> whos<br />
Name Size Bytes Class<br />
P 1x1 8 double array<br />
r 1x1 8 double array<br />
t 1x1 8 double array<br />
Add <strong>the</strong> follow<strong>in</strong>g cell to <strong>the</strong> file VariableScope.m.<br />
11 Copyrighted material. See: http://msenux.redwoods.edu/IntAlgText/