Andika Ramadhan Gurnida

From ccitonlinewiki
Revision as of 18:51, 16 December 2019 by Andikarg (talk | contribs)
Jump to: navigation, search

Andika profile.jpg

QUIZ 2

  1. ProbSet 2.1 no.6
  2. jawaban

from numpy import linalg import numpy as np

  1. Definisi

row1 = [0,0,2,1,2] row2 = [0,1,0,2,-1] row3 = [1,2,0,-2,0] row4 = [0,0,0,-1,1] row5 = [0,1,-1,1,-1] nmat = np.array([row1,row2,row3,row4,row5]) print("n matrix are:") print(nmat) cons = np.array([1,1,-4,-2,-1]) print("Y matrix are:") print(cons)

  1. Penyelesaian

Ans = linalg.solve(nmat,cons) x1val=int(Ans[0]) x2val=int(Ans[1]) x3val=int(Ans[2]) x4val=int(Ans[3]) x5val=int(Ans[4]) print("x result are:") print("x1=",x1val) print("x2=",x2val) print("x3=",x3val) print("x4=",x4val) print("x5=",x5val)


Ujian Tengah Semester

'''No.1''' from math import *

g = 9.81
m1 = eval(input("mass 1: "))
m2 = eval(input("mass 2: "))
m3 = eval(input("mass 3: "))
alpha = eval(input("alpha: "))
u = eval(input("friction coefficient: "))
x = sin(alpha)
y = cos(alpha)
t1 = m1*g*(x-(u*y))
t2 = (m2*g*(x-(u*y))) + t1
t3 = (m3*g*(x-(u*y))) + t2
t4 = t3
#Hasil
print("t1:  ",t1)
print("t2:  ",t2)
print("t3:  ",t3)
print("t4: ",t4)


'''No.2'''

from math import *
from sympy import *
g = 9.81
pro = 1.2
cd = eval(input("drag coefficient: "))
area = eval(input("area : "))
v0 = 0
m = eval(input("car mass: "))
u = eval(input("friction: "))
a = eval(input("acceleration: "))
vt = eval(input("top speed: "))
fs = g*u
fdrag= (cd*area*pro*v0**2)/2*m
f1 = a
atot = f1 - (fdrag + fs)
t = (vt-v0)/atot
print("time to reach top speed : ",t)


Video Muhasabah : https://youtu.be/RUl5zqLGhoE


Perbaikan UTS

Perbaikan kasus A dengan menggunakan metode eliminasi Gauss :

import math
import numpy as np
#matrix C & D
C = np.array([[1., 0., 0.],
        [-1., 1., 0.],
        [0., -1., 1.]], float)
D = np.array([21.37, 14.24, 7.12], float)
n = len(C) #panjang dari baris c
print('Matriks C :')
print(C,'\n')
print('Matriks C mempunyai ', n , ' baris','\n')
print('Matriks D :')
print(D,'\n')
for k in range(0,n-1): #menggunakan metode eliminasi gauss
for i in range(k+1,n):
    if C[i,k]!=0 :
        lam = C[i,k]/C[k,k] 
        C[i,k:n] = C[i,k:n]-(C[k,k:n]*lam)
        D[i] = D[i]-(D[k]*lam)
      
print('matrix C:', '\n', C, '\n')
print('Nilai tegangan tali :')
x = np.zeros(n,float)
for m in range(n-1,-1,-1):
 x[m]=(D[m]-np.dot(C[m,m+1:n],x[m+1:n]))/C[m,m]
 print('T',m+1,'=', x[m])

Kasus B dengan menggunakan metode Runge Kutta :

g = 9.81
u = eval(input("Friction Coefficient: "))
a = eval(input("Percepatan mobil : "))
cd = eval(input("Drag coefficient : "))
m = eval(input("Massa mobil : "))
t0 = 0
v0 = 0
dt = 1
error = 100
F = a - g*u #dibagi dengan massa
fs = cd/m #dibagi dengan massa
lst = []
def dvdt(t0, v0):
   return F-(fs*(v0)**(1.5))
  
while error > 0.005:
   k1 = dvdt(t0, v0) 
   k2 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k1)
   k3 = dvdt(t0 + 0.5 * dt, v0 + 0.5 * dt * k2) 
   k4 = dvdt(t0 + dt, v0 + dt * k3) 
   v1 = v0 + (1.0 / 6.0)*(k1 + 2 * k2 + 2 * k3 + k4)
   t0 = t0 + dt
   error = ((v1 - v0) / v1)*100 #persentase error
   v0 = v1
   lst.append(v1)
  
waktu = len(lst)
print ("Waktu yang dibutuhkan mobil untuk mencapai top speed dari diam: ", waktu+1, "s")
print ("top speed: ", v1, "m/s")


Tugas Permodelan Matematika Runge Kutta Orde 4