2a GNU Octave Online Compiler Refresher Tutorial
2a GNU Octave Online Compiler Refresher Tutorial
REFRESHER / TUTORIAL
CE 007 | Numerical Solutions on CE Problems
Why GNU Octave?
▪ MATLAB is a very useful tool ▪ You can access it using:
for all fields of engineering. https://octave online.net/
▪ GNU Octave works like
▪ If you know how to code in one
MATLAB. language, you can easily learn
▪ But GNU Octave is free! other languages.
Output
Script
Command Line
GNU Octave as a Calculator
On the Command Line, calculate the following expressions:
2
3. ln + cos −1 0.5
3𝜋
log10 10
log 2 8
GNU Octave as a Calculator
If you wish to format the answer differently:
1, 2, 3, …, 8, 9, 10 >> 1:10
1, 4, 7, 10, …, 22 >> 1:3:22
3, 1, 4, 1, 5, 9, 2, 6, 5 >> [3 1 4 1 5 9 2 6 5]
1, 2, 3, 7, 6, 5, 4 >> [1:3 7:-1:4]
3 0 >> [3 0; 2 1]
2 1
Left-divide: Right-divide:
Operations on Vectors and Matrices
1 0 2 1 0 1
A= 3 9 6 B= 0 1 0 C= 1 4 7 D= 4 2 0
7 5 8 1 0 1
You can perform these operations on vectors and matrices.
Exponentiation
Element-wise: Scalar:
Operations on Vectors and Matrices
If there is an operation performed between a row vector and a
column vector, then implicit expansion occurs:
Example 1:
4
Let’s add A = 1 2 3 and B = 5
6
The function
linspace(a,b,N)
creates a row vector of N
numbers that starts with
a and ends with b.
Plotting
Create a 3D depth image of the surface defined by:
𝑓 𝑥, 𝑦 = 𝑥 exp − 𝑥 − 2𝑦 2 2 − 2.5𝑦 2
Conditional Statements
Write a script that checks if a value stored in variable ‘x’ is odd or
even.
Conditional Statements
Relational operators compare 2 elements and return whether
the relationship is true or false.