SlideShare a Scribd company logo
2
Most read
3
Most read
9
Most read
Introduction to Octave
Programming
Milad Nourizade
Urmia University of Technology
history
• At first it was intended to be a companion to a
chemical reactor design course software.
• Real development was started by Prof. John
W.Eaton in 1992.
• Octave version 5.1.0 has been released in
Mar 1,2019
Octave, the language
• GNU Octave is a high-level primarily intended for
numerical computations. It is typically used for such
problems as solving linear and nonlinear equations,
numerical linear algebra, statistical analysis. It is
particularly designed for matrix computations.
• The Octave language is an interpreted programming
language. It is free software under the terms of GNU
General Public License (GPL) written in C, C++, Fortran.
• Octave’s mostly syntax compatible with MATLAB which
is commonly used in industry and academia.
Who uses octave?
• NASA use it to develop spacecraft docking
systems.
• Jaguar Racing use it to display and analyse data
transmitted from their Formula 1 cars.
• Sheffield University use it to develop software to
recognize cancerous cells.
Variables
• We can assign a variable much like any other
language.
• In Octave we don’t declare the variable type,
Octave will do this on creation.
• A=5 name = “ Milad”
Arithmetic
• Addition +
• Subtraction -
• Multiplication *
• Division /
• Element-wise .+ .- .* ./ .^
Vectors and Matrices
• Vectors are n*1 or 1*n matrices:
• Row Vectors r= [1 2 3 4 5] or [1, 2, 3, 4, 5]
• Column Vectors c = [1;2;3;4;5]
• m = [1 2; 3 4]
• 2 by 2 matrix
1 2
3 4
Special Matrices
• Ones(n, m) — generates a matrix n x m of 1’s
• Zeros(n, m) — generates a matrix n x m of 0’s
• Eye(n) — generates n x n identity matrix
• Rand(n , m) — generates n x m matrix of
uniformly random elements.
• Magic(n) — generates n x n matrix that sum of
elements in row, column and diagonal is equal.
Colon Operator
• The colon operator is a great syntax for creating
a set of values.
• R = 1:5 returns a vector [1 2 3 4 5] with 1’s
steps.
• Or we can change steps with a specific step:
• S = 1:0.1:10 [1 , 1.1, 1.2, 1.3, … , 10]
Indexing
• Now we know about vectors and matrices how we can access
elements?
• *** Be careful Octave is not zero index it is one.
• S = [1 2; 3 4]
• S(1, 1) will return 1
S(1, [1,2]) will return [1, 2]
S(1, 1:2) will return [1, 2]
S(1, :) will return [1, 2]
• Colon operator here is like selecting all
Boolean Operators
• As you know this part is almost is same in todays programming
languages.
• == - Is Equal to
• != or ~= - Not Equal to
• > - Greater than
• < - Less than
• >= - Greater or equal to
• <= - Less than or equal to
• E.g 5 >= 4 ans = 1 5 <= 4 ans = 0
The if else Statement
• if (condition)
then-body
elseif (condition)
elseif-body
else
else-body
endif;
• Parenthesis is optional and you can use both
end and endif
For & While loop
• for i = 1:10
body;
endfor;
• while (condition)
body;
endwhile;
• As same you can summarize endfor and end
while with end.
Functions
• Functions with return value:
function ret = myFuncName(arguments)
do something with arguments and
set ret.
endfunction
• Functions with none-return value:
myFuncName(arguments)
do something with arguments
endfunction
.m files
• .m files are octave scripts to be run.
• Each function in Octave must be in its .m file of
the same name.
• Eg. minimum(x) needs to go in a file called
minimum.m
The edit command
• Octave CLI support some basic commands:
• ls
• cd
• pwd
• …
• Using Octave CLI you can use edit command to
open or create .m file in specific directory.
• Eg. edit mini.m
Multiple return values
• Octave supports returning more than one variable from a
function.
• All we have to do is putting return values in a matrix.
• The syntax:
function [ret1, ret2, … , ret n] = myFuncName(arguments)
do something with arguments and
set return values.
endfunction
Load & Save file
• Loading file in Octave is very easy to do.
Accepting many different data format.
• load <filename> or load(“ filename”) Which
loads file in a vector or matrix.
• Ether you can save data easy as loading.
• save < filename > variable

More Related Content

PPTX
Four Pillers Of OOPS
PPT
Working with Callbacks
PPTX
Photoshop
PDF
Matlab-Data types and operators
ODP
Hands on Session on Python
PDF
Immutable vs mutable data types in python
PPTX
أنظمة إدارة التعلم.pptx
DOCX
C# Unit 1 notes
Four Pillers Of OOPS
Working with Callbacks
Photoshop
Matlab-Data types and operators
Hands on Session on Python
Immutable vs mutable data types in python
أنظمة إدارة التعلم.pptx
C# Unit 1 notes

What's hot (20)

PPTX
Theory of computation:Finite Automata, Regualr Expression, Pumping Lemma
PPTX
Rethrowing exception- JAVA
PPT
An introduction to photoshop
PPTX
Matlab matrices and arrays
PPT
Unit 2 Java
PDF
OpenGL Introduction.
PPSX
مهارات أساسية في التعامل مع برنـامج Microsoft Office Word
PPTX
وحدات الادخال والاخراج
PPTX
Java awt (abstract window toolkit)
PPTX
Introduction to computer graphics
PDF
Topological Sorting (Decrease and Conquer)
DOCX
Examen Principal - Fondement Multimedia Janvier 2015
PDF
Introduction to JavaFX
PPTX
تصميم المواقع الالكترونية عرض
PDF
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobot
PPTX
Scaling and shearing
PDF
Chapter 04 computer codes
PPTX
Design of a two pass assembler
PPTX
simple problem to convert NFA with epsilon to without epsilon
PPT
TP N°1 sketchup.ppt
Theory of computation:Finite Automata, Regualr Expression, Pumping Lemma
Rethrowing exception- JAVA
An introduction to photoshop
Matlab matrices and arrays
Unit 2 Java
OpenGL Introduction.
مهارات أساسية في التعامل مع برنـامج Microsoft Office Word
وحدات الادخال والاخراج
Java awt (abstract window toolkit)
Introduction to computer graphics
Topological Sorting (Decrease and Conquer)
Examen Principal - Fondement Multimedia Janvier 2015
Introduction to JavaFX
تصميم المواقع الالكترونية عرض
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobot
Scaling and shearing
Chapter 04 computer codes
Design of a two pass assembler
simple problem to convert NFA with epsilon to without epsilon
TP N°1 sketchup.ppt
Ad

Similar to Gnu octave (20)

PDF
Clojure intro
PDF
Lecture 01 variables scripts and operations
PDF
Logic Programming and ILP
PPTX
Unit 1.pptx
PDF
BCS401 ADA First IA Test Question Bank.pdf
PPTX
Algorithms & Complexity Calculation
PPTX
Dr.C S Prasanth-Physics ppt.pptx computer
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PDF
DSJ_Unit I & II.pdf
PPTX
Developer’s viewpoint on swift programming language
PDF
Matlab lec1
PDF
DSA
PPTX
Should i Go there
PPTX
Java 101 intro to programming with java
PPTX
Java 101 Intro to Java Programming
PPT
02 functions, variables, basic input and output of c++
PPT
PDF
DAA Notes.pdf
PPTX
Unit I - 1R introduction to R program.pptx
PPTX
Introduction to java 101
Clojure intro
Lecture 01 variables scripts and operations
Logic Programming and ILP
Unit 1.pptx
BCS401 ADA First IA Test Question Bank.pdf
Algorithms & Complexity Calculation
Dr.C S Prasanth-Physics ppt.pptx computer
Basic concept of Python.pptx includes design tool, identifier, variables.
DSJ_Unit I & II.pdf
Developer’s viewpoint on swift programming language
Matlab lec1
DSA
Should i Go there
Java 101 intro to programming with java
Java 101 Intro to Java Programming
02 functions, variables, basic input and output of c++
DAA Notes.pdf
Unit I - 1R introduction to R program.pptx
Introduction to java 101
Ad

Recently uploaded (20)

PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Soil Improvement Techniques Note - Rabbi
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
R24 SURVEYING LAB MANUAL for civil enggi
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Safety Seminar civil to be ensured for safe working.
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Soil Improvement Techniques Note - Rabbi
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Visual Aids for Exploratory Data Analysis.pdf
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
III.4.1.2_The_Space_Environment.p pdffdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...

Gnu octave

  • 1. Introduction to Octave Programming Milad Nourizade Urmia University of Technology
  • 2. history • At first it was intended to be a companion to a chemical reactor design course software. • Real development was started by Prof. John W.Eaton in 1992. • Octave version 5.1.0 has been released in Mar 1,2019
  • 3. Octave, the language • GNU Octave is a high-level primarily intended for numerical computations. It is typically used for such problems as solving linear and nonlinear equations, numerical linear algebra, statistical analysis. It is particularly designed for matrix computations. • The Octave language is an interpreted programming language. It is free software under the terms of GNU General Public License (GPL) written in C, C++, Fortran. • Octave’s mostly syntax compatible with MATLAB which is commonly used in industry and academia.
  • 4. Who uses octave? • NASA use it to develop spacecraft docking systems. • Jaguar Racing use it to display and analyse data transmitted from their Formula 1 cars. • Sheffield University use it to develop software to recognize cancerous cells.
  • 5. Variables • We can assign a variable much like any other language. • In Octave we don’t declare the variable type, Octave will do this on creation. • A=5 name = “ Milad”
  • 6. Arithmetic • Addition + • Subtraction - • Multiplication * • Division / • Element-wise .+ .- .* ./ .^
  • 7. Vectors and Matrices • Vectors are n*1 or 1*n matrices: • Row Vectors r= [1 2 3 4 5] or [1, 2, 3, 4, 5] • Column Vectors c = [1;2;3;4;5] • m = [1 2; 3 4] • 2 by 2 matrix 1 2 3 4
  • 8. Special Matrices • Ones(n, m) — generates a matrix n x m of 1’s • Zeros(n, m) — generates a matrix n x m of 0’s • Eye(n) — generates n x n identity matrix • Rand(n , m) — generates n x m matrix of uniformly random elements. • Magic(n) — generates n x n matrix that sum of elements in row, column and diagonal is equal.
  • 9. Colon Operator • The colon operator is a great syntax for creating a set of values. • R = 1:5 returns a vector [1 2 3 4 5] with 1’s steps. • Or we can change steps with a specific step: • S = 1:0.1:10 [1 , 1.1, 1.2, 1.3, … , 10]
  • 10. Indexing • Now we know about vectors and matrices how we can access elements? • *** Be careful Octave is not zero index it is one. • S = [1 2; 3 4] • S(1, 1) will return 1 S(1, [1,2]) will return [1, 2] S(1, 1:2) will return [1, 2] S(1, :) will return [1, 2] • Colon operator here is like selecting all
  • 11. Boolean Operators • As you know this part is almost is same in todays programming languages. • == - Is Equal to • != or ~= - Not Equal to • > - Greater than • < - Less than • >= - Greater or equal to • <= - Less than or equal to • E.g 5 >= 4 ans = 1 5 <= 4 ans = 0
  • 12. The if else Statement • if (condition) then-body elseif (condition) elseif-body else else-body endif; • Parenthesis is optional and you can use both end and endif
  • 13. For & While loop • for i = 1:10 body; endfor; • while (condition) body; endwhile; • As same you can summarize endfor and end while with end.
  • 14. Functions • Functions with return value: function ret = myFuncName(arguments) do something with arguments and set ret. endfunction • Functions with none-return value: myFuncName(arguments) do something with arguments endfunction
  • 15. .m files • .m files are octave scripts to be run. • Each function in Octave must be in its .m file of the same name. • Eg. minimum(x) needs to go in a file called minimum.m
  • 16. The edit command • Octave CLI support some basic commands: • ls • cd • pwd • … • Using Octave CLI you can use edit command to open or create .m file in specific directory. • Eg. edit mini.m
  • 17. Multiple return values • Octave supports returning more than one variable from a function. • All we have to do is putting return values in a matrix. • The syntax: function [ret1, ret2, … , ret n] = myFuncName(arguments) do something with arguments and set return values. endfunction
  • 18. Load & Save file • Loading file in Octave is very easy to do. Accepting many different data format. • load <filename> or load(“ filename”) Which loads file in a vector or matrix. • Ether you can save data easy as loading. • save < filename > variable