Page 49 - Numerical Analysis Using MATLAB and Excel
P. 49
Chapter 1 Introduction to MATLAB
•The real(z) and imag(z) functions display the real and imaginary parts of the complex quantity
z = x + iy, and the abs(z), and the angle(z) functions compute the absolute value (magnitude)
and phase angle of the complex quantity z = x + iy = r θ– . The polar(theta,r) function pro-
duces a plot in polar coordinates, where r is the magnitude, and theta is the angle in radians.
• MATLAB recognizes two types of files: script files and function files. Both types are referred to
as m−files. A script file consists of two or more built−in functions. Generally, a script file is one
which was generated and saved as an m−file with an editor such as the MATLAB’s Editor/
Debugger. A function file is a user−defined function using MATLAB. We use function files for
repetitive tasks. The first line of a function file must contain the word function, followed by the
output argument, the equal sign ( = ), and the input argument enclosed in parentheses. The
function name and file name must be the same, but the file name must have the extension .m.
•The MATLAB fmin(f,x1,x2) function minimizes a function of one variable. It attempts to
x
return a value of where f x() is minimum in the interval x << x 2 . The string f contains
x
1
the name of the function to be minimized.
•The MATLAB fplot(fcn,lims) command plots the function specified by the string fcn between
x
the −axis limits specified by lims = [xmin xmax]. Using lims = [xmin xmax ymin ymax] also
y
controls the −axis limits. The string fcn must be the name of an m−file function or a string
with variable .
x
•The MATLAB fprintf(format,array) command used above displays and prints both text and
arrays. It uses specifiers to indicate where and in which format the values would be displayed
and printed. Thus, if %f is used, the values will be displayed and printed in fixed decimal for-
mat, and if %e is used, the values will be displayed and printed in scientific notation format.
With these commands only the real part of each parameter is processed.
• MATLAB displays the results on the screen in integer format without decimals if the result is
an integer number, or in short floating point format with four decimals if it a fractional number.
The format displayed has nothing to do with the accuracy in the computations. MATLAB per-
forms all computations with accuracy up to 16 decimal places.
1−36 Numerical Analysis Using MATLAB® and Excel®, Third Edition
Copyright © Orchard Publications