Laporan Praktikum Pemrograman Komputer: Modul: 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

LAPORAN

PRAKTIKUM PEMROGRAMAN KOMPUTER


Modul : 1
INTRODUCTION TO OCTAVE
Hari : Senin Tanggal : 12 Agustus 2019 Jam: 13.00 - 14.40

Oleh:

Andi Bagus Rahmawan (081711733013)

Dosen Pembimbing : Erwin Sutanto S.T., M.Sc

PROGRAM STUDI S1 TEKNIK BIOMEDIS


FAKULTAS SAINS DAN TEKNOLOGI
UNVERSITAS AIRLANGGA
2019
A. Judul
Introduction To Octave

B. Tujuan
Untuk mengenali fitur – fitur pada program GNU Octave.

C. Dasar Teori
Octave is an open-source interactive software system for numerical
computations and graphics. Octave can display data in a variety of different
ways, and it also has its own programming language which allows the system
to be extended.

GETTING HELP
If you are not sure what a particular Octave command does, or want to find a
particular function, Octave contains an integrated help system. The basic form
of using help is to type : help commandname.

NAMED VARIABLES
In any significant calculation you are going to want to store your answers, or
reuse values, just like using the memory on a calculator. Octave allows you to
define and use named variables.

VECTOR
There are lots of ways of defining vectors and matrices. Usually the easiest
thing to do is to type the vector inside square brackets [].

PLOTTING GRAPHS
Octave has powerful facilities for plotting graphs as an open-source program.
however some of the range of plotting options are restricted compared with
MATLAB The basic command is plot(x,y), where x and y are the co-ordinates.

CONTROL STATEMENTS
Thus far the programs and expressions that we have seen have contained
simple, sequential operations. The use of vectors (and later matrices) enable
some more sophisticated computations to be performed using simple
expressions, but to proceed further we need some more of the standard
programming constructs. Octave supports the usual loops and selection
facilities.
For loops.
The programming construct you are likely to use the most is the for loop,
which repeats a section of code a number of times, stepping through a set of
values. In Octave you should try to use vector arithmetic rather than a for loop,
if possible, since a for loop is about 40 times slower. However, there are times
when a for loop is unavoidable. The syntax is :
for variable = vector
statements

end

FUNCTION AND MODULES


Basically, functions in Octave are passed numbers, perform some c
alculations, and give you back some other numbers.

A function is defined in an text file, just like a script, except that the first line
of the file has the following form:

Function [output1,output2,...] = name(input1,input2,...)

When doing Octave calculations you could just always convert your angle d to
radians using sin(d/180*pi), or even using the variable deg as defined in
Section 3.1, writing sin(d*deg). But it would be simpler and more readable if
you could just type sind(d) (‘sine in degrees’), and we can create a function to
do this. Such a function would be defined by creating a file sind.m containing
just the following lines:

function s = sind(x)

%SIND(X) Calculates sine(x) in degrees

s = sin(x*pi/180);

BASIC MATRIX FUNCTIONS


Octave allows all of the usual arithmetic to be performed on matrices. Matrix
multiplication has already been discussed, and the other common operation
is to add or subtract two matrices of the same size and shape.
eye : Create an identity matrix
zeros : Create a matrix of zeros
ones : Create a matrix of ones
rand : Create a matrix filled with random numbers
diag : Create a diagonal matrix, or extract the diagonal of the given
matrix
Inv : Inverse of a matrix
det : Determinant of a matrix trace Trace of a matrix
eig : Calculate the eigenvectors and eigenvalues of a matrix
rank : Calculate an estimate of the rank of a matrix
null : Calculate a basis for the null space of a matrix
rref : Perform Gaussian elimination on an augmented matrix.
lu : Calculate the LU decomposition of a matrix
qr : Calculate the QR decomposition of a matrix
svd : Calculate the SVD of a matrix
pinv : Calculate the pseudoinverse of a matrix

COMPLEX NUMBERS
Apart from matrix and vector computations, Octave also supports many
other mathematical and engineering concepts, and among these are complex
numbers. Complex numbers can be typed into Octave exactly as written, for
example

octave:##> z1=4-3i z1 = 4 - 3i

Alternatively, both i and j are initialised by Octave to be √−1 and so (if


you’ve not redefined them) you can also type

octave:##> z2 = 1 + 3*j z2 = 1 + 3i

You can perform all the usual arithmetic operations on the complex
numbers, exactly as for real numbers:

octave:##>z2-z1
ans = -3 + 6i
octave:##>z1+z2
ans=5
octave:##>z2/z1
ans = -0.20000 + 0.60000
octave:##> z1^2
ans= 7-24i

D. Tugas
1. Display the even number from zero to 100 and calculate the sum of it!
2. Calculate the value of 10! (10 factorial)!

E. Pembahasan
a. Analisis Masalah
Pada tugas yang pertama diharuskan untuk menampilkan angka
– angka yang tergolong pada angka genap kemudian dari angka – angka
genap yang tersusun dari 0 sampai 100 dijumlahkan sehingga
membutuhkan sum. Selanjutnya untuk tugas dua diharuskan untuk
mengkalkulasi atau memunculkan hasil dari 10! (10 faktorial)

b. Flowchart
• Flowchart even number from zero to 100
• Flowchart factorial :
c. Program
• Program yang menampilkan bilangan genap dari 0 - 100

• Calculate the value of 10!


d. Analisis Program
Pada tugas pertama hal yang patut digarisbawahi adalah
pengulangan, maka dari itu utuk menampilkan angka genap yang terdiri
dari 0 sampai 100 dibutuhkan looping. Dalam memunculkan angka-
angka dari interval 1 sampai 100 dapat menggunakan x=1:100
sedangkan untuk looping bisa menggunakan
EvenNumber=rem(x,2)==0. Untuk menampilkan angka-angka genap
dapat menggunakan if mod(i,2)==0. Dalam percobaan ini angka-angka
genap yang muncul dari interval 1 sampai 100 dijumlahkan, sehingga
untuk penjumlahannya dapat menggunakan sum=sum dengan sum
awalnya yakni sum=sum+i. Selanjutnya pada tugas yang kedua adalah
penjumlahan factorial yaitu 10!. Dalam hal ini factorial=i karena nilai
yang dicari adalah 10! Maka interval i=1-10 sementara untuk looping
menggunakan factorial=factorial*i.

F. Kesimpulan
Setelah melakukan praktikum atau percobaan yang pertama ini
dapat ditarik kesimpulan bahwa Octave adalah program atau software yang
dipakai untuk analisis numerik dan kemampuannya setara dengan Matlab.
Kelebihan utama dari Octave dan yang membedakan dengan Matlab yaitu
Octave gratis (freeware) dan tersedia untuk berbagai sistem operasi seperti
Windows 98/2000/XP, Mac OS/X, Debian, Suse, Fedora, RedHat Linux.
Kelebihan lain dari Octave yaitu dalamnya telah terpasang sejumlah besar
fungsi-fungsi matematika dan algoritma-algoritma metode numerik.

G. Daftar Pustaka
Houcque, David. 2005. “Introduction To MATLAB For
Engineering Students. Illinois : Northwestern University.
Long, P.J.G. 2005. “Introduction To Octave”. Cambridge :
Departement Of Engineering University of Cambridge.

You might also like