SlideShare a Scribd company logo
1 of 24
BASICS OF OCTAVE/MATLAB
PROGRAMMING LANGUAGE
AULIA KHALQILLAH, S.SI
“Be thankful”
sharing.auliakhalqillah.com
INTRODUCTION
The OCTAVE and MATLAB is the one of the most programming language. It is simple to
learn about the language. The main of these programming language is to visualization
the data become a graph.
There are no big different between OCTAVE and MATLAB. However, the MATLAB has
more complete function compared to OCTAVE.
Also, OCTAVE is OPEN SOURCE software
https://www.gnu.org/software/octave/ https://www.mathworks.com/videos/programming-with-matlab-
86354.html
sharing.auliakhalqillah.com
INTRODUCTION
In OCTAVE and MATLAB have 4 panels, such as:
 Command Window
 Workspace = The whole variables will be store in the workspace
 Current Folder = The active directory
 Text Editor = To write full script (like atom, notepad++, Xcode, etc)
In this note, we will use the command window to write the basic code of
OCTAVE/MATLAB programming language. After the all of the basic
code has been understood, we will explain how to write the full code
using the OCTAVE/MATLAB programming language.
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VARIABLE
You can type the command bellow in your Command Window:
>> 5
ans = 5
When you type the command above, the output is ans = 5. The ans is name of
variable what you typed before. If you type as the command bellow:
>> x = 5
x = 5
The x is the new name of variable what you typed.
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VARIABLE
If you add the (;) in the end of variable
>> x = 5;
The output variable doesn’t appear in the Command Window and it will
be stored in the Workspace
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
OPERATION OF MATH
The simple operation of math in OCTAVE/MATLAB programming
language is as follows:
>> x = 5;
>> y = 10;
>> z = x + y
z = 15
Operation Symbol
add +
substraction -
multiplication *
division /
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
CONSTANTS
In the OCTAVE/MATLAB programming language has a predefined
constants, such as:
Symbol Syntax information
𝜋 pi pi = 3.1416...
Imaginary i atau j 0 + 1i
epsilon eps 2.2204e-16
Infinity inf unlimited
- NaN no value
comment % to write some note in the code
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
FUNCTION OF MATH
In the OCTAVE/MATLAB programming language has a predefined
function, such as:
Symbol Syntax
sin x sin(x)
cos x cos(x)
arcsin x asin(x)
arccos x acos(x)
ex exp(x)
log10 x log10(x)
log2 x log2(x)
𝑥 sqrt(x)
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
FUCNTION OF MATH
Example
>> x = pi/2;
>> sin(x)
ans = 1
>> cos(x)
ans = 6.1232e-17
>> asin(x)
ans = 1.5708 - 1.0232i
>> acos(x)
ans = 0.00000 + 1.02323i
Example
>> exp(x)
ans = 4.8105
>> log10(x)
ans = 0.19612
>> log2(x)
ans = 0.65150
>> sqrt(x)
ans = 1.2533
>> log10(sin(x))
ans = 0
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VECTOR
>> x = [1 2] % Term 1
x =
1 2
>> x = [1;2] % Term 2
x =
1
2
Term 1 have the output horizontally or as the row
Term 2 have the output vertically or as the column
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VECTOR
If you want to make the vector (e.g. 1, 2, 3, ...., etc), you can type the command
as follows:
>> x = [1 2 3 4 5 6 7 8 9 10] % Row vector
x =
1 2 3 4 5 6 7 8 9 10
>> x = [1;2;3;4;5] % Column vector
x =
1
2
3
4
5
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VECTOR
You can generate the vector using linspace
Term 1 => x = linspace(start, end)
>> x = linspace(1,2);
The vector will be start from 1 to 2 with the default of data length is 100. This
output will be as a row vector. To produce the column vector, you can type:
>> x = linspace(1,2)’;
The output will be stored in Workspace
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VECTOR
The another term of linspace is:
Term 2 => linspace(start, end, N)
>> x = linspace(1,2,10);
The vector will be start from 1 to 2 with length of data is 10.
The another one term to generate the vector:
Term 3 => x = start:end
>> x = 1:10
x =
1 2 3 4 5 6 7 8 9 10
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
VECTOR
Term 4=> x = start:step:end
>> x = 1:2:20
x =
1 3 5 7 9 11 13 15 17 19
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
FUNCTION AND OPERATION OF VECTOR
Symbol Syntax Information
ak a(k) The component k-th of vector a
an a(end) The last component of vector a
𝑎 =
𝑘=1
𝑛
𝑎 𝑘
1/2
norm(a) normalization of vector
ab a*b multiplication of vector
max{ak}k=1, .. n max(a) maximum value of vector a
max{ak}k=1, .. N min(a) minimum value of vector a
n(a) length(a) size of vector a
𝑘=1
𝑛
𝑎 𝑘
sum(a) The summation of vector a
𝑘=1
𝑛
𝑎 𝑘
prod(a) The multiplication of vector a
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
FUNCTION AND OPERATION OF VECTOR
Symbol Syntax Information
𝑘=1
𝑛
𝑎 𝑘 𝑏 𝑘
dot(a,b) dot product between vector a and b
(a1b1, ....., anbn) a.*b multiplication between components
Example:
>> x = [3 2 5];
>> y = [4 1 6];
>> length(x)
ans = 3
>> length(y)
ans = 3
Example:
>> norm(x)
ans = 6.1644
>> dot(x,y)
ans = 44
>> z = x.*y
z =
12 2 30
Example
>> max(x)
ans = 5
>> max(y)
ans = 6
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX
To produce the matrix, you can type:
>> x = [1 2 3;4 5 6;7 8 9]
x =
1 2 3
4 5 6
7 8 9
The output is the example of matrix with size 3 x 3. The sign of (;) as the new
row for the matrix.
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX
INDEX OF MATRIX
Columns
𝐴 =
𝑎1 𝑎2 𝑎3
𝑎4 𝑎5 𝑎6
𝑎7 𝑎9 𝑎10
Rows
In OCTAVE/MATLAB index of matrix can be written as A(i,j), where the i
as the row and j as the column
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX
EXAMPLE
>> A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
If you want to take the element
from the third row and the second
column of the matrix A, you can
type:
>> AA = A(3,2)
AA = 8
EXAMPLE
>> A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
If you want to take the
element from the first column,
you can type:
>> AA = A(:,1)
AA =
1
4
7
sharing.auliakhalqillah.com
PENGGUNAAN COMMAND WINDOW:
MATRIKS
EXAMPLE
>> A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
If you want to take the
element from first row and
second row, you can type:
>> AA = A(1:2,:)
AA =
1 2 3
4 5 6
EXAMPLE
>> A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
If you want to take the
element second column and
third column, you can type:
>> AA = A(:,2:3)
AA =
2 3
5 6
8 9
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX OPERATION
The operation of math in matrix as follows:
 ADDITION (+),
 SUBSTRACTION(-),
 MULTIPLICATION (*),
 MULTIPLICATION BETWEEN ELEMENT(.*),
 POWER (^),
 TRANSPOSE (‘),
 LEFT DIVISION (),
 RIGHT DIVISION (/).
EXAMPLE
>> A = [1 2 3;4 5 6;7 8 9];
>> B = [2 4 6;8 10 12; 1 2 3];
>> C = A+B % Add
C =
3 6 9
12 15 18
8 10 12
>> C = A-B % Substrac
C =
-1 -2 -3
-4 -5 -6
6 6 6
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX OPERATION
Example
>> C = A^2 % Power
C =
30 36 42
66 81 96
102 126 150
>> C = A’ % Transpose
C =
1 4 7
2 5 8
3 6 9
Example
>> C = A*B % Multiplication
C =
21 30 39
54 78 102
87 126 165
>> C = A.*B % Element Multiplication
C =
2 8 18
32 50 72
7 16 27
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX OPERATION
LEFT DIVISION () => C = AB = A-1B
RIGHT DIVISION (/) => C = A/B = AB-1
Example:
>> A = [1 2 3;4 5 6;7 8 9];
>> B = [2 4 6;8 10 12; 1 2 3];
>> C = AB % LEFT DIVISION
C =
-2.305556 -3.611111 -4.916667
-0.055556 -0.111111 -0.166667
2.194444 3.388889 4.583333
sharing.auliakhalqillah.com
USING COMMAND WINDOW:
MATRIX OPERATION
>> C = A/B % RIGHT DIVISION
C =
4.0000e-01 1.5266e-16 2.0000e-01
4.8190e-16 5.0000e-01 3.8806e-16
-4.0000e-01 1.0000e+00 -2.0000e-01
SPECIFICALLY IN THE CASE OF MATRIX RULES, APPLICABLE
REQUIREMENTS FOR ANALYSIS OF MATRICES. WHERE THE REQUIREMENT
OF MATRIX MULTIPLICATION IS : THE NUMBER OF COLUMNS IN MATRICES
A = NUMBER OF LINES IN B MATRICES
THANK YOU AND GOOD LUCK
Source: Matematika Numerik dengan Implementasi Matlab, Julan Hernadi, Penerbit Andi (2012)
sharing.auliakhalqillah.com

More Related Content

What's hot

Daiso11 chuong-2a (3)
Daiso11 chuong-2a (3)Daiso11 chuong-2a (3)
Daiso11 chuong-2a (3)truongducvu
 
30 de va da hsg toan 7
30 de va da hsg toan 730 de va da hsg toan 7
30 de va da hsg toan 7Tuân Ngô
 
Test 1 - Mutlak Değer
Test 1 - Mutlak DeğerTest 1 - Mutlak Değer
Test 1 - Mutlak Değersorucanavari
 
Soal polinomial
Soal polinomialSoal polinomial
Soal polinomialzah1302
 
Materi suku banyak
Materi suku banyakMateri suku banyak
Materi suku banyakdina_usiani
 
Himpunan (pertemuan 2)
Himpunan (pertemuan 2)Himpunan (pertemuan 2)
Himpunan (pertemuan 2)Rudi Wicaksana
 
20 sequences x
20 sequences x20 sequences x
20 sequences xmath266
 
Permainan matematika PAPAN GEOMETRI
Permainan matematika PAPAN GEOMETRIPermainan matematika PAPAN GEOMETRI
Permainan matematika PAPAN GEOMETRIDessy Rasihen
 
Vektor Matematika Peminatan
Vektor Matematika PeminatanVektor Matematika Peminatan
Vektor Matematika PeminatanMaisyah Wanda
 
ĐẠI SỐ TỔ HỢP
ĐẠI SỐ TỔ HỢPĐẠI SỐ TỔ HỢP
ĐẠI SỐ TỔ HỢPDANAMATH
 
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020Tới Nguyễn
 
Kumpulan Soal LOGARITMA by syifadhila
Kumpulan Soal LOGARITMA by syifadhilaKumpulan Soal LOGARITMA by syifadhila
Kumpulan Soal LOGARITMA by syifadhilaSyifa Dhila
 
Test 7 Bölme Bölünebilme
Test 7 Bölme BölünebilmeTest 7 Bölme Bölünebilme
Test 7 Bölme Bölünebilmesorucanavari
 
Rumus cepat-matematika-vektor
Rumus cepat-matematika-vektorRumus cepat-matematika-vektor
Rumus cepat-matematika-vektorIr Al
 
Matematika Bangun Ruang (Integral)
Matematika Bangun Ruang (Integral)Matematika Bangun Ruang (Integral)
Matematika Bangun Ruang (Integral)Meka Saima
 
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy Thích
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy ThíchBồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy Thích
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy ThíchBồi dưỡng Toán lớp 6
 
Remidi matematika Bab Integral
Remidi matematika Bab IntegralRemidi matematika Bab Integral
Remidi matematika Bab IntegralXII IPA - 1
 

What's hot (20)

Daiso11 chuong-2a (3)
Daiso11 chuong-2a (3)Daiso11 chuong-2a (3)
Daiso11 chuong-2a (3)
 
30 de va da hsg toan 7
30 de va da hsg toan 730 de va da hsg toan 7
30 de va da hsg toan 7
 
Test 1 - Mutlak Değer
Test 1 - Mutlak DeğerTest 1 - Mutlak Değer
Test 1 - Mutlak Değer
 
Soal polinomial
Soal polinomialSoal polinomial
Soal polinomial
 
Materi suku banyak
Materi suku banyakMateri suku banyak
Materi suku banyak
 
Teori himpunan
Teori himpunanTeori himpunan
Teori himpunan
 
Himpunan (pertemuan 2)
Himpunan (pertemuan 2)Himpunan (pertemuan 2)
Himpunan (pertemuan 2)
 
20 sequences x
20 sequences x20 sequences x
20 sequences x
 
Permainan matematika PAPAN GEOMETRI
Permainan matematika PAPAN GEOMETRIPermainan matematika PAPAN GEOMETRI
Permainan matematika PAPAN GEOMETRI
 
Vektor Matematika Peminatan
Vektor Matematika PeminatanVektor Matematika Peminatan
Vektor Matematika Peminatan
 
ĐẠI SỐ TỔ HỢP
ĐẠI SỐ TỔ HỢPĐẠI SỐ TỔ HỢP
ĐẠI SỐ TỔ HỢP
 
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020
PHƯƠNG PHÁP GIẢI BÀI TẬP VỀ ANKAN - Chuyên đề Ankan 2020
 
Kumpulan Soal LOGARITMA by syifadhila
Kumpulan Soal LOGARITMA by syifadhilaKumpulan Soal LOGARITMA by syifadhila
Kumpulan Soal LOGARITMA by syifadhila
 
Combinatoria en progresiones
Combinatoria en progresionesCombinatoria en progresiones
Combinatoria en progresiones
 
Test 7 Bölme Bölünebilme
Test 7 Bölme BölünebilmeTest 7 Bölme Bölünebilme
Test 7 Bölme Bölünebilme
 
Rumus cepat-matematika-vektor
Rumus cepat-matematika-vektorRumus cepat-matematika-vektor
Rumus cepat-matematika-vektor
 
Matematika Bangun Ruang (Integral)
Matematika Bangun Ruang (Integral)Matematika Bangun Ruang (Integral)
Matematika Bangun Ruang (Integral)
 
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy Thích
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy ThíchBồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy Thích
Bồi dưỡng nâng cao HSG Toán lớp 7 qua 16 chuyên đề - Thầy Thích
 
Hw5sols
Hw5solsHw5sols
Hw5sols
 
Remidi matematika Bab Integral
Remidi matematika Bab IntegralRemidi matematika Bab Integral
Remidi matematika Bab Integral
 

Similar to Basic of octave matlab programming language

Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxgilpinleeanna
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptxBeheraA
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
Raushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptxRaushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptxhmghj
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabvikrammutneja1
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantssdharmesh69
 

Similar to Basic of octave matlab programming language (20)

Chapter 01.ppt
Chapter 01.pptChapter 01.ppt
Chapter 01.ppt
 
Chapter 01.ppt
Chapter 01.pptChapter 01.ppt
Chapter 01.ppt
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Matlab
MatlabMatlab
Matlab
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Matlab1
Matlab1Matlab1
Matlab1
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
 
Raushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptxRaushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptx
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Basic of octave matlab programming language

  • 1. BASICS OF OCTAVE/MATLAB PROGRAMMING LANGUAGE AULIA KHALQILLAH, S.SI “Be thankful” sharing.auliakhalqillah.com
  • 2. INTRODUCTION The OCTAVE and MATLAB is the one of the most programming language. It is simple to learn about the language. The main of these programming language is to visualization the data become a graph. There are no big different between OCTAVE and MATLAB. However, the MATLAB has more complete function compared to OCTAVE. Also, OCTAVE is OPEN SOURCE software https://www.gnu.org/software/octave/ https://www.mathworks.com/videos/programming-with-matlab- 86354.html sharing.auliakhalqillah.com
  • 3. INTRODUCTION In OCTAVE and MATLAB have 4 panels, such as:  Command Window  Workspace = The whole variables will be store in the workspace  Current Folder = The active directory  Text Editor = To write full script (like atom, notepad++, Xcode, etc) In this note, we will use the command window to write the basic code of OCTAVE/MATLAB programming language. After the all of the basic code has been understood, we will explain how to write the full code using the OCTAVE/MATLAB programming language. sharing.auliakhalqillah.com
  • 4. USING COMMAND WINDOW: VARIABLE You can type the command bellow in your Command Window: >> 5 ans = 5 When you type the command above, the output is ans = 5. The ans is name of variable what you typed before. If you type as the command bellow: >> x = 5 x = 5 The x is the new name of variable what you typed. sharing.auliakhalqillah.com
  • 5. USING COMMAND WINDOW: VARIABLE If you add the (;) in the end of variable >> x = 5; The output variable doesn’t appear in the Command Window and it will be stored in the Workspace sharing.auliakhalqillah.com
  • 6. USING COMMAND WINDOW: OPERATION OF MATH The simple operation of math in OCTAVE/MATLAB programming language is as follows: >> x = 5; >> y = 10; >> z = x + y z = 15 Operation Symbol add + substraction - multiplication * division / sharing.auliakhalqillah.com
  • 7. USING COMMAND WINDOW: CONSTANTS In the OCTAVE/MATLAB programming language has a predefined constants, such as: Symbol Syntax information 𝜋 pi pi = 3.1416... Imaginary i atau j 0 + 1i epsilon eps 2.2204e-16 Infinity inf unlimited - NaN no value comment % to write some note in the code sharing.auliakhalqillah.com
  • 8. USING COMMAND WINDOW: FUNCTION OF MATH In the OCTAVE/MATLAB programming language has a predefined function, such as: Symbol Syntax sin x sin(x) cos x cos(x) arcsin x asin(x) arccos x acos(x) ex exp(x) log10 x log10(x) log2 x log2(x) 𝑥 sqrt(x) sharing.auliakhalqillah.com
  • 9. USING COMMAND WINDOW: FUCNTION OF MATH Example >> x = pi/2; >> sin(x) ans = 1 >> cos(x) ans = 6.1232e-17 >> asin(x) ans = 1.5708 - 1.0232i >> acos(x) ans = 0.00000 + 1.02323i Example >> exp(x) ans = 4.8105 >> log10(x) ans = 0.19612 >> log2(x) ans = 0.65150 >> sqrt(x) ans = 1.2533 >> log10(sin(x)) ans = 0 sharing.auliakhalqillah.com
  • 10. USING COMMAND WINDOW: VECTOR >> x = [1 2] % Term 1 x = 1 2 >> x = [1;2] % Term 2 x = 1 2 Term 1 have the output horizontally or as the row Term 2 have the output vertically or as the column sharing.auliakhalqillah.com
  • 11. USING COMMAND WINDOW: VECTOR If you want to make the vector (e.g. 1, 2, 3, ...., etc), you can type the command as follows: >> x = [1 2 3 4 5 6 7 8 9 10] % Row vector x = 1 2 3 4 5 6 7 8 9 10 >> x = [1;2;3;4;5] % Column vector x = 1 2 3 4 5 sharing.auliakhalqillah.com
  • 12. USING COMMAND WINDOW: VECTOR You can generate the vector using linspace Term 1 => x = linspace(start, end) >> x = linspace(1,2); The vector will be start from 1 to 2 with the default of data length is 100. This output will be as a row vector. To produce the column vector, you can type: >> x = linspace(1,2)’; The output will be stored in Workspace sharing.auliakhalqillah.com
  • 13. USING COMMAND WINDOW: VECTOR The another term of linspace is: Term 2 => linspace(start, end, N) >> x = linspace(1,2,10); The vector will be start from 1 to 2 with length of data is 10. The another one term to generate the vector: Term 3 => x = start:end >> x = 1:10 x = 1 2 3 4 5 6 7 8 9 10 sharing.auliakhalqillah.com
  • 14. USING COMMAND WINDOW: VECTOR Term 4=> x = start:step:end >> x = 1:2:20 x = 1 3 5 7 9 11 13 15 17 19 sharing.auliakhalqillah.com
  • 15. USING COMMAND WINDOW: FUNCTION AND OPERATION OF VECTOR Symbol Syntax Information ak a(k) The component k-th of vector a an a(end) The last component of vector a 𝑎 = 𝑘=1 𝑛 𝑎 𝑘 1/2 norm(a) normalization of vector ab a*b multiplication of vector max{ak}k=1, .. n max(a) maximum value of vector a max{ak}k=1, .. N min(a) minimum value of vector a n(a) length(a) size of vector a 𝑘=1 𝑛 𝑎 𝑘 sum(a) The summation of vector a 𝑘=1 𝑛 𝑎 𝑘 prod(a) The multiplication of vector a sharing.auliakhalqillah.com
  • 16. USING COMMAND WINDOW: FUNCTION AND OPERATION OF VECTOR Symbol Syntax Information 𝑘=1 𝑛 𝑎 𝑘 𝑏 𝑘 dot(a,b) dot product between vector a and b (a1b1, ....., anbn) a.*b multiplication between components Example: >> x = [3 2 5]; >> y = [4 1 6]; >> length(x) ans = 3 >> length(y) ans = 3 Example: >> norm(x) ans = 6.1644 >> dot(x,y) ans = 44 >> z = x.*y z = 12 2 30 Example >> max(x) ans = 5 >> max(y) ans = 6 sharing.auliakhalqillah.com
  • 17. USING COMMAND WINDOW: MATRIX To produce the matrix, you can type: >> x = [1 2 3;4 5 6;7 8 9] x = 1 2 3 4 5 6 7 8 9 The output is the example of matrix with size 3 x 3. The sign of (;) as the new row for the matrix. sharing.auliakhalqillah.com
  • 18. USING COMMAND WINDOW: MATRIX INDEX OF MATRIX Columns 𝐴 = 𝑎1 𝑎2 𝑎3 𝑎4 𝑎5 𝑎6 𝑎7 𝑎9 𝑎10 Rows In OCTAVE/MATLAB index of matrix can be written as A(i,j), where the i as the row and j as the column sharing.auliakhalqillah.com
  • 19. USING COMMAND WINDOW: MATRIX EXAMPLE >> A = [1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 If you want to take the element from the third row and the second column of the matrix A, you can type: >> AA = A(3,2) AA = 8 EXAMPLE >> A = [1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 If you want to take the element from the first column, you can type: >> AA = A(:,1) AA = 1 4 7 sharing.auliakhalqillah.com
  • 20. PENGGUNAAN COMMAND WINDOW: MATRIKS EXAMPLE >> A = [1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 If you want to take the element from first row and second row, you can type: >> AA = A(1:2,:) AA = 1 2 3 4 5 6 EXAMPLE >> A = [1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 If you want to take the element second column and third column, you can type: >> AA = A(:,2:3) AA = 2 3 5 6 8 9 sharing.auliakhalqillah.com
  • 21. USING COMMAND WINDOW: MATRIX OPERATION The operation of math in matrix as follows:  ADDITION (+),  SUBSTRACTION(-),  MULTIPLICATION (*),  MULTIPLICATION BETWEEN ELEMENT(.*),  POWER (^),  TRANSPOSE (‘),  LEFT DIVISION (),  RIGHT DIVISION (/). EXAMPLE >> A = [1 2 3;4 5 6;7 8 9]; >> B = [2 4 6;8 10 12; 1 2 3]; >> C = A+B % Add C = 3 6 9 12 15 18 8 10 12 >> C = A-B % Substrac C = -1 -2 -3 -4 -5 -6 6 6 6 sharing.auliakhalqillah.com
  • 22. USING COMMAND WINDOW: MATRIX OPERATION Example >> C = A^2 % Power C = 30 36 42 66 81 96 102 126 150 >> C = A’ % Transpose C = 1 4 7 2 5 8 3 6 9 Example >> C = A*B % Multiplication C = 21 30 39 54 78 102 87 126 165 >> C = A.*B % Element Multiplication C = 2 8 18 32 50 72 7 16 27 sharing.auliakhalqillah.com
  • 23. USING COMMAND WINDOW: MATRIX OPERATION LEFT DIVISION () => C = AB = A-1B RIGHT DIVISION (/) => C = A/B = AB-1 Example: >> A = [1 2 3;4 5 6;7 8 9]; >> B = [2 4 6;8 10 12; 1 2 3]; >> C = AB % LEFT DIVISION C = -2.305556 -3.611111 -4.916667 -0.055556 -0.111111 -0.166667 2.194444 3.388889 4.583333 sharing.auliakhalqillah.com
  • 24. USING COMMAND WINDOW: MATRIX OPERATION >> C = A/B % RIGHT DIVISION C = 4.0000e-01 1.5266e-16 2.0000e-01 4.8190e-16 5.0000e-01 3.8806e-16 -4.0000e-01 1.0000e+00 -2.0000e-01 SPECIFICALLY IN THE CASE OF MATRIX RULES, APPLICABLE REQUIREMENTS FOR ANALYSIS OF MATRICES. WHERE THE REQUIREMENT OF MATRIX MULTIPLICATION IS : THE NUMBER OF COLUMNS IN MATRICES A = NUMBER OF LINES IN B MATRICES THANK YOU AND GOOD LUCK Source: Matematika Numerik dengan Implementasi Matlab, Julan Hernadi, Penerbit Andi (2012) sharing.auliakhalqillah.com