We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1353769 commit e6f4792Copy full SHA for e6f4792
integration_sin.py
@@ -0,0 +1,38 @@
1
+import numpy as np
2
+import matplotlib.pyplot as plt
3
+import math
4
+
5
+dx = 0.1
6
+xvals = []
7
+yvals = []
8
9
+# 적분 근사화 함수
10
+def integral_approximation(f, a, b):
11
+ return (b-a)*np.mean(f)
12
13
+# 적분 f(x) = sin(x)
14
+def f(x):
15
+ global xvals, yvals
16
+ y = math.sin(x)
17
+ xvals.append(x)
18
+ yvals.append(y)
19
+ return y
20
21
+# 적분의 범위 정의
22
+a = 0
23
+b = 1
24
25
+# 함수 값 생성
26
+x_range = np.arange(a, b, dx)
27
+fx = np.vectorize(f)(x_range)
28
29
+# 근사 적분
30
+approx = integral_approximation(fx, a, b)
31
+print(approx)
32
33
+plt.plot(xvals, yvals)
34
+plt.fill_between(xvals[:], yvals[:], alpha=0.2)
35
+plt.xlabel("x")
36
+plt.ylabel("sin(x)")
37
+plt.grid()
38
+plt.show()
0 commit comments