SlideShare a Scribd company logo
1 of 37
Download to read offline
5. OCTAVE
• % comment line
Basic Operations:
• 5+6
• 3-2
• 5*8
• 4/2
• 2^6 power
➢Logical:
1==2 %false = 0
1~=2(not equal) %true = 1
➢To change the prompt string: PS1(‘>> ‘);
➢Semicolon supresses output: put ; at the end of code line:
o/p won’t print
➢Semicolon is also used to write two statements on same line
➢Chaining with “ , ” is also possible, but it will print the o/p
≫ Variables:
a=3
b=’hi’ %single quotes are used for strings
c = (3>=1) %c=1 %true
a=pi %pi is predefined
To print a:
o a o disp(a);
To display strings:
o disp(sprintf(‘ pi to 2 decimal places: %0.2f ‘, a))
pi to 2 decimal places: 3.14
 Format Shortcut:
o format long %3.14159265358979
o format short % 3.1416
MATRICES AND VECTORS:
Matrix: ; to change rows Using secondary prompt:
Vectors:
Row vector: Column vector:
➢Range Vectors:
It starts at 1 and increments in steps of 0.1 upto 2: 1 & 2 are
inclusive
Special vector functions:
➢ones :
➢zeros:
➢rand(row, col): gives random numbers bw 0 and 1
using Uniform Distribution
➢randn(row, col): gives random no from galsian distribution with
mean=0 and variance =1
➢Histograms:
This plots the given matrix on a histogram.
Histograms mean value is = -6 in this case
: this incr the no of pins
➢Identity matrix:
➢size(matrix): return a 1x2 vector of size of another matrix
It can also be assigned as a vector:
help command:
o help eye
o help rand
help help
➢When only no of rows or cols of A are req:
length(matrix): returns the largest dimension; mostly used
for vectors
present working directory:
change dir:
listing files and folders:
loading files in octave:
➢featuresX.dat and priceY.dat contains input and o/p data:
➢this command will load the file_name.extention into a
variable named file_name
Or as string:

finding out variables that are currently assigned:
Detailed view:
clear variable_name – deletes var from memory: type who to
check
clear : clears every var
Saving a variable into a file
If we clear after this
Then if we load back the file “hello.mat”
It will load back the variable v… not hello
To save as human readable format:
MATRIX DATA HANDLING:
returns element at row=3; col=2
Shorthand methods:
Returns a vector
Let:
Getting multiple rows or
columns:
It can also be used for assignment:
It replaces the 2nd col of every row
in the matrix
Appending a row or col:
Now let:
joining 2 matrices column wise: == C = [A, B]
joining 2 matrices row wise:
COMPUTATION ON DATA:
Matrix multiplication: Element-wise
multiplication:
Element-wise exponent:
Elementwise Reciprocal:
Reciprocation of a vector or
matrices: element wise:
Element-wise logarithm: Elementwise exponent with
e %ev
Element wise absolute: Elementwise negation:
Creating a float matrix:
Incrementing every element:
Or
Transpose:
Finding max element in a vector:
val = value
ind = index -- starts from 1
Max element in a matrix:
Elemnt wise max
Compares corresponding elements of both matrices
Column wise max:
1 is for column
Row wise max:
2 is for row wise
max(A) will do column wise max: by default
Absolute max in a matrix
Or
Element wise comparison: Finding elements based on
comparison:
Magic matrix: every row/col/diagonal adds up to same no.
Finding indices of elements based on conditions:
Here r are the row indices and c are col indices
Corresponding to (1, 1) (3, 2) (2, 3)
Sum of all elements of a vector:
Column wise sum:
1 is for column
Row wise sum:
2 is for rows
Sum of main diagonal:
Sum of secondary diagonal:
Product of all elements of a vector:
Element wise Floor :
Element wise Ceil:
Inverse of a matrix:
pinv is a pseudo inverse function.. it gives just approximate
inverse values:
temp is inverse of A.. still temp * A is not identity matrix
its just nearly identical
PLOTTING DATA:
Let:
Plotting a sine curve using the values in t
Similar for cos:
Hold on:
This will plot y2 first and then plot y1 but then y2 will disappear
So we use: hold on to plot another curve in the same window:
‘r’ is to use diff color -- red
Giving it labels, legend and title:
Saving the plot into an image file:
Closing a figure:
$close
To plot more than one plots simultaneously but in diff windows:
Specify the figure number:
Subplots:
access the 2nd
element
Setting axis ranges for plots:
To clear all figures: $clf
To plot a matrix as a set of colours: each colour denote a value
specified by range:
The range is given in colour bar
To bring it to greyscale: and to also bring out the colour bar:
CONTROL STRUCTURES:
For loop: Let:
Using list control:
While loop:
If statements:
an infinite loop is used.
If-elseif-else:
Exit: $exit or $quit
FUNCTIONS:
Functions are saved in different file in pwd: name of file = name of
function
Extension= .m
Here, function y denotes that it’s a fxn and “y” is the return
parameter
(x) = argument
Then the statements through which return parameters are
calculated
To execute a fxn: cd to the location of file; and call()
Or: we can just change the octave search path for fxns:
Fxns can return multiple values:
Calculating the minimum cost error
Let:
Here,
X → m x (n+1) n=1
y → m x 1 o/p of all examples
theta = (n+1) x 1
predictions = X * Θ = m x 1 – here, hypothesis value of each
example is calculated separately and stored in diff rows.
(prediction – y) – this id the term of diff bw predicted value and
actual value
Both are m x 1 vectors: so it subtracts from
corresponding elements.
sqrErrors -- elementwise sqr is used then all values are
summed
and J is calculated
J=0 means the chosen values of Θ perfectly fits the given data
Here 2.333 = sum of sqr of all values of y divided by 2m
VECTORIZATION:
Comparing implementations:
Gradient descent:
Here Θ and δ are vectors
Where
Dimensions:
Where
Where
The above multiplication of vectors is like :
For loop implementation:
Vectorized implementation:

More Related Content

What's hot

Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applicationsRinkuMonani
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programmingAhmed Moawad
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheetlokeshkumer
 
Evaluation of programs codes using machine learning
Evaluation of programs codes using machine learningEvaluation of programs codes using machine learning
Evaluation of programs codes using machine learningVivek Maskara
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Philip Schwarz
 

What's hot (20)

7 regularization
7 regularization7 regularization
7 regularization
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 
Mbd2
Mbd2Mbd2
Mbd2
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
R normal distribution
R   normal distributionR   normal distribution
R normal distribution
 
Interpolation and its applications
Interpolation and its applicationsInterpolation and its applications
Interpolation and its applications
 
Graph Representation
Graph RepresentationGraph Representation
Graph Representation
 
R - binomial distribution
R - binomial distributionR - binomial distribution
R - binomial distribution
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheet
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Fourier Transform Assignment Help
Fourier Transform Assignment HelpFourier Transform Assignment Help
Fourier Transform Assignment Help
 
Intro to Matlab programming
Intro to Matlab programmingIntro to Matlab programming
Intro to Matlab programming
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheet
 
Evaluation of programs codes using machine learning
Evaluation of programs codes using machine learningEvaluation of programs codes using machine learning
Evaluation of programs codes using machine learning
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
L06
L06L06
L06
 
Matlab quickref
Matlab quickrefMatlab quickref
Matlab quickref
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
 
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZEAPPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
 

Similar to 5 octave tutorial

Similar to 5 octave tutorial (20)

Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Matlab1
Matlab1Matlab1
Matlab1
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Fst ch2 notes
Fst ch2 notesFst ch2 notes
Fst ch2 notes
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
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
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Es272 ch1
Es272 ch1Es272 ch1
Es272 ch1
 

More from TanmayVijay1

18 application example photo ocr
18 application example  photo ocr18 application example  photo ocr
18 application example photo ocrTanmayVijay1
 
1 Introduction to Machine Learning
1 Introduction to Machine Learning1 Introduction to Machine Learning
1 Introduction to Machine LearningTanmayVijay1
 
17 large scale machine learning
17 large scale machine learning17 large scale machine learning
17 large scale machine learningTanmayVijay1
 
16 recommender systems
16 recommender systems16 recommender systems
16 recommender systemsTanmayVijay1
 
11 ml system design
11 ml system design11 ml system design
11 ml system designTanmayVijay1
 
10 advice for applying ml
10 advice for applying ml10 advice for applying ml
10 advice for applying mlTanmayVijay1
 
6 logistic regression classification algo
6 logistic regression   classification algo6 logistic regression   classification algo
6 logistic regression classification algoTanmayVijay1
 
3 linear algebra review
3 linear algebra review3 linear algebra review
3 linear algebra reviewTanmayVijay1
 

More from TanmayVijay1 (8)

18 application example photo ocr
18 application example  photo ocr18 application example  photo ocr
18 application example photo ocr
 
1 Introduction to Machine Learning
1 Introduction to Machine Learning1 Introduction to Machine Learning
1 Introduction to Machine Learning
 
17 large scale machine learning
17 large scale machine learning17 large scale machine learning
17 large scale machine learning
 
16 recommender systems
16 recommender systems16 recommender systems
16 recommender systems
 
11 ml system design
11 ml system design11 ml system design
11 ml system design
 
10 advice for applying ml
10 advice for applying ml10 advice for applying ml
10 advice for applying ml
 
6 logistic regression classification algo
6 logistic regression   classification algo6 logistic regression   classification algo
6 logistic regression classification algo
 
3 linear algebra review
3 linear algebra review3 linear algebra review
3 linear algebra review
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

5 octave tutorial

  • 1. 5. OCTAVE • % comment line Basic Operations: • 5+6 • 3-2 • 5*8 • 4/2 • 2^6 power ➢Logical: 1==2 %false = 0 1~=2(not equal) %true = 1 ➢To change the prompt string: PS1(‘>> ‘); ➢Semicolon supresses output: put ; at the end of code line: o/p won’t print ➢Semicolon is also used to write two statements on same line ➢Chaining with “ , ” is also possible, but it will print the o/p ≫ Variables: a=3 b=’hi’ %single quotes are used for strings c = (3>=1) %c=1 %true a=pi %pi is predefined To print a: o a o disp(a);
  • 2. To display strings: o disp(sprintf(‘ pi to 2 decimal places: %0.2f ‘, a)) pi to 2 decimal places: 3.14  Format Shortcut: o format long %3.14159265358979 o format short % 3.1416 MATRICES AND VECTORS: Matrix: ; to change rows Using secondary prompt: Vectors: Row vector: Column vector:
  • 3. ➢Range Vectors: It starts at 1 and increments in steps of 0.1 upto 2: 1 & 2 are inclusive Special vector functions: ➢ones :
  • 4. ➢zeros: ➢rand(row, col): gives random numbers bw 0 and 1 using Uniform Distribution ➢randn(row, col): gives random no from galsian distribution with mean=0 and variance =1
  • 5. ➢Histograms: This plots the given matrix on a histogram. Histograms mean value is = -6 in this case : this incr the no of pins
  • 6. ➢Identity matrix: ➢size(matrix): return a 1x2 vector of size of another matrix It can also be assigned as a vector: help command: o help eye o help rand help help
  • 7. ➢When only no of rows or cols of A are req: length(matrix): returns the largest dimension; mostly used for vectors present working directory: change dir:
  • 8. listing files and folders: loading files in octave: ➢featuresX.dat and priceY.dat contains input and o/p data: ➢this command will load the file_name.extention into a variable named file_name Or as string:  finding out variables that are currently assigned:
  • 9. Detailed view: clear variable_name – deletes var from memory: type who to check clear : clears every var Saving a variable into a file If we clear after this Then if we load back the file “hello.mat” It will load back the variable v… not hello To save as human readable format:
  • 10. MATRIX DATA HANDLING: returns element at row=3; col=2 Shorthand methods: Returns a vector Let:
  • 11. Getting multiple rows or columns: It can also be used for assignment: It replaces the 2nd col of every row in the matrix Appending a row or col:
  • 12. Now let: joining 2 matrices column wise: == C = [A, B] joining 2 matrices row wise:
  • 13. COMPUTATION ON DATA: Matrix multiplication: Element-wise multiplication: Element-wise exponent: Elementwise Reciprocal: Reciprocation of a vector or matrices: element wise:
  • 14. Element-wise logarithm: Elementwise exponent with e %ev Element wise absolute: Elementwise negation:
  • 15. Creating a float matrix: Incrementing every element: Or Transpose:
  • 16. Finding max element in a vector: val = value ind = index -- starts from 1 Max element in a matrix: Elemnt wise max Compares corresponding elements of both matrices
  • 17. Column wise max: 1 is for column Row wise max: 2 is for row wise max(A) will do column wise max: by default Absolute max in a matrix Or
  • 18. Element wise comparison: Finding elements based on comparison: Magic matrix: every row/col/diagonal adds up to same no. Finding indices of elements based on conditions: Here r are the row indices and c are col indices Corresponding to (1, 1) (3, 2) (2, 3)
  • 19. Sum of all elements of a vector: Column wise sum: 1 is for column Row wise sum: 2 is for rows
  • 20. Sum of main diagonal: Sum of secondary diagonal:
  • 21. Product of all elements of a vector: Element wise Floor : Element wise Ceil: Inverse of a matrix:
  • 22. pinv is a pseudo inverse function.. it gives just approximate inverse values: temp is inverse of A.. still temp * A is not identity matrix its just nearly identical PLOTTING DATA: Let: Plotting a sine curve using the values in t
  • 23. Similar for cos: Hold on: This will plot y2 first and then plot y1 but then y2 will disappear So we use: hold on to plot another curve in the same window: ‘r’ is to use diff color -- red
  • 24. Giving it labels, legend and title:
  • 25. Saving the plot into an image file: Closing a figure: $close To plot more than one plots simultaneously but in diff windows: Specify the figure number: Subplots:
  • 26. access the 2nd element Setting axis ranges for plots:
  • 27. To clear all figures: $clf To plot a matrix as a set of colours: each colour denote a value specified by range: The range is given in colour bar
  • 28. To bring it to greyscale: and to also bring out the colour bar: CONTROL STRUCTURES: For loop: Let:
  • 30. While loop: If statements: an infinite loop is used.
  • 31. If-elseif-else: Exit: $exit or $quit FUNCTIONS: Functions are saved in different file in pwd: name of file = name of function Extension= .m
  • 32. Here, function y denotes that it’s a fxn and “y” is the return parameter (x) = argument Then the statements through which return parameters are calculated To execute a fxn: cd to the location of file; and call() Or: we can just change the octave search path for fxns: Fxns can return multiple values:
  • 33. Calculating the minimum cost error Let:
  • 34. Here, X → m x (n+1) n=1 y → m x 1 o/p of all examples theta = (n+1) x 1 predictions = X * Θ = m x 1 – here, hypothesis value of each example is calculated separately and stored in diff rows. (prediction – y) – this id the term of diff bw predicted value and actual value Both are m x 1 vectors: so it subtracts from corresponding elements. sqrErrors -- elementwise sqr is used then all values are summed and J is calculated J=0 means the chosen values of Θ perfectly fits the given data Here 2.333 = sum of sqr of all values of y divided by 2m
  • 37. Where The above multiplication of vectors is like : For loop implementation: Vectorized implementation: