MATLAB Mathematic operation

Mathematical operation in matlab programming is very simple, it similar if you use the regular calculator. Here is mathematic table operator that use in Matlab programming.


Addition
+
A + B
Subtraction
-
A - B
Multiplication
*
A * B
Division
/ or \
A / B or A \ B
exponent
^
A ^ B

Knowledge of the matrix is essential in Matlab programming because all patterns of mathematical operations will be restored in the pattern matrix math operations. For example is when we declare variable 'a' and fill it with the value 5 in the following way :
>> a=5
a =
    5

otomatically, matlab will recognize variable 'a' above as a matrix which has 1x1 matric dimension. It can be proof as follow :
>> a(1,1)
ans =
      5

The difference will be more felt when we do an operation that entangle multiplication and division. For example we can use the case of area calculation whith length and width data is provided. As a first case, it is provided length data (5) and width (6). the solution for this case as follow :
>> length = 5;
>> width = 6;
>> area = length*width;
area = 30

whereas  for second case, it is provided four datas in each variable, length (4,5,3,1) and width (5,3,2,2), if we use same method, it will result error message :
>> length = [4 5 3 1]
length =
        4 5 3 1
>> width = [5 3 2 2]
width =
        5 3 2 2
>> area = length*width
??? Error using ==> *
Inner matrix dimensions must agree.

An error message above is shown because it is not meet the matrix multiplication requirement. You should remember that first column of the first matrix should be same with total row of second matrix.

0 comments:

Post a Comment