Chapter 1. Getting to know your MATLAB
You could start MATLAB by
clicking the MATLAB icon on windows, and once started, it will pop up and
display something like this:
And now you are now in MATLAB.
Command for MATLAB:
>> exit %to exit….. the symbol “%”
without quotes is used to put comments into your
%algorithm so I’ll use this symbol to put
what the syntax is all about
>>help syntax %displays the syntax function
and its uses.. syntax is variable
%example:
>>help plot; or help sine
Now try this exercise:
>>z %now if you will type the
letter z, it will look like this
MATLAB uses conventional
decimal notation and the one we called PEMDAS rule in mathematics (Parenthesis Exponent Multiplication Division Addition Subtraction),
so if you will type;
>>z=3+7*8; %it is just like z= 3+ (7*8)
>>z
z =
59
>>pi %the constant pi = 3.1416
>>sqrt %the square root operation
>>6^2 %the symbol ^ means raised to
the nth so 6^2 means 6 squared,
ans =
36
>>sin(pi/2) %sine function of pi divided by 2, make
sure you put a parenthesis after the function
ans =
1
MATRIX
Matrix operation can also be
done in MATLAB. Columns are separated by space, and the rows are separated by
semicolon:
>>A = [1 2 3; 4 5 6; 7 8
9]
A =
1 2 3
4 5 6
7 8 9
I want you to explore every
possible outcome by using some matrix operations, and functions:
+ %addtion Inv %inverse of matrix
- %subtraction det %determinant of a matrix
* %matrix multiplication size %size of the matrix
^ %power rank %rank of matrix
‘ %transpose rand %random matrix number
\ %left division
/ %right division
>>F=rand(3,3)
F =
0.8147
0.9134 0.2785
0.9058
0.6324 0.5469
0.1270
0.0975 0.9575
0 comments