# draw_math_function
Jalankan kode pada sel-sel di bawah ini sehingga identitas Anda tertampilkan dengan benar dan gambarkan beberapa fungsi matematika.


```python
from IPython.core.display import HTML
HTML("")

import sys, os
sys.path.insert(1, os.path.join(sys.path[0], '../..'))

from src.student import Students as stu
nim = 10200999
print(nim, end=' ')
print(stu[nim]['name'], end=' ')
print("https://github.com/", stu[nim]['github'], sep='')
```


```python
import math
import matplotlib.pyplot as plt
```

## function
Sebuah fungsi matematika, misalnya saja

<a name='eqn1'></a>
\begin{equation}\tag{1}
f(x) = \left[ x - 2.5 e^{-(x - 2.8)} \right] \sin \tfrac23 \pi (x-1)
\end{equation}

dapat digambarkan dengan dalam rentang $x \in [x_{\rm beg}, x_{\rm end}]$.


```python
# define a function of x
def f(x):
    y1 = (x -  2.5 * math.exp(-(x - 2.8)))
    y2 = math.sin(2 * math.pi * (x - 1) / 3)
    y = y1 * y2
    return y
```


```python
# create data
xbeg = 0
xend = 10
N = 100
dx = (xend - xbeg) / N

xx = []
yy = []

for i in range(0, N + 1):
    x = xbeg + i * dx
    y = f(x)
    
    xx.append(x)
    yy.append(y)

```


```python
# plot data
plt.ion()
fig, ax = plt.subplots()
ax.set_xlabel("$x$")
ax.set_ylabel("$y$")
plt.plot(xx, yy)

# draw horizontal line
line = plt.Line2D((xbeg, xend), (0, 0), color='#aaa', lw=1, ls='dashed')
plt.gca().add_line(line)

# show plot result
plt.show()
```

## another function
Terdapat fungsi lain berbentuk

<a name='eqn2'></a>
\begin{equation}\tag{2}
f(x) = e^{-ax} \sin bx
\end{equation}

dalam rentang $x \in [x_{\rm beg}, x_{\rm end}]$ yang memberikan hasil



dengan nilai-nilai $a$, $b$, $x_{\rm beg}$, $x_{\rm end}$, dan $N$ tertentu.


```python
# set parameters
a = 0.1
b = 4
xbeg = 0
xend = 8
N = 100

# define another function of x
def g(x):
    y = math.exp(-a * x) * math.sin(b * x)
    return y

# create data
dx = (xend - xbeg) / N

xx = []
yy = []

for i in range(0, N + 1):
    x = xbeg + i * dx
    y = g(x)
    
    xx.append(x)
    yy.append(y)

# plot data
plt.ion()
fig, ax = plt.subplots()
ax.set_xlabel("$x$")
ax.set_ylabel("$y$")
plt.plot(xx, yy)

# draw horizontal line
line = plt.Line2D((xbeg, xend), (0, 0), color='#aaa', lw=1, ls='dashed')
plt.gca().add_line(line)
line = plt.Line2D((xbeg, xend), (0.4, 0.4), color='#aaa', lw=1, ls='dashed')
plt.gca().add_line(line)
line = plt.Line2D((xbeg, xend), (0.8, 0.8), color='#aaa', lw=1, ls='dashed')
plt.gca().add_line(line)
line = plt.Line2D((xbeg, xend), (-0.4, -0.4), color='#aaa', lw=1, ls='dashed')
plt.gca().add_line(line)

# show plot result
plt.show()

# print parameters
print("a = ", a, sep='')
print("b = ", b, sep='')
print("xbeg = ", xbeg, sep='')
print("xend = ", xend, sep='')
print("N = ", N, sep='')
```

Modifikasi kode di atas sehingga gambar berikut dapat diperoleh.



46dbe3d8edb41efd971cb47087993a602fc43491
ipynb
Jupyter Notebook
notebook/3201-u2-instruction/test-2021-2-fi3201-01-u2/que/10200000/draw_math_function.ipynb
dudung/cookbook
8a43a923af8367dafd04e3dd2ef6b9e7ed82b22f
MIT
notebook/3201-u2-instruction/test-2021-2-fi3201-01-u2/que/10200000/draw_math_function.ipynb
dudung/cookbook
8a43a923af8367dafd04e3dd2ef6b9e7ed82b22f
MIT
notebook/3201-u2-instruction/test-2021-2-fi3201-01-u2/que/10200000/draw_math_function.ipynb
dudung/cookbook
8a43a923af8367dafd04e3dd2ef6b9e7ed82b22f
MIT
Qwen/Qwen-72B
1. YES
2. YES