Saturday, October 10, 2009

MATLAB Basics

MATLAB is started by clicking the mouse on the appropriate icon and is ended by typing exit or by using the menu option. After each MATLAB command, the "return" or "enter" key must be depressed.
A. Definition of Variables
Variables are assigned numerical values by typing the expression directly, for example, typing
a = 1+2
yields: a = 3
The answer will not be displayed when a semicolon is put at the end of an expression, for example type a = 1+2;.

MATLAB utilizes the following arithmetic operators:
+
addition
-
subtraction
*
multiplication
/
division
^
power operator
'
transpose
A variable can be assigned using a formula that utilizes these operators and either numbers or previously defined variables. For example, since a was defined previously, the following expression is valid
b = 2*a;
To determine the value of a previously defined quantity, type the quantity by itself:
b
yields: b = 6
If your expression does not fit on one line, use an ellipsis (three or more periods at the end of the line) and continue on the next line.
c = 1+2+3+...
5+6+7;

There are several predefined variables which can be used at any time, in the same manner as user-defined variables:
i
sqrt(-1)
j
sqrt(-1)
pi
3.1416...
For example,
y= 2*(1+4*j)
yields: y = 2.0000 + 8.0000i
There are also a number of predefined functions that can be used when defining a variable. Some common functions that are used in this text are:
abs
magnitude of a number (absolute value for real numbers)
angle
angle of a complex number, in radians
cos
cosine function, assumes argument is in radians
sin
sine function, assumes argument is in radians
exp
exponential function

For example, with y defined as above,
c = abs(y)
yields: c = 8.2462
c = angle(y)
yields: c = 1.3258
With a=3 as defined previously,
c = cos(a)
yields: c = -0.9900
c = exp(a)
yields: c = 20.0855
Note that exp can be used on complex numbers. For example, with y = 2+8i as defined above,
c = exp(y)
yields: c = -1.0751 + 7.3104i
which can be verified by using Euler's formula:
c = exp(2)cos(8) + je(exp)2sin(8)

No comments:

Post a Comment