Difference between revisions of "Samuel Albert Sitompul"
(→QUIZ (14/10/2019)) |
(→PYTHON CODE) |
||
Line 45: | Line 45: | ||
n=len(A) | n=len(A) | ||
+ | |||
+ | Gauss Elimination code, | ||
for k in range (0,n-1): | for k in range (0,n-1): | ||
Line 53: | Line 55: | ||
B[i]=B[i]-(B[k]*lam) | B[i]=B[i]-(B[k]*lam) | ||
print ('matrix A:', '\n', A) | print ('matrix A:', '\n', A) | ||
+ | |||
+ | Back substitution, | ||
+ | |||
x=np.zeros(n,float) | x=np.zeros(n,float) | ||
for m in range (n-1, -1, -1): | 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] | 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]) | print ('nilai X', m+1, '=', x[m]) |
Revision as of 14:53, 14 October 2019
PROFILE
Nama saya adalah Samuel Albert Sitompul lahir di Medan, 1 Maret 1997. Saya mengawali pendidikan sekolah di Medan (TK-SMA) hingga sekarang saya sedang menempuh perkuliahan saya di Universitas Indonesia pada jurusan Teknik Mesin sejak tahun 2016. Hobi saya adalah berolahraga dan membaca.
QUIZ (14/10/2019)
Problem set 2.1 Number 6 page 55
Matrix given,
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]
Before entering Gauss Elimination, matrix should be configured so we could eliminate it,
Matrix configuration,
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]
So the result is,
X1 = 2
X2 = -2
X3 = 1
X4 = 1
X5 = -1
PYTHON CODE
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)
Gauss Elimination code,
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)
Back substitution,
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])