Anda di halaman 1dari 9

Luthfi Arfiansyah

Aplikasi
2213106048
Penyelesaian
Numerik
Permasalahan
Optimasi Tanpa
Kendala Metode
Penyelidikan Operasi
Golden Section
Menggunakan Bahasa Visual
Basic

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Algoritma Program:

Metode Golden Section Menggunakan Visual Basic | 1

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Metode Golden Section Menggunakan Visual Basic | 2

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Realisasi Tampilan Program:


Saat Baru dijalankan

Setelah dilakukan proses kalkulasi

Metode Golden Section Menggunakan Visual Basic | 3

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Metode Golden Section Menggunakan Visual Basic | 4

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Kode Program dalam Visual Basic ( menggunakan Visual Studio Ultimate 2012):
Public Class Form1
' deklarasi konstanta p
Const P As Decimal = 0.6180339887
' deklarasi variabel
Dim R As Decimal
Dim S As Decimal
Dim T As Decimal
Dim l As Decimal
Dim a As Decimal
Dim b As Decimal
Dim x1 As Decimal
Dim x2 As Decimal
Dim fx1 As Decimal
Dim fx2 As Decimal
Dim Epsilon As Decimal
Dim iterasi As Integer
Dim xbintang As Decimal
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Start.Click
'mengosongkan text box
textap.Text = ""
TextBp.Text = ""
TextL.Text = ""
TextX1.Text = ""
TextX2.Text = ""
TextFX1.Text = ""
TextFX2.Text = ""
'membaca input user
a = inputap.Text
b = inputbp.Text
Epsilon = inputE.Text
R = InputA.Text
S = InputB.Text
T = InputC.Text
'apabila a >b
If a > b Then
MsgBox("Input salah! a harus lebih kecil dari b", 64, "Warning")
GoTo break
End If
'kalkulasi pertama
iterasi = 1
l=b-a
x1 = a + ((1 - P) * l)
x2 = a + (P * l)
'loop program hingga l < epsilon
Do
'Print data kedalam text box
textap.Text = textap.Text & iterasi & (". ") & FormatNumber(a, 4) & vbNewLine
TextBp.Text = TextBp.Text & iterasi & (". ") & FormatNumber(b, 4) & vbNewLine
TextL.Text = TextL.Text & iterasi & (". ") & FormatNumber(l, 4) & vbNewLine
TextX1.Text = TextX1.Text & iterasi & (". ") & FormatNumber(x1, 4) & vbNewLine
TextX2.Text = TextX2.Text & iterasi & (". ") & FormatNumber(x2, 4) & vbNewLine
TextFX1.Text = TextFX1.Text & iterasi & (". ") & FormatNumber(fx1, 4) & vbNewLine
TextFX2.Text = TextFX2.Text & iterasi & (". ") & FormatNumber(fx2, 4) & vbNewLine
fx1 = (R * (x1 ^ 2)) + (S * x1) + T
fx2 = (R * (x2 ^ 2)) + (S * x2) + T

Metode Golden Section Menggunakan Visual Basic | 5

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi


If fx1 >= fx2 Then
a = x1
x1 = x2
l=P*l
x2 = a + (P * l)
Else
b = x2
x2 = x1
l=P*l
x1 = a + ((1 - P) * l)
End If
iterasi = iterasi + 1
Loop Until l <= Epsilon
'print data terakhir kedalam text box
textap.Text = textap.Text & iterasi & (". ") & FormatNumber(a, 4) & vbNewLine
TextBp.Text = TextBp.Text & iterasi & (". ") & FormatNumber(b, 4) & vbNewLine
TextL.Text = TextL.Text & iterasi & (". ") & FormatNumber(l, 4) & vbNewLine
TextX1.Text = TextX1.Text & iterasi & (". ") & FormatNumber(x1, 4) & vbNewLine
TextX2.Text = TextX2.Text & iterasi & (". ") & FormatNumber(x2, 4) & vbNewLine
TextFX1.Text = TextFX1.Text & iterasi & (". ") & FormatNumber(fx1, 4) & vbNewLine
TextFX2.Text = TextFX2.Text & iterasi & (". ") & FormatNumber(fx2, 4) & vbNewLine
'kalkulasi x* dan print x* dan jumlah iterasi
xbintang = (a + b) / 2
Xbin.Text = FormatNumber(xbintang, 4)
LabelIterasi.Text = iterasi
GroupBox1.Visible = True
break:
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Quit.Click
'keluar dari program
End
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox11_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles
InputA.TextChanged
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs)
End Sub
Private Sub TextIterasi_TextChanged(sender As Object, e As EventArgs)
End Sub

Metode Golden Section Menggunakan Visual Basic | 6

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi


Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)
End Sub
Private Sub VScrollBar8_Scroll(sender As Object, e As ScrollEventArgs)
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As
DataGridViewCellEventArgs)
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs)
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub DataGridView1_CellContentClick_1(sender As Object, e As
DataGridViewCellEventArgs)
End Sub
Private Sub Xbin_Click(sender As Object, e As EventArgs) Handles Xbin.Click
End Sub
Private Sub TextFX2_TextChanged(sender As Object, e As EventArgs) Handles
TextFX2.TextChanged
End Sub
Private Sub TextFX1_TextChanged(sender As Object, e As EventArgs) Handles
TextFX1.TextChanged
End Sub
Private Sub TextX2_TextChanged(sender As Object, e As EventArgs) Handles
TextX2.TextChanged
End Sub
Private Sub TextX1_TextChanged(sender As Object, e As EventArgs) Handles
TextX1.TextChanged
End Sub
Private Sub TextL_TextChanged(sender As Object, e As EventArgs) Handles
TextL.TextChanged
End Sub
Private Sub TextBp_TextChanged(sender As Object, e As EventArgs) Handles
TextBp.TextChanged
End Sub

Metode Golden Section Menggunakan Visual Basic | 7

Luthfi Arfiansyah / 2213106048 / Penyelidikan Operasi

Private Sub Reset_Click(sender As Object, e As EventArgs) Handles Reset.Click


'reset semua text box dan input
textap.Text = Nothing
TextBp.Text = Nothing
TextL.Text = Nothing
TextX1.Text = Nothing
TextX2.Text = Nothing
TextFX1.Text = Nothing
TextFX2.Text = Nothing
Xbin.Text = Nothing
inputap.Text = 0
inputbp.Text = 0
inputE.Text = 0
InputA.Text = 0
InputB.Text = 0
InputC.Text = 0
MsgBox("Terhapus! ", 64, "Reset")
GroupBox1.Visible = False
End Sub
Private Sub textap_TextChanged(sender As Object, e As EventArgs) Handles
textap.TextChanged
End Sub
End Class

Metode Golden Section Menggunakan Visual Basic | 8

Anda mungkin juga menyukai