Page 15 - Numerical Analysis Using MATLAB and Excel
P. 15
Chapter 1 Introduction to MATLAB
practice to save the script in a file name that is descriptive of our script content. For instance, if
the script performs some matrix operations, we ought to name and save that file as
matrices01.m or any other similar name. We should also use a separate disk to backup our files.
2. Once the script is written and saved as an m−file, we may exit the Editor/Debugger window by
clicking on Exit Editor/Debugger of the File menu, and MATLAB returns to the command
window.
3. To execute a program, we type the file name without the .m extension at the EDU>> prompt;
then, we press <enter> and observe the execution and the values obtained from it. If we have
saved our file in drive a or any other drive, we must make sure that it is added it to the desired
directory in MATLAB’s search path. The MATLAB User’s Guide provides more information
on this topic.
Henceforth, it will be understood that each input command is typed after the EDU>> prompt
and followed by the <enter> key.
The command help matlab iofun will display input/output information. To get help with other
MATLAB topics, we can type help followed by any topic from the displayed menu. For example, to
get information on graphics, we type help matlab graphics. We can also get help from the Help pull−
down menu. The MATLAB User’s Guide contains numerous help topics.
To appreciate MATLAB’s capabilities, we type demo and we see the MATLAB Demos menu. We
can do this periodically to become familiar with them. Whenever we want to return to the com-
mand window, we click on the Close button.
When we are done and want to leave MATLAB, we type quit or exit. But if we want to clear all
previous values, variables, and equations without exiting, we should use the clear command. This
command erases everything; it is like exiting MATLAB and starting it again. The clc command
clears the screen but MATLAB still remembers all values, variables and equations which we have
already used. In other words, if we want MATLAB to retain all previously entered commands, but
leave only the EDU>> prompt on the upper left of the screen, we can use the clc command.
All text after the % (percent) symbol is interpreted by MATLAB as a comment line and thus it is
ignored during the execution of a program. A comment can be typed on the same line as the func-
tion or command or as a separate line. For instance, the statements
conv(p,q) % performs multiplication of polynomials p and q
% The next statement performs partial fraction expansion of p(x) / q(x)
are both correct.
One of the most powerful features of MATLAB is the ability to do computations involving com-
i
j
plex numbers. We can use either , or to denote the imaginary part of a complex number, such as
34i or 34j . For example, the statement
–
–
z=3−4j
1−2 Numerical Analysis Using MATLAB® and Excel®, Third Edition
Copyright © Orchard Publications