LAB 1 General MATLAB Information

General:
To enter a matrix:
> type the entries between square brackets, [.....]
> enter it by rows with elements separated by a space or comma
> rows are terminated by a semicolon

command A= [1 2 3;4 5 6;7 8 9] displays

Suppressing Displays: When you place a semicolon at the end of a command, the
command will be executed but the result will not be displayed on the screen. This is
very useful when you are creating big matrices or to not reveal intermediate steps of
a calculation
. Try typing the command

w = linspace(1,20,100); Note the semicolon

to create a row vector with equally spaced entries. The contents of w will not be
displayed. To see the contents just type w.

To enter a string: type the contents of the string between single quotes ' ... '

command st = 'Hi there.' displays st =
Hi there.

Strings are not commands.
Strings supply information.
Strings are used for messages and formulas .


What you see on the screen:
MATLAB has various display formats. That is, ways to
show things on the screen. All numerical values stored by MATLAB have about 16
decimal places . However, we do not always want to see all the decimals places. That is
why MATLAB has display formats.

The default format is format short.
Format short shows 4 places behind the decimal point for reasonable sized numbers.
Examples:
pi is shown as 3.1416 in format short
2/3 is shown as 0.6667 in format short
1/8 is shown as 0.1250 in format short
(Format short rounds to obtain the last digit which is displayed. Beware, there may be
many more decimal places than those shown.)

Examples of other display formats: (e formats or floating point formats display a
number and an exponent which is a power of ten ; 1.2345e+002 means 1.2345*102 )

FORMAT SHORT Scaled fixed point format with 5 digits.
FORMAT LONG Scaled fixed point format with 15 digits.
FORMAT SHORT E Floating point format with 5 digits.
FORMAT LONG E Floating point format with 15 digits.
FORMAT SHORT G Best of fixed or floating point format with 5 digits.
FORMAT LONG G Best of fixed or floating point format with 15 digits.
FORMAT RAT Approximation by ratio of small integers.

format short e shows pi as 3.1416e+000
format long shows pi as 3.14159265358979
format long e shows pi as 3.141592653589793e+000
format rat   shows pi as 355/113

Note: 355/113 is only an approximation to pi; computing 355/113 in format long gives
3.14159292035398

Use command help format for the description of other display formats.

Special case: A value which is exactly zero will be displayed as a single zero. If
you see 0.0000, the value is not exactly zero. Change to a long format and re-display it.

Illustrations of ALGEBRA Expressions and their MATLAB form.

Standard Algebra Form MATLAB Representation
3x2 - 5x + 1 3*x^2-5*x+1
multiplication must be indicated using * and
exponents require an ^
(2*x-3)/(4-7*x)
the numerator and denominator must be
enclosed in parentheses if they are more
than 1 term
sqrt(x^2+1) or (x^2+1)^.5 or
(x^2+1)^(1/2)
using sqrt is preferred; fractional exponents
must be enclosed in parentheses
exp(-x)
ln(x) log(x)
the natural log function is denoted log; log
base 10 is denoted log10
cos2(x - π) cos(x-pi)^2
constant π is denoted pi; all arguments of
trig. functions are considered radians
sin(x) e-2.3x sin(x)*exp(-2.3*x)
note that the exponent is in parentheses
and that we must use * to indicate
multiplication
|tan(x)| abs(tan(x))
the absolute value is denoted by abs;
parentheses must be used

Operators, Elementary Functions, & General Purpose Commands

Arithmetic operators.
plus
minus
times
power
divide
+
-
*
^
\
Relational operators.
Equal
Not equal
Less than
Greater than
Less than or equal
Greater than or equal
==
~=
<
>
<=
>=
Logical operators.
and
or
not
&
|
~

 

Trigonometric & Hyperbolic
sin  - Sine.
sinh - Hyperbolic sine.
asin - Inverse sine.
asinh  - Inverse hyperbolic sine.
cos  - Cosine.
cosh - Hyperbolic cosine.
acos - Inverse cosine.
acosh - Inverse hyperbolic cosine.
tan - Tangent.
tanh - Hyperbolic tangent.
atan - Inverse tangent.
atan2
 
- Four quadrant
inverse tangent.
atanh - Inverse hyperbolic tangent.
sec  - Secant.
sech - Hyperbolic secant.
asec - Inverse secant.
asech - Inverse hyperbolic secant.
csc - Cosecant.
csch - Hyperbolic cosecant.
acsc - Inverse cosecant.
acsch - Inverse hyperbolic cosecant.
cot - Cotangent.
coth - Hyperbolic cotangent.
acot - Inverse cotangent.
acoth - Inverse hyperbolic cotangent.
Exponential
exp - Exponential.
log - Natural logarithm.
log10 - Common (base 10) logarithm.
log2
 
- Base 2 logarithm and
dissect floating point number.
pow2
 
 - Base 2 power and
scale
floating point number.
sqrt - Square root .
nextpow2 - Next higher power of 2. Complex
Complex
abs - Absolute value.
angle - Phase angle.
complex
 
- Construct complex data
from real and imaginary parts.
conj - Complex conjugate.
imag - Complex imaginary part.
real - Complex real part.
Calculus Operators
diff
 
- Difference and approximate
derivative when working on a vector.
diff


 

- Differentiate when working on a
string or symbolic expression; will do
higher derivatives & partial
derivatives
int
 
-Integrate; indefinite or definite
depending upon the arguments.
General Purpose Commands
home

 

-Moves the cursor to the upper left corner of the Command Window
and clears the visible portion of the window. You can use the
scroll bar to see what was on the screen previously.
clc - Clear command window; scrollbar not available.
demo - Run demonstrations.
who - List current variables.
whos - List current variables, long form.
clear - Clear variables and functions from memory.
load - Load workspace variables from disk.
save - Save workspace variables to disk.
saveas - Save Figure or model to desired output format.
quit - Quit MATLAB session.
exit - Exit from MATLAB.
what - List MATLAB-specific files in directory.
type - List M-file.
which - Locate functions and files.
path - Get/set search path.
addpath  - Add directory to search path.
rmpath - Remove directory from search path.
diary - Save text of MATLAB session.
Prev Next