A Public MatLAB Compatible Interpreter: Octave - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

A Public MatLAB Compatible Interpreter: Octave

Description:

Octave is a public domain software which was developed for chemical reactor design essentially. ... Octave is run via its public interpreter which is mostly ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 27
Provided by: vedatd
Category:

less

Transcript and Presenter's Notes

Title: A Public MatLAB Compatible Interpreter: Octave


1
A Public MatLAB Compatible Interpreter Octave
  • Asst. Prof. Emin Korkut

2
Octave is a public domain software which was
developed for chemical reactor design
essentially. However the concern with this
software urged its creators to improve and
sophisticate it by giving many fundamental
properties of the licensed software MatLAB and C
programming language. Octave is run via its
public interpreter which is mostly available for
a lot of Unix based systems. Since the existence
of the compatibility with the MatLAB structure,
many MatLAB program can be run with Octave
without any appearable changes. Hence, Octave
means MatLAB up to some extent. Octave has dvi or
ps or pdf format documentation. The documentation
and the interpreter are available in the
Informatics Institute resources. Many Linux
system installs Octave by default. The SuSE
system used in the laboratories of the
Informatics Institute of Istanbul Technical
University present Octave.
3
30 different Octave scripts are presented. Their
outputs are also individually given after the
corresponding source code. The scripts are named
such that the last four letters are .oct . This
is not compulsory. You may give some other
extension like group of letters. The general
tendency is to use.m to get a compatibility with
MatLAB although we intend not to use it. The
scripts can be run by giving their names to
octave as follows octave lt prog1.oct gt
prog1.out This yields to take the commands from
the script prog1.oct and sends the output to the
file prog1.out. However, if the script has a !
starting line to address the interpreter then the
command must be as follows prog1.oct gt prog1.out
4
The content of the file prog1.oct printf("This is
my first Octave program") quit The content of
the file prog2.oct x12 x23 x3x1x2 printf("2
3 d\n", x3) printf("2 3 d\n", 23)
quit
5
The content of the file prog3.oct x135 x23.5 p
rintf("3 5 d\n", x1) printf("3 . 5
d\n", x2) x18-11 x28.-11 printf("8 11
d\n", x1) printf("8 . 11 d\n", x2)
x123/7 x223./7 printf("23 / 7 d\n", x1)
printf("23 ./ 7 d\n", x2) quit
6
  • You may give an arithmetic expression to be
    executed without an assignment. In that case the
    result of the operation is named ans and
    displayed with a statement starting with ans
  • 35
  • x35
  • printf("3 5 d\n", x)

7
The content of the file prog6.oct filestream1fope
n("prog06.out", "w") 35 x35 fprintf(filestream1
,"3 5 d\n", x) fclose(filestream1)
8
The content of the file prog7.oct x2.13458890324
5.324466651515 printf("2.13458890324
5.324466651515 f\n", x) x2.13458890324 .
5.324466651515 printf("2.13458890324 .
5.324466651515 f\n", x) x2.11115654245 -
6.786781313247 printf("2.11115654245 -
6.786781313247 f\n", x) x2.11115654245 .-
6.786781313247 printf("2.11115654245 .-
6.786781313247 f\n", x) x1.64534563569
9.5456123133309 printf("1.64534563569
9.5456123133309 f\n", x) x1.64534563569 .
9.5456123133309 printf("1.64534563569 .
9.5456123133309 f\n", x) x3.76786868434 /
4.56756712314338 printf("3.76786868434 /
4.56756712314338 f\n", x) x3.76786868434 ./
4.56756712314338 printf("3.76786868434 /
4.56756712314338 f\n", x)
9
This program is constructed to show the
arithmetical operations between the float type
numerical data. As can be seen there is no data
type declaration. Octave can understand and
decide whether the data under consideration is
numerical and float type. The results are
given within single float precision which
corresponds to approximately six or seven decimal
digits. This is controlled by the format
specifier f.
10
The content of the file prog8.oct format
specifier m.nf where the integer m denotes the
maximum number of decimal digits while n stands
for the number of the decimal digits.
x2.13458890324 5.324466651515 printf("2.13458
890324 5.324466651515 40.36f\n", x)
x2.13458890324 . 5.324466651515 printf("2.13458
890324 . 5.324466651515 40.36f\n", x)
x2.11115654245 - 6.786781313247
11
The content of the file prog9.oct Exponentiation
or raising to power facilities of Octave.
There are two equivalent symbol for the
exponentiation operation and .
x23 printf("23 d\n", x) x2.3 printf("2.
3 d\n", x) x23 printf("23 d\n",
x) x2.3 printf("2.3 d\n", x)
12
The content of the file prog10.oct x2.13 printf(
"2.13 20.15f\n", x) x23.7 printf("23.7
20.15f\n", x) x5.43.7 printf("5.43.7
20.15f\n", x) x0.03.7 printf("0.03.7
20.15f\n", x) x6.80.0 printf("6.80.0
20.15f\n", x) x0.00.0 printf("0.00.0
20.15f\n", x) x(-7.9)4.5 printf("(-7.9)4.5
20.15f\n", x)
13
The content of the file prog11.oct In this
program we deal with the functions which
convert a real or complex number to an
approximate integer number. We give examples for
ceiling the nearest greater integer floor
nearest smaller integer fix nearest integer
towards zero functions
14
xceil(1.289766) printf("ceil(1.289766) d\n",
x) xceil(-5.127656) printf("ceil(-5.127656)
d\n", x) zceil(5.67993.42554i) printf("ceil(5
.67993.42554i) d di\n",real(z),imag(z)) x
floor(1.289766) printf("floor(1.289766) d\n",
x) xfloor(-5.127656) printf("floor(-5.127656)
d\n", x) zfloor(5.67993.42554i) printf("flo
or(5.67993.42554i) d di\n",real(z),imag(z))
xfix(1.289766) printf("fix(1.289766) d\n",
x) xfix(-5.127656) printf("fix(-5.127656)
d\n", x) zfix(5.67993.42554i) printf("fix(5.6
7993.42554i) d di\n",real(z),imag(z))
15
The content of the file prog12.oct gcd the
greatest common divisor lcm the least common
multiple of their arguments xgcd(12,18,48,210)
printf("gcd(12,18,48,210) d\n",
x) xgcd(12,18,48,210) printf("gcd(12,18,48,2
10) d\n", x) xlcm(12,18,48,210) printf("lcm
(12,18,48,210) d\n", x) xlcm(12,18,48,210)
printf("lcm(12,18,48,210) d\n", x) quit
16
The content of the file prog13.oct xexp(1.000) p
rintf("exp(1.000) 20.16f\n",
x) xexp(-100.000) printf("exp(-100.000)
20.16f\n", x) xlog(1.0000) printf("log(1.0000)
20.16f\n", x) xlog(e) printf("log(e)
20.16f\n", x) xlog10(e) printf("log10(e)
20.16f\n", x) xlog10(10) printf("log10(10)
20.16f\n", x) xlog2(10) printf("log2(10)
20.16f\n", x) xlog2(2) printf("log2(2)
20.16f\n", x)
17
The content of the file prog14.oct xsin(pi) prin
tf("sin(pi) 20.16f\n", x) xcos(pi) printf("c
os(pi) 20.16f\n", x) xtan(pi) printf("tan(pi
) 20.16f\n", x) xcot(pi) printf("cot(pi)
20.16f\n", x) quit
18
The content of the file prog16.oct xsinh(10.0) p
rintf("sinh(10.0) 20.16f\n",
x) xcosh(10.0) printf("cosh(10.0)
20.16f\n", x) xcosh(1.0) printf("cosh(1.0)
20.16f\n", x) xcosh(0.0) printf("cosh(0.0)
20.16f\n", x)
19
The content of the file prog17.oct xasinh(10.0)
printf("asinh(10.0) 20.16f 20.16fi\n",
real(x), imag(x)) xacosh(10.0) printf("acosh(10
.0) 20.16f 20.16fi\n", real(x), imag(x))
20
The content of the file prog18.oct round the
closest integer value to its argument sign
returns 1, 0, and -1 values when its
arguments is positive, zero, and negative
respectively. rem the remainder of its given
arguments when the first argument is divided by
the second. When one of its arguments is a real
number, that argument is rounded to the nearest
integer, then the remainder is evaluated. This
function does not work with complex numbers abs
the absolute value of a given number either
integer or float.
21
xround(1.5432) printf("round(1.5432) d\n",
x) xround(-2.452) printf("round(-2.452)
d\n", x) xsign(4.85) printf("sign(4.85)
d\n", x) xsign(0.0) printf("sign(0.0)
d\n", x) xsign(-7.8904) printf("sign(-7.8904)
d\n", x) xrem(35,4) printf("rem(35,4)
d\n", x)
22
xrem(-23,7) printf("rem(-23,7) d\n",
x) xrem(23.7, 6.58) printf("rem(23.7,6.58)
d\n", x) xabs(-23.3452) printf("abs(-23.3452)
d\n", x) xabs(35.1221) printf("abs(35.1221)
d\n", x) xabs(34i) printf("abs(34i)
d\n", x) quit
23
The content of the file prog19.oct xsqrt(2.0) pr
intf("sqrt(2.0) 12.9f 12.9fi\n", real(x),
imag(x)) xsqrt(-25.0) printf("sqrt(-25.0)
12.9f 12.9fi\n", real(x), imag(x)) xsqrt(86
i) printf("sqrt(86i) 12.9f 12.9fi\n",
real(x), imag(x)) xmax(1,22,2,33,4.53,33.4) p
rintf("max(1,22,2,33,4.53,33.4)
12.9f\n",x) xmin(1,22,2,33,4.53,33.4) printf
("max(1,22,2,33,4.53,33.4) 12.9f\n",x) xeps
printf("Machine Epsilon 12.9E\n",x) xrealma
x printf("Greatest Real Number
12.9E\n",x) xrealmin printf("Least Real
Number 12.9E\n",x) quit
24
The content of the file prog20.oct A1,2,34,5,6
B1,4,58,9,10 CAB DA-B disp("The
matrix A \n") disp(A)disp("") disp("The
matrix B \n") disp(B)disp("") disp("The
matrix C A B \n") disp(C)disp("") disp("T
he matrix D A - B \n") disp(D)disp("") quit

25
A1,23,45,6 B1,4,5,78,9,10,11 CAB dis
p("The matrix A \n") disp(A)disp("") disp("Th
e matrix B \n") disp(B)disp("") disp("The
matrix C A B \n") disp(C)disp("") quit
26
A4,1,1,11,4,1,11,1,4,11,1,1,4 BA-1 CBA
DAB disp("The matrix A \n")
disp(A)disp("") disp("The matrix B A-1
\n") disp(B)disp("") disp("The matrix C
A-1A \n") disp(C)disp("") disp("The matrix
D AA-1 \n") disp(D)disp("") quit
Write a Comment
User Comments (0)
About PowerShow.com