MATLAB Technical Computing Environment

Download Report

Transcript MATLAB Technical Computing Environment

MATLAB
Trigonometry, Complex
Numbers and Array Operations
Basic Trigonometry
Basic Trigonometric Expressions in
MATLAB







sin(alpha) Sine of alpha
cos(alpha) Cosine of alpha
tan(alpha) Tangent of alpha
asin(z) Arcsine or inverse sine of z, where z must be between .1
and 1. Returns an angle between .π/2 and π/2 (quadrants I and IV).
acos(z) Arccosine or inverse cosine of z, where z must be
between .1 and 1. Returns an angle between 0 and π (quadrants I
and II).
atan(z) Arctangent or inverse tangent of z. Returns an angle
between .π/2 and π/2 (quadrants I and IV).
atan2(y,x) Four quadrant arctangent or inverse tangent, where x
and y are the coordinates in the plane shown in the .gure above.
Returns an angle between -π and π (all quadrants), depending on
the signs of x and y.
Hyperbolic Functions


The hyperbolic functions are functions of
the natural exponential function ex, where e is
the base of the natural logarithms, which is
approximately e = 2.71828182845904. The
inverse hyperbolic functions are functions of
the natural logarithm function, ln x.
The curve y = cosh x is called a catenary
(from the Latin word meaning “chain”). A
chain or rope, suspended from its ends,
forms a curve that is part of a catenary.
Basic Hyperbolic Expressions in
MATLAB
Complex Numbers



Imaginary number: The most fundamental
new concept in the study of complex
numbers is the “imaginary number” j. This
imaginary number is defined to be the square
root of -1:
j = √(-1)
j2 = -1
Complex Numbers - Rectangular
Representatiton
Complex Numbers - Rectangular
Representatiton
Rectangular Representation: A complex
number z consists of the “real part” x and the
“imaginary part” y and is expressed as
 z = x + jy
where
 x = Re[z]; y = Im[z]

Complex Numbers - Rectangular
Representatiton
A general complex number can be formed in three
ways:
>> z = 1 + j*2
z=
1.0000+ 2.0000i
>> z = 1 + 2j
z=
1.0000+ 2.0000i
>> z = complex(1,2)
z=
1.0000 + 2.0000i

Complex Numbers - Rectangular
Representatiton
>> z = 3 + 4j
z=
3.0000+ 4.0000i
>> x = real(z)
x=
3
>> y = imag(z)
y=
4
Polar Representation
Defining the radius r and the angle θ of the
complex number z can be represented in
polar form and written as
 z = r cos θ + jr sin θ
or, in shortened notation
 z = r θ

Polar Representation
>> z = 3 + 4j;
>> r = abs(z)
r=
5
>> theta = angle(z)
theta =
0.9273
theta = (180/pi)*angle(z)
theta =
53.1301
Polar Representation
Arrays and Array Operations





Scalars: Variables that represent single numbers, as considered to
this point. Note that complex numbers are scalars, even though they
have two components, the real part and the imaginary part.
Arrays: Variables that represent more than one number. Each
number is called an element of the array. Rather than than
performing the same operation on one number at a time, array
operations allow operating on multiple numbers at once.
Row and Column Arrays: A row of numbers (called a row vector)
or a column of numbers (called a column vector).
Two-Dimensional Arrays: A two-dimensional table of numbers,
called a matrix.
Array Indexing or Addressing: Indicates the location of an
element in the array.
Vector Arrays
Consider computing y = sin(x) for 0 ≤ x ≤ π. It is impossible to compute y
values for all values of x, since there are an infinite number of values, so
we will choose a finite number of x values.
Consider computing
y = sin(x), where x = 0, 0.1π, 0.2π, . . . , π
You can form a list, or array of the values of x, and then using a calculator
you can compute the corresponding values of y, forming a second array y.
x and y are ordered lists of numbers, i.e., the first value or element of y is
associated with the first value or element of x. Elements can be denoted by
subscripts, e.g. x1 is the first element in x, y5 is the fifth element in y. The
subscript is the index, address, or location of the element in the array.
Vector Creation
By an explicit list,
>> x=[0 .1*pi .2*pi .3*pi .4*pi .5*pi .6*pi .7*pi .8*pi .9*pi pi]
By a function,
>>y=sin(x)
Vector Addressing
A vector element is addressed in Matlab with an integer index (also called a
subscript) enclosed in parentheses. For example, to access the third element of x
and the fifth element of y:
>> x(3)
ans =
0.6283
>> y(5)
ans =
0.9511
Colon Notation
Addresses a block of elements The format for colon
notation is:
(start:increment:end)
where start is the starting index, increment is the amount
to add to each successive index, and end is the ending
index, where start, increment, and end must be integers.
The increment can be negative, but negative indices are
not allowed to be generated. If the increment is to be 1, a
shortened form of the notation may be used:
(start:end)
Colon Notation Examples
1:5 means “start with 1 and count up to 5.”
>> x(1:5)
ans =
0 0.3142 0.6283 0.9425 1.2566
7:end means “start with 7 and count up to the end of the vector.”
>> x(7:end)
ans =
1.8850 2.1991 2.5133 2.8274 3.1416
3:-1:1 means “start with 3 and count down to 1.”
>> y(3:-1:1)
ans =
0.5878 0.3090 0
2:2:7 means “start with 2, count up by 2, and stop at 7.”
>> x(2:2:7)
ans =
0.3142 0.9425 1.5708