- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathintegration_sin.py
More file actions
Latest commit
38 lines (31 loc) · 654 Bytes
/
Copy pathintegration_sin.py
File metadata and controls
38 lines (31 loc) · 654 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
importnumpyasnp
importmatplotlib.pyplotasplt
importmath
dx=0.1
xvals= []
yvals= []
# 적분 근사화 함수
defintegral_approximation(f, a, b):
return (b-a)*np.mean(f)
# 적분 f(x) = sin(x)
deff(x):
globalxvals, yvals
y=math.sin(x)
xvals.append(x)
yvals.append(y)
returny
# 적분의 범위 정의
a=0
b=1
# 함수 값 생성
x_range=np.arange(a, b, dx)
fx=np.vectorize(f)(x_range)
# 근사 적분
approx=integral_approximation(fx, a, b)
print(approx)
plt.plot(xvals, yvals)
plt.fill_between(xvals[:], yvals[:], alpha=0.2)
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.grid()
plt.show()