Difference between revisions of "Yarynara Sebrio. S"
(→UTS) |
(→Tugas Metode Numerik) |
||
Line 18: | Line 18: | ||
== '''Tugas Metode Numerik''' == | == '''Tugas Metode Numerik''' == | ||
+ | ==Video Tugas Metode Numerik== | ||
+ | |||
+ | https://youtu.be/IY77XrCa_mY | ||
+ | |||
+ | https://youtu.be/45ka7X07Ikw | ||
+ | |||
==UTS== | ==UTS== | ||
1.A | 1.A |
Revision as of 21:31, 27 October 2019
Contents
Biografi
Nama : Yarynara Sebrio Suharyadi
TTL : Jakarta,23 September 1999
NPM : 1706070816
Jurusan : Teknik Mesin Paralel Universitas Indonesia
Hobi : Bermain Tenis lapangan
Di bagian pemograman python ini saya mempelajari cara mengerjakan operasi matematika yang sering digunakan untuk membuat simulasi di berbagai sistem seperti fisika,kimia,biologi , cara menyelesaikan matematika tersebut cukup sulit diperoleh karena persamaan disamping yang tidak efisien
Tugas Metode Numerik
Video Tugas Metode Numerik
UTS
1.A import numpy as np class GEPP():
def __init__(self, A, b, doPricing=True): #super(GEPP, self).__init__() self.A = A # input: A is an n x n numpy matrix self.b = b # b is an n x 1 numpy array self.doPricing = doPricing
self.n = None # n is the length of A self.x = None # x is the solution of Ax=b
self._validate_input() # method that validates input self._elimination() # method that conducts elimination self._backsub() # method that conducts back-substitution
def _validate_input(self): self.n = len(self.A) if self.b.size != self.n: raise ValueError("Invalid argument: incompatible sizes between" + "A & b.", self.b.size, self.n)
def _elimination(self): """ k represents the current pivot row. Since GE traverses the matrix in the upper right triangle, we also use k for indicating the k-th diagonal column index. :return """ # Elimination for k in range(self.n - 1): if self.doPricing: # Pivot maxindex = abs(self.A[k:, k]).argmax() + k if self.A[maxindex, k] == 0: raise ValueError("Matrix is singular.") # Swap if maxindex != k: self.Ak, maxindex = self.Amaxindex, k self.bk, maxindex = self.bmaxindex, k else: if self.A[k, k] == 0: raise ValueError("Pivot element is zero. Try setting doPricing to True.") # Eliminate for row in range(k + 1, self.n): multiplier = self.A[row, k] / self.A[k, k] self.A[row, k:] = self.A[row, k:] - multiplier * self.A[k, k:] self.b[row] = self.b[row] - multiplier * self.b[k]
def _backsub(self): # Back Substitution self.x = np.zeros(self.n) for k in range(self.n - 1, -1, -1): self.x[k] = (self.b[k] - np.dot(self.A[k, k + 1:], self.x[k + 1:])) / self.A[k, k]
def main():
A = np.array([[1., 0., 0., 0.], [-1., 1., 0., 0.], [0., 0., -1., 1.], [0., 0., 0., 1.]]) b = np.array([[50.], [20.], [5.], [10.]]) GaussElimPiv = GEPP(np.copy(A), np.copy(b), doPricing=False) print(GaussElimPiv.x) print(GaussElimPiv.A) print(GaussElimPiv.b) GaussElimPiv = GEPP(A, b) print(GaussElimPiv.x)
if __name__ == "__main__":
main()
1.B
- masukan plugin numpy
import numpy as np def diff_y (x,y): fungsi = x**2 - 4*y return (fungsi) #definisikan syarat perhitungan x=0 y=1 h=0.7 j=5 step_size = 0.5 step_size = -np.arange (0,0.5,h) for t in step_size: k1 = diff_y (x,y) k2 = diff_y ((x+0.5*h),(y+0.05*k1*h)) #simulasi hasil w1 = y + 1/3*(k1+2*k2) #cek kecepatan pada saat 0,7 detik print ('maka x(0.7) sama dengan', w1)
Quiz
Quiz nomor 1.
import numpy as np
class GEPP():
def __init__(self, A, b, doPricing=True):
#super(GEPP, self).__init__()
self.A = A # input: A is an n x n numpy matrix
self.b = b # b is an n x 1 numpy array
self.doPricing = doPricing
self.n = None # n is the length of A
self.x = None # x is the solution of Ax=b
self._validate_input() # method that validates input
self._elimination() # method that conducts elimination
self._backsub() # method that conducts back-substitution
def _validate_input(self):
self.n = len(self.A)
if self.b.size != self.n:
raise ValueError("Invalid argument: incompatible sizes between" +
"A & b.", self.b.size, self.n)
def _elimination(self):
# Elimination
for k in range(self.n - 1):
if self.doPricing:
# Pivot
maxindex = abs(self.A[k:, k]).argmax() + k
if self.A[maxindex, k] == 0:
raise ValueError("Matrix is singular.")
# Swap
if maxindex != k:
self.Ak, maxindex = self.Amaxindex, k
self.bk, maxindex = self.bmaxindex, k
else:
if self.A[k, k] == 0:
raise ValueError("Pivot element is zero. Try setting doPricing to True.")
# Eliminate
for row in range(k + 1, self.n):
multiplier = self.A[row, k] / self.A[k, k]
self.A[row, k:] = self.A[row, k:] - multiplier * self.A[k, k:]
self.b[row] = self.b[row] - multiplier * self.b[k]
def _backsub(self):
# Back Substitution
self.x = np.zeros(self.n)
for k in range(self.n - 1, -1, -1):
self.x[k] = (self.b[k] - np.dot(self.A[k, k + 1:], self.x[k + 1:])) / self.A[k, k]
def main():
A = np.array([[1., 2., 0., -2., 0.],
[0., 1., 0., 2., -1.],
[0., 0., 2., 1., 2.],
[0., 0., 0., -1., 1.],
[0., 1., -1., 1., -1.]])
b = np.array([[-4.],
[1.],
[1.],
[-2.],
[-1.]])
GaussElimPiv = GEPP(np.copy(A), np.copy(b), doPricing=False)
print(GaussElimPiv.x)
print(GaussElimPiv.A)
print(GaussElimPiv.b)
GaussElimPiv = GEPP(A, b)
print(GaussElimPiv.x)
if __name__ == "__main__":
main()
Quiz no.2
import numpy as np
def diff_y (x,y):
fungsi = x**2 - 4*y
returm (fungsi)
x=0
y=1
h=0,01
step_size=np.arrange (0,0,03,h)
for t in step_size:
k1=diff_y (x,y)
k2=diff_y ((x+0.5*h), (y+0,5*kl*h))
y=y+kl*h
print ('make y(0.03) adalah ',y)
Tugas 1
x1 = 0
dx1 = ('0.1')
dx = float (dx1)
x2 = x1+dx
Fx_1 = ((x2**2)-1) / (x1-1)
n = 1 error = 0
print ("n x F(x) error")
print (n," ",x1," ",Fx_1," ",error)
while x2<1 :
Fx_2 = ((x2**2)-1) / (x2-1)
error = ((Fx_2-Fx_1) / Fx_1)
Fx_1 = Fx_2
n = n+1
print (n," ",x1," ",Fx_1," ",error)
x2=x2+dx
Tugas 2
Tugas 3
Soal ini dikerjakan dengan menggunakan Hukum Kontinuitas Massa Definisi : massa yang masuk ke dalam sistem akan sama dengan massa yang keluar dari sistem
Rumus Q*p=Q*p
Karena terdapat 4 variabel, maka terdapat 4 persamaan
6C1 - 4C2 = 50
-2C1 - 1C3 + 4C4 = 50
7C2 - 3C3 - 4C4 = 0
-4C1 + 4C3 = 0
6C1 - 4C2 + 0C3 + 0C4 = 50
-2C1 + 0C2 - 1C3 + 4C4 = 50
0C1 + 7C2 - 3C3 - 4C4 = 0
-4C1 + 0C2 + 4C3 + 0C4 = 0
Dari model python akan didapatkan nilai
C1 = 275/9
C2 = 100/3
C3 = 275/9
C4 = 425/12
- python segera menyusul