Lecture 1: Introduction: Essential MATLAB
Lecture 1: Introduction: Essential MATLAB
Essential MATLAB
for Engineers and Scientists
By
Hahn & Valentine
-------------------------------------------------
Lectures by Daniel T. Valentine
%
% Tool to compute the volume of a cone.
% A simple sample for a first lecture.
% B.H.& Daniel........... January 2007
%
rr = 4; % radius of the cone
h = 12; % height of the cone
v = (pi.*r.^2.*h)./3 % Volume of the cone
Execute an M-file as a Command
Now execute (or run) the program by pushing
F5, or by typing on the command line
>> cone <Enter>
– or by clicking the run button. (Note that the run button looks
like a page with a down arrow to its left. It can be found below help on
the toolbar of the edit window.)
If you entered the code as written on the
previous slide you will get an error!
What went wrong?
Repair your program (Change rr = 4 to r = 4.), save it,
and run it again.
Now change the height to 24, save and run your
program again.
Summary
MATLAB can be used like a hand calculator to
do arithmetic.
You can define (or assign) variables with
numbers and expressions to do calculations as
illustrated by the volume-of-cone example.
The advantage of saving programs as M-files is
that you open it, make changes and/or execute it
again without having to type it all over again.
This concludes our overview of MATLAB and a
taste of things to come!