Laporan Praktikum Pemrograman Komputer: Modul: 1
Laporan Praktikum Pemrograman Komputer: Modul: 1
Laporan Praktikum Pemrograman Komputer: Modul: 1
Oleh:
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
A function is defined in an text file, just like a script, except that the first line
of the file has the following form:
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)
s = sin(x*pi/180);
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
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
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.