Professional Documents
Culture Documents
Octave
Octave
to
Octave
Display Facilities
Using operators
Creating Plots
MANAV RACHNA UNIVERSITY
What is Octave?
Octave is basically a high level language which has many
specialized toolboxes for making things easier for us.
Octave is compatible with MATLAB.
Octave is free software
Octave provides a language and environment for
numerical computation, data analysis, visualisation and
algorithm development.
Structures
>> A=32
A=32
To find out the value of a variable simply type the
name in
>> A
A=32
original value
Example:
>> B=A
B= 32
>> A=15
A=15
>> B=32
MANAV RACHNA UNIVERSITY
Creating Octave variables
For Example:
>> A=10
A=10
>> A+A
ans = 20
>> B=A+A
B=20
available by typing
>> help Command
Another way to get help is to use the look for command.
MANAV RACHNA UNIVERSITY
Use on-line help to request info on a specific function
>> help sqrt
Tab completion
After typing few alphabet press tab to auto complete
it.
In the current version , the doc function opens the on-
line version of the help manual. This is very helpful
for more complex commands.
>> doc plot
0.8
0.6
0.2
>>plot(y) -0.2
-0.4
-0.6
-0.8
-1
0 10 20 30 40 50 60 70 80 90 100
For x label:
>> xlabel(‘x = 0:4*pi’)
For y label
0.8
0.6
0.4
0.2
Sin of x
-0.2
-0.4
-0.6
-0.8
-1
0 10 20 30 40 50 60 70 80 90 100
x = 0:4*pi
m Magenta s Square
y Yellow d Diamond
>> y = sin(x)
0.6
0.4
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7
0.5
>>plot(y2) 0.4
0.3
0.2
0.1
-0.1
-0.2
-0.3
0 10 20 30 40 50 60 70 80 90 100
legend
axis
xlabel
ylabel
>> hold on 1
>> xlabel(‘x’);
-1.5
>> ylabel(‘y’);
-2
0 1 2 3 4 5 6
>> hold off x
Warning: Imaginary 7
parts of complex X 5
and/or Y arguments
4
ignored 2
0
-2 0 2 4 6 8 10
Warning: Imaginary
8
6
parts of complex X 4
and/or Y arguments 0
ignored
-2
-4
-6
-10
-2 0 2 4 6 8 10
-2
-4
-6
-8
-10
-1 0 1 2 3 4 5 6 7 8 9 10
A(-2), A(0)
Error: ??? Subscript indices must either be real positive integers or logicals.
A(4,2)
Error: ??? Index exceeds matrix dimensions.
>>k =2:-0.5:-1
k=
2 1.5 1 0.5 0 -0.5 -1
x = ones(1,3)
x =
1 1 1
A = [ x y]
1 2 4 5
B = [x ; y]
1 2
4 5
C = [x y ;z]
Error:
??? Error using ==> vertcat CAT arguments dimensions are not consistent.
Given A and B:
.* element-by-element multiplication
./ element-by-element division
.^ element-by-element power
b = x .* y c=x./y d = x .^2
x = A(1,:) y = A(3 ,:)
b= c= d=
x= y= 3 8 -3 0.33 0.5 -3 1 4 9
1 2 3 3 4 -1
K= x^2
Erorr:
??? Error using ==> mpower Matrix must be square.
B=x*y
Erorr:
??? Error using ==> mtimes Inner matrix dimensions must agree.