Difference between revisions of "Samuel Albert Sitompul"

From ccitonlinewiki
Jump to: navigation, search
(KUIS)
 
(Blanked the page)
Line 1: Line 1:
== KUIS ==
 
  
=== Problem set 2.1 Nomor 6 halaman 55 ===
 
 
Pada soal ini matrix yang diberikan soal adalah sebagai berikut,
 
 
A = [[0, 0, 2, 1, 2], [0, 1, 0, 2, -1], [1, 2, 0, -2, 0], [0, 0, 0, -1, 1], [0, 1, -1, 1, -1]]
 
 
B = [1, 1, -4, -2, -1]
 
 
sebelum memasuki eliminasi gauss, matrix tersebut harus dikonfigurasi ulang agar bisa dihitung,
 
 
konfigurasi matrix,
 
 
A = [[1, 2, 0, -2, 0], [0, 1, 0, 2, -1],[0, 1, -1, 1, -1], [0, 0, 0, -1, 1], [0, 0, 2, 1, 2]]
 
 
B = [-4, 1, -1, -2, 1]
 
 
maka hasil yang akan didapatkan adalah,
 
 
X1 = 2
 
 
X2 = -2
 
 
X3 = 1
 
 
X4 = 1
 
 
X5 = -1
 
 
==== kode python ====
 
 
import numpy as np
 
 
A=np.array([[1, 2, 0, -2, 0], [0, 1, 0, 2, -1],[0, 1, -1, 1, -1], [0, 0, 0, -1, 1], [0, 0, 2, 1, 2]],float)
 
 
B=np.array([-4, 1, -1, -2, 1],float)
 
 
n=len(A)
 
 
for k in range (0,n-1):
 
for i in range (k+1, n):
 
if A[i,k]!=0 :
 
lam= A[i,k]/A[k,k]
 
A[i,k:n]= A[i, k:n]-(A[k,k:n]*lam)
 
B[i]=B[i]-(B[k]*lam)
 
print ('matrix A:', '\n', A)
 
x=np.zeros(n,float)
 
for m in range (n-1, -1, -1):
 
x[m]=(B[m]-np.dot(A[m, m+1:n], x[m+1:n]))/A[m,m]
 
print ('nilai X', m+1, '=', x[m])
 

Revision as of 14:13, 14 October 2019