Kalkulus 1.3

mail@pastecode.io avatar
unknown
python
2 years ago
576 B
2
Indexable
Never
# Latihan 1.3 bagian a
import numpy as np
from scipy.integrate import quad

def integrand(x, a, b):
  return (a * (x ** 2)) + b

a = 1
b = 2
I = quad(integrand, 0, 1, args=(a,b))
print(I)

def integran(x):
  return x*np.sin(x)
bb = 0
ba = np.pi/2
# Latihan 1.3 bagian b
Iq = quad(integran, bb, ba)
print(Iq)

# Latihan 1.3 bagian c
from scipy.integrate import trapz
xtr = np.linspace(bb, ba, num=17)
ytr = []
for hhh in xtr:
  ytr.append(integran(hhh))
It = trapz(ytr, xtr)
print(It)

# Latihan 1.3 bagian d
from scipy.integrate import simpson
Is = simpson(ytr, xtr)
print(Is)