SlideShare a Scribd company logo
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
Ad

Recommended

CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
Eng Teong Cheah
 
pg_chameleon MySQL to PostgreSQL replica made easy
pg_chameleon MySQL to PostgreSQL replica made easy
Federico Campoli
 
Union in C programming
Union in C programming
Kamal Acharya
 
Structures in c language
Structures in c language
Tanmay Modi
 
Functions in Python
Functions in Python
Shakti Singh Rathore
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
sumitbardhan
 
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Michael Redlich
 
Structure in c
Structure in c
Prabhu Govind
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++
Hitesh Kumar
 
standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
OOPs in Java
OOPs in Java
Ranjith Sekar
 
GNU octave
GNU octave
gauravmalav
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
ICS
 
Structures in c language
Structures in c language
tanmaymodi4
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16
sumitbardhan
 
Xml query language and navigation
Xml query language and navigation
Raghu nath
 
安全なPHPアプリケーションの作り方2016
安全なPHPアプリケーションの作り方2016
Hiroshi Tokumaru
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
thewebsacademy
 
Stl Containers
Stl Containers
ppd1961
 
Introduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
ZIO-Direct - Functional Scala 2022
ZIO-Direct - Functional Scala 2022
Alexander Ioffe
 
Arrays and structures
Arrays and structures
Mohd Arif
 
Chapter 01.ppt
Chapter 01.ppt
JulijaKaraliunaite1
 
Chapter 01.ppt
Chapter 01.ppt
JulijaKaraliunaite1
 

More Related Content

What's hot (20)

Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Michael Redlich
 
Structure in c
Structure in c
Prabhu Govind
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++
Hitesh Kumar
 
standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
OOPs in Java
OOPs in Java
Ranjith Sekar
 
GNU octave
GNU octave
gauravmalav
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
ICS
 
Structures in c language
Structures in c language
tanmaymodi4
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16
sumitbardhan
 
Xml query language and navigation
Xml query language and navigation
Raghu nath
 
安全なPHPアプリケーションの作り方2016
安全なPHPアプリケーションの作り方2016
Hiroshi Tokumaru
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
thewebsacademy
 
Stl Containers
Stl Containers
ppd1961
 
Introduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
ZIO-Direct - Functional Scala 2022
ZIO-Direct - Functional Scala 2022
Alexander Ioffe
 
Arrays and structures
Arrays and structures
Mohd Arif
 
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Michael Redlich
 
Abstraction in c++ and Real Life Example of Abstraction in C++
Abstraction in c++ and Real Life Example of Abstraction in C++
Hitesh Kumar
 
standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Abstract class in c++
Abstract class in c++
Sujan Mia
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
ICS
 
Structures in c language
Structures in c language
tanmaymodi4
 
Python Workshop Part 2. LUG Maniapl
Python Workshop Part 2. LUG Maniapl
Ankur Shrivastava
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16
sumitbardhan
 
Xml query language and navigation
Xml query language and navigation
Raghu nath
 
安全なPHPアプリケーションの作り方2016
安全なPHPアプリケーションの作り方2016
Hiroshi Tokumaru
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
thewebsacademy
 
Stl Containers
Stl Containers
ppd1961
 
ZIO-Direct - Functional Scala 2022
ZIO-Direct - Functional Scala 2022
Alexander Ioffe
 
Arrays and structures
Arrays and structures
Mohd Arif
 

Similar to Basic of octave matlab programming language (20)

Chapter 01.ppt
Chapter 01.ppt
JulijaKaraliunaite1
 
Chapter 01.ppt
Chapter 01.ppt
JulijaKaraliunaite1
 
Matlab ch1 intro
Matlab ch1 intro
Ragu Nathan
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
Matlab
Matlab
Abdulbasit Hassan
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
Matlab1
Matlab1
guest8ba004
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
BeheraA
 
Mmc manual
Mmc manual
Urvi Surat
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
Matlab 1
Matlab 1
asguna
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
eAssessment in Practice Symposium
 
1. Ch_1 SL_1_Intro to Matlab.pptx
1. Ch_1 SL_1_Intro to Matlab.pptx
MOHAMMAD SAYDUL ALAM
 
Raushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptx
hmghj
 
presentation.pptx
presentation.pptx
raghav415187
 
Matlab Nn Intro
Matlab Nn Intro
Imthias Ahamed
 
Introduction to matlab
Introduction to matlab
vikrammutneja1
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
tejas1235
 
Matlab ch1 intro
Matlab ch1 intro
Ragu Nathan
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
BeheraA
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
Matlab 1
Matlab 1
asguna
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
Raushan's MATLB PPT..pptx
Raushan's MATLB PPT..pptx
hmghj
 
Introduction to matlab
Introduction to matlab
vikrammutneja1
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
tejas1235
 
Ad

Recently uploaded (20)

THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
2025 Completing the Pre-SET Plan Form.pptx
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Code Profiling in Odoo 18 - Odoo 18 Slides
Code Profiling in Odoo 18 - Odoo 18 Slides
Celine George
 
2025 Completing the Pre-SET Plan Form.pptx
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT KGP Quiz Week 2024 Sports Quiz (Prelims + Finals)
IIT Kharagpur Quiz Club
 
Ad

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