Introduction to GNU-Octave

Similar documents
This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

A very brief Matlab introduction

A. Matrix-wise and element-wise operations

LAB 1 General MATLAB Information 1

Finding, Starting and Using Matlab

Part IB Computing Course Tutorial Guide to MATLAB

Arithmetic and Logic Blocks

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Consider this m file that creates a file that you can load data into called rain.txt

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Introduction to MATLAB for CSE390

Lecture 1: What is MATLAB?

A General Introduction to Matlab

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Lecturer: Keyvan Dehmamy

Some elements for Matlab programming

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Script started on Thu 25 Aug :00:40 PM CDT

Introduction to MATLAB

Introduction to MATLAB Practical 1

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Chapter 1 MATLAB Preliminaries

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

A Brief Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

A very short introduction to Matlab and Octave

General MATLAB Information 1

Dr Richard Greenaway

Introduction to MATLAB

Introduction to Matlab

A Guide to Using Some Basic MATLAB Functions

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

GRAPH 4.4. Megha K. Raman APRIL 22, 2015

Laboratory 1 Octave Tutorial

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Math 2250 MATLAB TUTORIAL Fall 2005

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Introduction to Matlab

Introduction to MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

A QUICK INTRODUCTION TO MATLAB

Ebooks Chemical Engineering

Matlab Workshop I. Niloufer Mackey and Lixin Shen

MATLAB and Numerical Analysis

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Basic types and definitions. Chapter 3 of Thompson

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

How to learn MATLAB? Some predefined variables

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Basic MATLAB Tutorial

Mechanical Engineering Department Second Year (2015)

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to Engineering gii

MATLAB Functions and Graphics

Introduction to Matlab

Introduction to MATLAB

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Subprograms. FORTRAN 77 Chapter 5. Subprograms. Subprograms. Subprograms. Function Subprograms 1/5/2014. Satish Chandra.

Fundamentals of MATLAB Usage

Built-in Types of Data

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Stokes Modelling Workshop

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

Introduction to MATLAB

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes.

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Introduction to MatLab. Introduction to MatLab K. Craig 1

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

AMS 27L LAB #2 Winter 2009

Matlab Tutorial, CDS

Single row numeric functions

MATLAB: a Brief Introduction. by Robert L. Rankin

6.094 Introduction to MATLAB January (IAP) 2009

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

An Introductory Tutorial on Matlab

Computational Physics

Statistical Data Analysis: Python Tutorial

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

Introduction to MATLAB

1 Introduction to Matlab

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

The value of f(t) at t = 0 is the first element of the vector and is obtained by

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

Appendix A: MATLAB Basics

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Matlab Programming Introduction 1 2

Computer Programming in MATLAB

AN INTRODUCTION TO MATLAB

Fixed point algorithmic math package user s guide By David Bishop

MATLAB. Input/Output. CS101 lec

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Introduction to MATLAB Programming

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Transcription:

Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016 KR Chowdhary GNU-Octave 1/ 22

What is Octave? Open source interactive software tool for numerical computations and graphics Solving Simultaneous equations, computing Eigen-vectors and Eigen-values Data can be expressed in matrix and vectors Has its own programming language More suited for Engineering problem solution, & equivalent to Matlab Most of the functionality of MATLAB already exists in GNU Octave and octave can run most MATLAB scripts More efficient than C++ or other HLLS Has GUI as well command-line interface Is interpreted language dynamically typed KR Chowdhary GNU-Octave 2/ 22

MATLAb vs GNU Octave GNU Octave is mostly compatible with MATLAB. However, Octave s parser allows some (often very useful) syntax that MATLAB s does not, so programs written for Octave might not run in MATLAB. Octave supports the use of both single and double quotes. MATLAB only supports single quotes Octave supports C-style autoincrement and assignment operators, MATLAB does not: i++; ++i; i+=1; etc. Octave supports temporary expressions: columns = size(mtx)(2); tmp = size(mtx) Install on linux: sudo apt-get install octave Available on windows, Linux, mac KR Chowdhary GNU-Octave 3/ 22

Installing octave with GUI for Ubuntu 16.04 Method 1 - Using PPA: sudo apt-add-repository ppa:octave/stable sudo apt-get update sudo apt-get install octave method 2 - Compiling the source yourself: sudo apt-get build-dep octave wget ftp://ftp.gnu.org/gnu/octave/octave-4.0.0.tar.gz tar xf octave-4.0.0.tar.gz cd octave-4.0.0/./configure make sudo make install More tools of octve can be installed by "$ synaptic" command at pronmpt or through menu. KR Chowdhary GNU-Octave 4/ 22

Simple Commands >> 2+2 ans=4 >> exp(1) ans=2.7183 >> 1.2*sin(40*pi/180+log(2.4^2)) ans=0.76618 >> who ans >> format long >> ans ans=0.766177651029692 >> format short >> ans =0.76618 KR Chowdhary GNU-Octave 5/ 22

functions cos: Cosine of an angle (in radians) sin: Sine of an angle (in radians) tan: Tangent of an angle (in radians) exp: Exponential function (ex ) log: Natural logarithm (NB this is loge, not log10 )cos log10: Logarithm to base 10 sinh: Hyperbolic sine cosh: Hyperbolic cosine tahh: Hyperbolic tangent acos: Inverse cosine acosh: Inverse hyperbolic cosine KR Chowdhary GNU-Octave 6/ 22

functions asin: Inverse sine asinh: Inverse hyperbolic sine atan: Inverse tangent atan2: Two-argument form of inverse tangent atanh: Inverse hyperbolic tangent abs: Absolute value sign: Sign of the number (-1 or +1) round: Round to the nearest integer floor: Round down (towards minus infinity) ceil: Round up (towards plus infinity) fix: Round towards zero rem: Remainder after integer division KR Chowdhary GNU-Octave 7/ 22

Simple Commands Loading and saving data files: >> save anyname (saves to anyname.mat, in current directory) Later on it can be retrieved by: >> load anyname >> help sqrt >> a=[1 4 5] a = 1 4 5 s= "hello world!" s= Hello world! KR Chowdhary GNU-Octave 8/ 22

Simple Commands >> b=[2, 1, 0]; # vector b= 2 1 0 >> c= [1 4; 3 10]; # matrix c = 1 4 3 10 >> inv(c) -2.0 1.0 1.5-0.5 >> e = 2:6 e=2 3 4 5 6 >> e=2:0.3:4 e=2.000 2.300... 3.800 KR Chowdhary GNU-Octave 9/ 22

Simple Commands >> a=[1:2:6-1 0] a=1 3 5-1 0 >>a(3) ans= 5 >> a(3:5) 5-1 0 >> a*2 2 6 10-2 0 >> b=[1 2 3 4 5 6] b= 1 2 3 4 5 6 >> a.^2 ans=1 9 25 1 0 >> b.^2 ans=1 4 9 16 25 36 KR Chowdhary GNU-Octave 10/ 22

Control structure #If statement: if.m vector = [ 1 2 3 4 5]; if length(vector) < 4 vector(4) = 0; else vector(4) end #Loops: for.m for i = 1:10 i; endfor #loop: while.m while i <= 10 i++; endwhile KR Chowdhary GNU-Octave 11/ 22

The transpose operator >> A A = 5 7-1 3 9-2 >> A ans = 5 3 7 9-1 -2 >> I = eye(4) I = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 KR Chowdhary GNU-Octave 12/ 22

Matrices and vectors >> A=[5 7 9-1 3-2] A = 5 7 9-1 3-2 >> B=[2 0; 0-1; 1 0] B= 2 0 0-1 1 0 >> C = [1:3; 8:-2:4] C = 1 2 3 8 6 4 Matrix multiplication >> A*B ans = 19-7 -4-3 >>B*C ans = 2 4 6-8 -6-4 1 2 3 KR Chowdhary GNU-Octave 13/ 22

Solving simultaneous linear equations let x1=1, x2=2, x3=-1, x4=-2, so x1 + 2x2 - x3 + x4 = 4 2x1 + x2 + 3x3 - x4 = 3 3x1 - x2 + 2x3 + 2x4 = -5 -x1 - x2 + 3x3 + x4 = -8 A =[1 2-1 1; 2 1 3-1; 3-1 2 2; -1-1 3 1]; b =[4; 3; -5; -8]; x= A \ b x = 1.0000 2.0000-1.0000-2.0000 KR Chowdhary GNU-Octave 14/ 22

Plotting a graph >> x=[0:pi/3:2*pi] x=0.0000... 6.28319 >> y=sin(x) y=0.0000... 0.86603...-0.0000 Plot the Graph by command: >> plot(x, y) The graph displayed can be saved though gui menu or by command: >> print( graph1.eps, -deps ) This program is plotprog.m KR Chowdhary GNU-Octave 15/ 22

Plotting graphs Thse plots more accurate graph: accuplot.m >> x=linspace(0, 2*pi, 1000); >> y = sin(x); >> plot(x, y); Improving the presentation: >> title( Graph of y = sin(x) ) >> xlabel( Angles ) >> ylabel( value ) >> grid on Clear graph by >> clf Multiple graphs can be created by: >> plot(x, y, :, x, cos(x), - ) KR Chowdhary GNU-Octave 16/ 22

A rectified sine wave >> edit using editor and save as rectsin.m t = linspace(0, 10, 100); y = abs(sin(t)); plot(t,y); title( Rectified Sine Wave ); xlabel( t ); can also run by command >> rectsin<cr> KR Chowdhary GNU-Octave 17/ 22

Control structures if expression statements elseif expression statements else statements end >> a=0; b=2; >> if a > b c=3 else c=4 end c = 4 >> 1 == 2 ans=0 KR Chowdhary GNU-Octave 18/ 22

Control structures switch x case x1, statements case x2, statements otherwise, statements end >> a=1; >> switch a case 0 disp( a is zero ); case 1 disp( a is one ); otherwise disp( a is not a binary digit ); end a is one KR Chowdhary GNU-Octave 19/ 22

Control structures for variable = vector statements end >> for n=1:5 nf(n) = factorial(n); end >> disp(nf) 1 2 6 24 120 while expression statements end For example, >> x=1; >> while 1+x > 1 x = x/2; end >> x x = 1.1102e-016 # smallest no. KR Chowdhary GNU-Octave 20/ 22

Putting several graphs in one window subplot(rows, columns, select): >> x = linspace(-10, 10); >> subplot(2,1,1) % Specify two rows, one column, and select >> % the top one as the current graph >> plot(x, sin(x)); >> subplot(2,1,2); >> plot(x, sin(x)./x); 3D plots: 1>> t = 0:pi/50:10*pi; >> x = sin(t); y = cos(t); z = t; >> plot3(x, y, z); KR Chowdhary GNU-Octave 21/ 22

Putting surfaces >> x = 2:0.2:4; % Define the x- and y- coordinates >> y = 1:0.2:3; % of the grid lines >> [X,Y] = meshgrid(x, y); %Make the grid For example, to plot f(x, y)=(x-3)^2-(y-2)^2 over the grid calculated earlier, you would type: >> Z=(X-3).^2 - (Y-2).^2; >> surf(x,y,z) KR Chowdhary GNU-Octave 22/ 22