0% found this document useful (0 votes)
9 views28 pages

CPT3701 LU Introduction

Thermodynamics Lectures. University Tutorials

Uploaded by

unisamodules5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views28 pages

CPT3701 LU Introduction

Thermodynamics Lectures. University Tutorials

Uploaded by

unisamodules5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to Computational

Techniques: Octave

Dr Mandla Mahlobo

S Department of Chemical and Materials Engineering,


School of Engineering,

College of Science, Engineering and Technology


University of South Africa

21 August 2024
Assessment Dates
1. Minor Test 1 - Assessment 1
• Feedback out
2. Major Test 1: Re-write – Assessment 2
• 10 September 2024 – Date confirmed!
3. Minor Test 2 - Assessment 3
• Due - 25 August 2024
4. Major Test 2 - Assessment 4
• New date to be generated!
5. Re-Test – Assessment 5
• 30 October 2024?? - New date to be generated!
Unit 1: Learning Outcomes

▪ Solve linear and nonlinear problems using numerical methods


▪ Comprehend interface, anatomy and basic language of Octave software
▪ Execute basic commands in Octave software
▪ Create, save and run a script in Octave software
Analytical methods vs Numerical methods
▪ Scientific and engineering problems are mostly solved via mathematical approaches.
▪ Mathematical approaches are either analytical or numerical.
▪ Analytical methods vs Numerical methods?
▪ Consider:

𝑓 𝑥 =𝑥+3

Analytical method?

𝑓 𝑥 =0
Thus:
𝑥+3=0
𝑥 = −3

Now, consider:

Fig. 1: Summary of differential equations, Linear vs Nonlinear


Linear Systems vs Nonlinear Systems
▪ Linear systems vs Nonlinear systems:

https://www.acs.psu.edu/drussell/Demos/Pendulum/Pendulum.html

Fig. 1: Linear systems vs Nonlinear systems.


Numerical Tools: Octave Software
Download Octave:

GNU Octave

Install and run Octave


Numerical Tools: Octave Software (Cont.)
Introduction to Octave Software
Octave Exercises:
Introduction to Octave Software (Cont.)

Creating a script on Octave:

▪ Consider a solids mixer which mixes three components, i.e. x, y and z,


▪ Each time the components are mixed, the total mass of the mixture must be determined,
▪ Because it is a non-ideal mixing process, the mass values can be tedious to determined,
▪ You are tasked with creating numerical programme for calculating the total mass, everyday,
▪ You have the Octave software at your disposal to execute this,
▪ The idea is to minimize the workload of punching numbers on the calculator,
▪ Also, to eliminate the human error in calculating, daily, the mass of the mixture.
Introduction to Octave Software (Cont.)
Creating a script on Octave:
Thank You!
Unit 2: Learning Outcomes

▪ Use basic mathematical functions in Octave


▪ Use predefined constants and complex numbers in Octave
▪ Define a matrix
▪ Use Octave functions to generate matrices
▪ Perform basic matrix operations
▪ Perform element-wise operations in Octave
▪ Compute inverse and identity matrices in Octave
▪ Determine if a matrix is a square matrix using Octave
▪ Calculate the roots for a set of linear equations using Octave
Recap!!!
What we know about Octave so far:
▪ Recognize the interface, anatomy and language of Octave:
❑ Download and install Octave software,
❑ Navigate throughout the Octave window and various tabs,
▪ Execute basic commands in Octave:
❑ Perform simple calculations,
❑ Create new and multiple scripts,
❑ Execute various sequences,
▪ Documentation and help available for further exploration of Octave.

Let’s Recall!
Mathematical Expressions in Octave
Octave fully understands Mathematical language, this includes:
▪ Octave will therefore execute mathematical equations expressed by common mathematical
symbols.
Mathematical Expressions in Octave (Cont.)
What about Scientific Notation? Off course!
Predefined Constants and Complex Numbers
The following well known constants are predefined in the Octave software:
▪ 𝜋 (𝑝𝑖)
▪ Euler’s number (𝑒)
▪ Imaginary numbers (𝑖 and 𝑗)
▪ Infinity (𝑖𝑛𝑓)
▪ Not a Number (𝑁𝑎𝑁), e.g., 𝑖𝑛𝑓/𝑖𝑛𝑓,
Mathematical Functions
What other common mathematical symbols and/or functions does Octave understand:
▪ Absolute value: 𝑎𝑏𝑠( ),
▪ Logarithm: log , log(10),
▪ Trigonometric functions: sin , cos , tan( ), in radians,
▪ Inverse trigonometric functions: asin , acos( ) , atan( ),
▪ Square root: 𝑠𝑞𝑟𝑡 ( ),
▪ Exponential: exp ( ),
Mathematical Functions (Cont.)
Exercises:
Mathematical Functions (Cont.)
Can you personalize your own constants of functions in Octave? Yup!!
Arrays and Matrices
What is an Array?
▪ Octave also recognizes a set of organized multiple variables, known as an Array,
▪ Can exist in the form of integers, floating point numbers, complex numbers, etc.

What is a Matrix?
▪ An array of numbers enclosed in square brackets, i.e., [ ],

Matrix dimensions:
▪ Rows are separated by semi-colons (;),
▪ In a single row, each entry is separated by a comma (,) or space (bar),

We then define:
▪ Row vector = 1 × 𝑛 ,
▪ Column vector = 𝑛 × 1,
▪ From the above definitions, we can get the size of the matrix.
Vector and Matrix Creation

Let’s create a row vector:


▪ Type the numbers on Octave, each separated by a comma (,),

Now, let’s create a column vector:


▪ Type the numbers on Octave, use a transpose sign (‘) or a
semi-colon (;) to separate the entries,
Vector and Matrix Creation (Cont.)
Now, a matrix with multiple rows and columns?

How about adding or subtracting a defined matrix from another one?


▪ Let the first one be “a” and the second one be “b”,

▪ Multiply or divide a matrix?


Vector and Matrix Creation (Cont.)
Exercise:
Vector and Matrix Creation (Cont.)
Exercise (Cont.):
Vector and Matrix Creation Functions
Let’s build and manipulate matrices by using special functions:
▪ Analogous to mathematical functions discussed earlier (trigonometric, logarithm functions, etc.)
Vector and Matrix Creation Functions (Cont.)
Exercise:
Vector and Matrix Creation Functions (Cont.)
Solution:
Thank You!

You might also like