Professional Documents
Culture Documents
>> help command lists all your previously worked files. But if you need a real help, for example
you want to find the meaning of a command and/or you need a command like zeros then you
go the upper right box and type what you want.
For example type zeros and look what you can find.
>> A = zeros(1,3)
A=
0 0 0
>> B = ones(4,7)
B=
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
Dimensions can be as you need. These types of zeros or ones matrices are useful to form the
dimensions of a desired matrix first then fill it with other calculations.
The colon operator “:” works totally different from brackets as we saw previously.
>> a = 1:3:34
a=
1 4 7 10 13 16 19 22 25 28 31 34
This means if you want to create a matrix which starts from 1 and end in 34 and numbers step
by 3. Something like 1, 1+3=4, 4+3=7, … etc.
You can change increment (number steps) as you wish like increasing as 1:3:34, decreasing as
75:-1:68 and/or decimals as 73:-0.5:15.
linspace(x1, x2, n) and logspace(x1, x2, n) both generate equally spaced vectors. For example
A=
Columns 1 through 12
4.0000 6.3278 8.6555 10.9833 13.3110 15.6388 17.9666 20.2943 22.6221 24.9498
27.2776 29.6054
Columns 13 through 24
Columns 25 through 36 …
Apart from this, logspace uses decade increments as 10x1 and 10x2. For example
B=
1.0e+10 *
Columns 1 through 6
0.000000000000000 0.000000000000000 0.000000000000000 0.000000000000002
0.000000000000009 0.000000000000050
Columns 7 through 12
Columns 13 through 18
Columns 19 through 24
You can easily understand the importance of format short and long functions along with
linspace and logspace functions.
>> V = 'Yeser';
>> Z = 'Aslanoglu';
2. Mathematical Operations
^ Exponentiation
- Negation
* Multiplication
/ Division
\ Left Division (applies to matrix algebra)
+ Addition
- Subtraction
As it is obvious MATLAB can work as a calculator. You can play with tis option with your
previous notes. Hands on training! Dig deeper on matrix algebra rules!
2. Built-in Functions
Built-in mentions which the functions MATLAB already has in its info. You can use these built-
in functions to make your life easier. At beginning of this doc, you saw >>help function. Only
typing help shows your previous works on MATLAB. But if you want to learn about a function
more, you have to type for example as >>help zeros.
>> help zeros
zeros Zeros array.
zeros(N) is an N-by-N matrix of zeros.
zeros(..., 'like', Y) is an array of zeros with the same data type, sparsity,
and complexity (real or complex) as the numeric variable Y.
Example:
x = zeros(2,3,'int8');
MATLAB can give you all about the function which you asked to learn. Give a try the functions
you are wondering with typing help.
Example_1. Create two matrices and try to find min, max, mean and square root of each matrix.
Then try basic math algebra with them (addition, subtraction, multiplication, division, etc.)
Assignment_2. (1). You have a bungee-jumping company and you need to check the safety
plans are working or not. First of all, you need to find a bungee jumper’s free-falling velocity.
Please calculate the velocity with below equation and the givens. USE MATLAB!
mass is m = 72 kg,
acceleration due to gravity is g = 9,81 m/s2,
drag coefficient is cd = 0.23 kg/m
time is t = 20s by 2s steps*
* you have to create a column vector for t(you learned to create a vector which is default a row,
you learned also transpose and make it a column vector, tanh is a built-in function also)
𝑔𝑚 𝑔𝑐𝑑
𝑣= √ 𝑡𝑎𝑛ℎ (√ 𝑡)
𝑐𝑑 𝑚