0% found this document useful (0 votes)
87 views8 pages

Simetrik Matrik

The document describes a Python program that draws 3D surface graphs from symmetric matrices. The program allows the user to input a symmetric matrix and determines if it is positive definite, semi-positive definite, indefinite, or negative definite. It then plots the surface z=f(x,y) based on the matrix entries, where f(x,y) = ax^2 + 2bxy + cy^2. The pseudocode explains the process of finding the matrix properties, defining the surface function, and outputting the graph.

Uploaded by

Hery Putrawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views8 pages

Simetrik Matrik

The document describes a Python program that draws 3D surface graphs from symmetric matrices. The program allows the user to input a symmetric matrix and determines if it is positive definite, semi-positive definite, indefinite, or negative definite. It then plots the surface z=f(x,y) based on the matrix entries, where f(x,y) = ax^2 + 2bxy + cy^2. The pseudocode explains the process of finding the matrix properties, defining the surface function, and outputting the graph.

Uploaded by

Hery Putrawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

TUGAS MATEMATIKA LANJUT

I KADEK AGUS WAHYU RAHARJA (23219019)

Program Menggambar Grafik dari Matriks Simetris

'''
I Kadek Agus Wahyu Raharja(23219019)
Menggambar Surface dari Simetric Matric
'''

from mpl_toolkits import mplot3d


import numpy as np
import matplotlib.pyplot as plt
import sys

A1 = np.array([[4, 6],[6, 12]])


A2 = np.array([[4, 6],[6, 9]])
A3 = np.array([[4, 6],[6, 7]])

def definite_test(A):
#Mencari determinant dengan metode pivot
n = len(A)
for i in range(n):
for j in range(i+1,n):
c = A[j][i]/A[i][i]
for k in range(n):
A[j][k] -= A[i][k]*c
m = np.array(A)

#Menentukan sifat definite matrix


for i in range(n):
row = []
row1 = []
row2 = []
for j in range(n):
if (i == j):
r_ = m[i][i]>0.0
r1_ = m[i][i]==0.0
r2_ = m[i][i]<0.0
row.append(r_)
row1.append(r1_)
row2.append(r2_)
r = np.array(row)
r1 = np.array(row1)
r2 = np.array(row2)
if(r.all()==True and r1.all()==False and r2.all()==False):
result = print('Matrix A adalah Positive Definite')
elif(r.all()==False and r1.all()==False and r2.all()==True):
result = print('Matrix A adalah Negative Definite')
elif(r.any()==True and r1.any()==True and r2.all()==False):
result = print('Matrix A adalah Semipositif Definite')
elif(r.all()==False and r1.any()==True and r2.any()==True):
result = print('Matrix A adalah Seminegatif Definite')
elif(r.any()==True and r1.any()==False and r2.any()==True):
result = print('Matrix A adalah Indefinite')
return result

#Menentukan model yang dipilih


print('pilihan mode pada program :\n 1. Matrix Positive Definite\n 2. Matrix
SemiPositive Definite\n 3. Matrix Indefinite\n 4. Input Matrix Simetris')
mode = int(input('Inputkan no mode yang diinginkan(1,2,3,4) :'))

if (mode==1):
A = A1
print(A)
elif (mode==2):
A = A2
print(A)
elif (mode==3):
A = A3
print(A)
elif (mode==4):
print("Masukan nilai matrix simetris A 2x2(pisahkan dengan spasi): ")
entries = list(map(float, input().split()))
B = np.array(entries).reshape(2,2)
C = np.transpose(B)== B
if (C.all()==True):
A = B
print(A)
D = definite_test(A)
else :
sys.exit('A.T != A (Matrix tidak simetris)')

#fungsi f(x,y) jika A adalah matrix 2x2


def f(a, b, c, x, y):
return (a*(x ** 2) + 2*b*x*y + c*(y** 2))

#menggambar Surface dengan fungsi f(x,y) = ax^2 + 2bxy + cy^2


a = A[0][0]
b = A[0][1]
c = A[1][1]

fig = plt.figure()
ax = fig.gca(projection="3d")

x = np.linspace(-5, 5, 20)
y = np.linspace(-5, 5, 20)

x, y = np.meshgrid(x, y)
z = f(a, b, c, x, y)

ax.plot_surface(x, y, z, rstride=1, cstride=1,


cmap='viridis', edgecolor='none')

ax.set_title('Surface Matrix A\n')


ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('f(x,y)')
plt.show()
Berdasarkan program dapat dilihat terdapat empat pilihan input matriks simetris yang diinginkan
yaitu 1. Matrix Positive Definite\n 2. Matrix SemiPositive Definite\n 3.
Matrix Indefinite\n 4. Input Matrix Simetris, Setelah itu akan dibentuk gafik 3
dimensi dengan fungsi f(x,y) = ax^2 + 2bxy + cy^2 dengan batas nilai x dan y adalah
dari -5 sampai 5. Berikut adalah output masing – masing inputan.

Mode 1:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>>
======================= RESTART: D:\SymmetricMatrix.py
=======================
pilihan mode pada program :
1. Matrix Positive Definite
2. Matrix SemiPositive Definite
3. Matrix Indefinite
4. Input Matrix Simetris
Inputkan no mode yang diinginkan(1,2,3,4) :1
[[ 4 6]
[ 6 12]]

Grafik :
Mode 2:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>>
======================= RESTART: D:\SymmetricMatrix.py
=======================
pilihan mode pada program :
1. Matrix Positive Definite
2. Matrix SemiPositive Definite
3. Matrix Indefinite
4. Input Matrix Simetris
Inputkan no mode yang diinginkan(1,2,3,4) :2
[[ 4 6]
[ 6 9]]
Grafik :
Mode 3:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>>
======================= RESTART: D:\SymmetricMatrix.py
=======================
pilihan mode pada program :
1. Matrix Positive Definite
2. Matrix SemiPositive Definite
3. Matrix Indefinite
4. Input Matrix Simetris
Inputkan no mode yang diinginkan(1,2,3,4) :3
[[ 4 6]
[ 6 7]]
Grafik :
Mode 4:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>>
======================= RESTART: D:\SymmetricMatrix.py
=======================
pilihan mode pada program :
1. Matrix Positive Definite
2. Matrix SemiPositive Definite
3. Matrix Indefinite
4. Input Matrix Simetris
Inputkan no mode yang diinginkan(1,2,3,4) :4
Masukan nilai matrix simetris A 2x2(pisahkan dengan spasi):
1 2 2 9
[[1. 2.]
[2. 9.]]
Matrix A adalah Positive Definite

Grafik :
Pseudocode Program Menggambar Grafik dari Matriks Simetris
Berikut adalah pseudocode program utama dari proses Menggambar Grafik dari Matriks Simetris
Pseudocode Menggambar Grafik dari Matriks Simetris
Program ini menunjukan cara kerja sistem dimana sistem akan
menampilkan gambar serta mengidentifikasi sifat definite suatu matrik
INPUT :
1. matriks A
GET :
1. orde matriks A = n x n
SET :
1. x, y = RANGE(-5,5)
2. a = A[0][0]
3. b = A[0][1]
4. c = A[1][1]
//Mencari nilai pivot
FOR (nilai baris matriks A = i):
FOR(baris ke 2 sampai nilai kolom matriks A = j):
c = A[j][i]/A[i][i]
FOR (operasi sebanyak i):
A[j][k] -= A[i][k]*c
END FOR
END FOR
END FOR
//menentukan sifat definit
FOR (nilai baris matriks A = i):
FOR(nilai kolom matriks A = j):
c = A[j][i]/A[i][i]
IF (i == j):
r_ = m[i][i]>0.0 (menentukan positif definit dan
semipositif definit)
r1_ = m[i][i]==0.0 (menentukan semipositif dan
seminegatif definit)
r2_ = m[i][i]<0.0 (menentukan negative definit dan
seminegatif definit)
END FOR
END FOR
Z = a*x^2 + 2*b*x*y + c*y^2
OUTPUT:
1. Sifat Matriks
2. Grafik (x,y,z)

You might also like