© 2019 Dr.Rathishchandra.R.Gatti .
Getting Started with
MATLAB/Octave for Engineers
OCTAVE
Dr. Rathishchandra. R. Gatti
Professor- Mech. Engg
gattirathish@gmail.com
MATLAB is the registered trademark of Mathworks Inc.
GNU Octave is an Open source software.
1
Level 0
© 2019 Dr.Rathishchandra.R.Gatti .
AGENDA
1. Introduction to MATLAB
2. Introduction to Octave
3. Some Hands-on Using Octave
2
© 2019 Dr.Rathishchandra.R.Gatti .
OBJECTIVES OF THIS WORKSHOP
• To make you familiar with computational tools
that every engineer MUST know.
• To push you to learn these tools during your
holidays and use them next year for FY projects.
“NO MATH, NO ENGINEERING.
KNOW MATH, KNOW ENGINEERING.”
3
© 2019 Dr.Rathishchandra.R.Gatti .
1. Introduction to MATLAB
• High level Programming language = Easy to
prototype language of your logic /algorithm.
• Extensive repository of Toolboxes and in-built
functions
• It is a commercial package with student and
commercial licenses.
• MATLAB = MATRIX + LAB . It is based on
Matrices and Vectors.
4
© 2019 Dr.Rathishchandra.R.Gatti . 5
© 2019 Dr.Rathishchandra.R.Gatti . 6
© 2019 Dr.Rathishchandra.R.Gatti .
2. Introduction to OCTAVE
• High level Programming language = Easy to
prototype language of your logic /algorithm.
• Extensive repository of packages and in-built
functions. Downloadable .pkg files.
• It is completely OPEN SOURCE – FREE and
Source code can be edited .
• Used prominently in Scholarly institutes who
donot like someone else to build code for
them.
7
© 2019 Dr.Rathishchandra.R.Gatti . 8
© 2019 Dr.Rathishchandra.R.Gatti .
3. Opinion
• Both MATLAB and GNU Octave are good in
their own merits.
• Do not waste time by being a fanatic of either
commercial or open source. Be a fanatic of
“GETTING THINGS DONE” .
• Use what is available – SURVIVAL
INSTINCT.
9
© 2019 Dr.Rathishchandra.R.Gatti .
GNU Octave
10
© 2019 Dr.Rathishchandra.R.Gatti .
1. Downloading & Installing GNU Octave
11
Web clipped from https://www.gnu.org/software/octave/
© 2019 Dr.Rathishchandra.R.Gatti .
1. Downloading & Installing GNU Octave
12
Web clipped from https://www.gnu.org/software/octave/
© 2019 Dr.Rathishchandra.R.Gatti .
1. Downloading & Installing GNU Octave
13
Web clipped from https://www.gnu.org/software/octave/
© 2019 Dr.Rathishchandra.R.Gatti .
2. Running GNU Octave
Command Line Interface
Graphical User Interface
14
© 2019 Dr.Rathishchandra.R.Gatti .
a = [1 2 3….10]
b = a3+3a2+4a
Plot a v.s bCommand Line Interface
15
© 2019 Dr.Rathishchandra.R.Gatti .
Graphical User Interface
16
© 2019 Dr.Rathishchandra.R.Gatti .
Programming approaches
• Script level programming (.m files) – creating
M files for small programs.
• Functional programming- creating modules or
packages with several interdependent M
function files.
17
© 2019 Dr.Rathishchandra.R.Gatti .
Two Script programming approaches :
Option 1 : First script and then run
commands
Option 2 : First evaluate commands
and then script
18
© 2019 Dr.Rathishchandra.R.Gatti .
Option 1 : First script and then run commands
19
© 2019 Dr.Rathishchandra.R.Gatti .
Option 2 : First evaluate commands and then script
20
© 2019 Dr.Rathishchandra.R.Gatti .
Simple program #1
##OK let us write a program
a=[20,15,30;40 75,-40;30,23,67];
b=exp(4.*a);
21
© 2019 Dr.Rathishchandra.R.Gatti .
x = -10:0.1:10; # Create an evenly-
spaced vector from -10..10
y = sin (x); # y is also a vector
plot (x, y);
title ("Simple 2-D Plot");
xlabel ("x");
ylabel ("sin (x)");
Simple program #2
Source : https://www.gnu.org/software/octave/#install
22
© 2019 Dr.Rathishchandra.R.Gatti . 23
© 2019 Dr.Rathishchandra.R.Gatti .
Simple program #3
x = -10:0.1:10; # Create an evenly-spaced
vector from -10..10
y = sin (x); # y is also a vector
z = cos(x);
plot3 (x, y, z);
title ("Simple 2-D Plot");
xlabel ("x");
ylabel ("sin (x)");
zlabel ("cos (x)");
24
© 2019 Dr.Rathishchandra.R.Gatti . 25
© 2019 Dr.Rathishchandra.R.Gatti . 26
© 2019 Dr.Rathishchandra.R.Gatti .
Simple program #4
tx = ty = linspace (-8, 8, 41)';
[xx, yy] = meshgrid (tx, ty);
r = sqrt (xx .^ 2 + yy .^ 2) + eps;
tz = sin (r) ./ r;
mesh (tx, ty, tz);
xlabel ("tx");
ylabel ("ty");
zlabel ("tz");
title ("3-D Sombrero plot");
Source : https://www.gnu.org/software/octave/#install
27
© 2019 Dr.Rathishchandra.R.Gatti . 28
© 2019 Dr.Rathishchandra.R.Gatti . 29
Octave Use in Typical Theoretical Analysis
Theoretical equation
Numerical equation
Numerical solving
Numerical solution
Data visualisation and analysis
Convert to numerical equation using Laplace or
Statespace or any other methods
Convert to numerical equation using Laplace or
Statespace or any other methods
[x, istate, msg] = lsode (fcn, x_0, t)
[x, istate, msg] = lsode (fcn, x_0, t, t_crit)
© 2019 Dr.Rathishchandra.R.Gatti . 30
Experiment
Setup
t = xlsread (‘Test.xls', ‘sheet1', 'C4:AB38');
XLS or CSV
format data
Data
Logger
Octave Use in Typical Experimentation
Sensors
q = t* Pi*C*d2;
XLS Data Visualisation
© 2019 Dr.Rathishchandra.R.Gatti .
Octave Forge
This is like the
the play store of Octave apps
https://octave.sourceforge.io/packages.php
31
© 2019 Dr.Rathishchandra.R.Gatti .
https://octave.sourceforge.io/packages.php
32
© 2019 Dr.Rathishchandra.R.Gatti .
First to know if you already have packages
Type “ pkg list” and Hit enter
33
© 2019 Dr.Rathishchandra.R.Gatti .
pkg install -forge package_name
pkg load package_name
pkg install -forge linear-algebra
pkg load linear-algebra
Format :
Example :
34
© 2019 Dr.Rathishchandra.R.Gatti .
Source: https://octave.sourceforge.io/packages.php
35
© 2019 Dr.Rathishchandra.R.Gatti .
Source: https://octave.sourceforge.io/packages.php
36
© 2019 Dr.Rathishchandra.R.Gatti . 37
Not Enough time to explain …
Encourage you to contact any of us (faculty) and
learn as much as possible these tools before you
graduate.
Most importantly, USE THESE TOOLS before you
graduate.
Thank you 

Getting Started with MATLAB and OCTAVE for engineers