Page 826 - Mechatronics with Experiments
P. 826
812 MECHATRONICS
>>
ans =
a
ans =
97
X =
1 2
3 4
S =
1 2
3 4
The basic arithmetic operators, +,-,∗,/ are defined for scalars as well as vectors and matrices.
In C++ terminology, the +, -, ∗, / operators have been overloaded to handle scalar, vector,
®
and matrix data objects. In MATLAB , we can add two matrices like scalars,
>> A = [ 1 2 ; 3 4 ] ;
>> B = [ 1 2 ; 3 4 ] ;
>> C = A+B ;
Element-by-element algebraic operations are also defined using the following operators:
.+ .− .∗ ./
The following is a standard matrix multiplication operator,
>> C = A ∗ B ;
Whereas, the following multiplies the A and B matrices element by element and assigns it
to the C matrix
>> C = A.∗ B ; % C(i,j) = A(i,j) ∗ B(i,j)
®
MATLAB automatically defines the following variables,
>> pi
>> eps
>> inf
>> NaN
>> i
>> j
where “pi” is , “eps” is a very small number which is 2 −52 ≈ 2.2204 E −16 , and “inf”
represents the infinity. “NaN” is used to represent a condition that data is not a number. The
®
maximum and minimum numbers that MATLAB can represent as integers and floating
points can be determined on a given computer as follows. Any mathematical operation that
results in a number beyond this range will result in overflow (larger than maximum repre-
sentable number) or underflow (smaller than the smallest representable number) errors.
>> intmax
ans =
2147483647
>> intmin