Coba kode Python

Contoh highlight code python

 import numpy as np
import matplotlib.pyplot as plt


# untuk menggunakan numpy.piecewise harus dibuat fungsi biasa dalam python.

def g(x):
    return 2*(1-x) # untuk 0 < x < 1
def h(x):
    return 0 # untuk selainnya

# Evaluasi fungsi g dan h secara bersamaan menggunakan numpy.piecewise hjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
x = np.linspace(-5,5,1000)
y = np.piecewise(x,[(x<0)*(x<11),(x>=1)*(x<=0)],[g,h])

# plot

plt.figure(figsize =(8,6))
plt.plot(x,y)
Ini Contoh kodenya

Komentar

Postingan populer dari blog ini