Web VPython · 고급 미적분 정적분 30선

움직이는 정적분 함수 그래프 30개

Web VPython 3.2에서 그대로 붙여 넣어 실행할 수 있는 고급 미적분 애니메이션 예제입니다. 함수 그래프, 누적 정적분, 수치적분, 부호 있는 넓이, 곡선 사이 넓이, 회전체 부피, 확률, 매개변수 적분까지 단계적으로 구성했습니다.

실행: 아래 코드 복사 → Web VPython 새 프로그램 → 붙여넣기 → Run. 각 코드는 독립 실행형입니다.

① 그래프 애니메이션
rate()로 시간 흐름을 만들고 점·곡선·막대를 계속 갱신합니다.
② 정적분 계산
area += f(x)*dx 형태로 리만합을 누적합니다.
③ 고급 주제
FTC, Simpson, 이동구간, CDF, convolution, 회전체 부피를 포함합니다.
④ 탐구 활동
dx, 구간, 함수, 매개변수를 바꾸며 오차와 형태를 비교합니다.
예제 01

01. x²의 누적 정적분

F(b)=∫₀ᵇx²dx

핵심: 미적분학의 기본정리와 누적함수

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "01. x²의 누적 정적분\nF(b)=∫₀ᵇx²dx\n"

a = 0
bmax = 4
dx = 0.02

# 함수 정의
def f(x):
    return x**2

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 02

02. sin(x)의 부호 있는 넓이

F(b)=∫₀ᵇsin(x)dx

핵심: 양의 넓이와 음의 넓이가 상쇄되는 과정을 관찰

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "02. sin(x)의 부호 있는 넓이\nF(b)=∫₀ᵇsin(x)dx\n"

a = 0
bmax = 2*pi
dx = 0.03

# 함수 정의
def f(x):
    return sin(x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 03

03. cos(x)의 누적 정적분

F(b)=∫₀ᵇcos(x)dx

핵심: F(b)=sin(b)의 움직임 비교

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "03. cos(x)의 누적 정적분\nF(b)=∫₀ᵇcos(x)dx\n"

a = 0
bmax = 2*pi
dx = 0.03

# 함수 정의
def f(x):
    return cos(x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 04

04. e^(-x)의 누적 넓이

F(b)=∫₀ᵇe^(-x)dx

핵심: 무한구간 적분의 수렴을 유한 구간에서 관찰

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "04. e^(-x)의 누적 넓이\nF(b)=∫₀ᵇe^(-x)dx\n"

a = 0
bmax = 6
dx = 0.03

# 함수 정의
def f(x):
    return exp(-x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 05

05. 가우스 함수

F(b)=∫₀ᵇe^(-x²)dx

핵심: 초등함수로 원시함수를 쓰기 어려운 대표 예

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "05. 가우스 함수\nF(b)=∫₀ᵇe^(-x²)dx\n"

a = 0
bmax = 3
dx = 0.02

# 함수 정의
def f(x):
    return exp(-x*x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 06

06. 1/(1+x²)

F(b)=∫₀ᵇ1/(1+x²)dx

핵심: arctan과 정적분의 관계

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "06. 1/(1+x²)\nF(b)=∫₀ᵇ1/(1+x²)dx\n"

a = 0
bmax = 5
dx = 0.03

# 함수 정의
def f(x):
    return 1/(1+x*x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 07

07. √x의 누적 넓이

F(b)=∫₀ᵇ√x dx

핵심: 거듭제곱 함수의 정적분

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "07. √x의 누적 넓이\nF(b)=∫₀ᵇ√x dx\n"

a = 0
bmax = 5
dx = 0.03

# 함수 정의
def f(x):
    return sqrt(x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 08

08. x³-x의 부호 넓이

F(b)=∫₋₂ᵇ(x³-x)dx

핵심: 영점 통과 때 누적값이 어떻게 변하는지 관찰

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "08. x³-x의 부호 넓이\nF(b)=∫₋₂ᵇ(x³-x)dx\n"

a = -2
bmax = 2
dx = 0.02

# 함수 정의
def f(x):
    return x**3-x

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 09

09. |x|의 정적분

F(b)=∫₋₃ᵇ|x|dx

핵심: 절댓값 함수의 구간별 적분

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "09. |x|의 정적분\nF(b)=∫₋₃ᵇ|x|dx\n"

a = -3
bmax = 3
dx = 0.03

# 함수 정의
def f(x):
    return abs(x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 10

10. sinc 함수

F(b)=∫₀.₀₅ᵇ sin(x)/x dx

핵심: 진동하며 수렴하는 적분의 직관

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "10. sinc 함수\nF(b)=∫₀.₀₅ᵇ sin(x)/x dx\n"

a = 0.05
bmax = 18
dx = 0.05

# 함수 정의
def f(x):
    return sin(x)/x

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 11

11. sin(x²) 프레넬형 적분

F(b)=∫₀ᵇsin(x²)dx

핵심: 진동수가 증가하는 함수의 누적 적분

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "11. sin(x²) 프레넬형 적분\nF(b)=∫₀ᵇsin(x²)dx\n"

a = 0
bmax = 5
dx = 0.02

# 함수 정의
def f(x):
    return sin(x*x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 12

12. 감쇠진동

F(b)=∫₀ᵇe^(-0.2x)sin(3x)dx

핵심: 진동과 감쇠가 누적값에 미치는 영향

Web VPython 3.2
scene.width = 900
scene.height = 420
scene.background = color.black
scene.title = "12. 감쇠진동\nF(b)=∫₀ᵇe^(-0.2x)sin(3x)dx\n"

a = 0
bmax = 12
dx = 0.03

# 함수 정의
def f(x):
    return exp(-0.2*x)*sin(3*x)

# 좌표 범위를 계산하기 위한 표본값
xs = arange(a, bmax+dx, dx)
ys = [f(x) for x in xs]
ymin = min(min(ys), -0.5)
ymax = max(max(ys), 0.5)
scene.center = vec((a+bmax)/2, (ymin+ymax)/2, 0)
scene.range = max(bmax-a, ymax-ymin)*0.58
scene.autoscale = False

# 축
curve(pos=[vec(a,0,0), vec(bmax,0,0)], color=color.white)
curve(pos=[vec(0,ymin,0), vec(0,ymax,0)], color=color.white)

# 함수 그래프
fc = curve(color=color.cyan, radius=0.012)
for x in xs:
    fc.append(pos=vec(x, f(x), 0))

# 누적 적분을 나타낼 막대
bars = []
marker = sphere(pos=vec(a,f(a),0), radius=0.06, color=color.yellow)
info = label(pos=vec((a+bmax)/2, ymax*0.9, 0), text="", box=False, color=color.white)

area = 0
x = a
while x < bmax:
    rate(45)
    y = f(x)
    area += y*dx

    # 넓이 막대: 양수는 초록, 음수는 빨강
    c = color.green if y >= 0 else color.red
    h = abs(y)
    bar = box(pos=vec(x+dx/2, y/2, -0.05),
              size=vec(dx*0.88, h, 0.05),
              color=c, opacity=0.45)
    bars.append(bar)

    marker.pos = vec(x, y, 0.05)
    info.text = "b = " + str(round(x,2)) + "    integral ≈ " + str(round(area,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 13

13. 움직이는 구간 [a,b] 적분

I(t)=∫ₜᵗ⁺² sin(x)dx

핵심: 적분구간 자체가 이동하는 Leibniz형 예제

Web VPython 3.2
scene.width=900
scene.height=420
scene.background=color.black
scene.title="움직이는 구간 [t,t+2]에서 sin(x)의 정적분\n"
scene.center=vec(3,0,0)
scene.range=6
scene.autoscale=False

curve(pos=[vec(-2,0,0),vec(8,0,0)],color=color.white)
fc=curve(color=color.cyan,radius=0.012)
for x in arange(-2,8.01,0.02):
    fc.append(pos=vec(x,sin(x),0))

left=box(pos=vec(0,0,0),size=vec(0.04,2.4,0.04),color=color.yellow)
right=box(pos=vec(2,0,0),size=vec(0.04,2.4,0.04),color=color.orange)
info=label(pos=vec(3,1.8,0),text="",box=False)

t=-1.5
while True:
    rate(40)
    if t>5.5: t=-1.5
    a=t
    b=t+2
    dx=0.01
    s=0
    x=a
    while x<b:
        s += sin(x)*dx
        x += dx
    left.pos.x=a
    right.pos.x=b
    info.text="t="+str(round(t,2))+"   integral≈"+str(round(s,5))
    t += 0.03
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 14

14. 리만합 n 증가

∫₀³x²dx ≈ Σ f(xᵢ*)Δx

핵심: 분할 수가 증가하며 근사값이 9에 접근

Web VPython 3.2
scene.width=900
scene.height=430
scene.background=color.black
scene.title="리만합: n이 증가할수록 ∫0^3 x² dx = 9 에 접근\n"
scene.center=vec(1.5,4.5,0)
scene.range=5
scene.autoscale=False
curve(pos=[vec(0,0,0),vec(3.3,0,0)],color=color.white)
fc=curve(color=color.cyan,radius=0.015)
for x in arange(0,3.01,0.02):
    fc.append(pos=vec(x,x*x,0))
info=label(pos=vec(1.5,10,0),text="",box=False)

for n in range(2,61):
    rate(3)
    dx=3/n
    rects=[]
    s=0
    for i in range(n):
        x=(i+0.5)*dx
        y=x*x
        s += y*dx
        rects.append(box(pos=vec(x,y/2,-0.04), size=vec(dx*0.94,y,0.04),
                         color=color.green,opacity=0.38))
    info.text="n="+str(n)+"   midpoint sum="+str(round(s,6))+"   error="+str(round(abs(9-s),6))
    sleep(0.08)
    for r in rects:
        r.visible=False
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 15

15. 좌·우·중점 리만합 비교

∫₀²eˣdx

핵심: 표본점 선택에 따른 오차 비교

Web VPython 3.2
g=graph(title="Left / Right / Midpoint Riemann Sum Error", xtitle="n", ytitle="absolute error")
L=gcurve(color=color.red,label="Left")
R=gcurve(color=color.orange,label="Right")
M=gcurve(color=color.green,label="Midpoint")
exact=exp(2)-1

for n in range(2,101):
    rate(20)
    dx=2/n
    sl=0
    sr=0
    sm=0
    for i in range(n):
        sl += exp(i*dx)*dx
        sr += exp((i+1)*dx)*dx
        sm += exp((i+0.5)*dx)*dx
    L.plot(n,abs(exact-sl))
    R.plot(n,abs(exact-sr))
    M.plot(n,abs(exact-sm))
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 16

16. 사다리꼴 공식 수렴

∫₀^π sin(x)dx=2

핵심: 사다리꼴 공식의 수렴을 오차 그래프로 관찰

Web VPython 3.2
g=graph(title="Trapezoidal Rule: ∫0^π sin(x) dx", xtitle="n", ytitle="approximation")
approx=gcurve(color=color.cyan,label="trapezoid")
exact=gcurve(color=color.yellow,label="exact = 2")

for n in range(2,121):
    rate(25)
    dx=pi/n
    s=0.5*sin(0)+0.5*sin(pi)
    for i in range(1,n):
        s += sin(i*dx)
    T=s*dx
    approx.plot(n,T)
    exact.plot(n,2)
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 17

17. 심프슨 공식 수렴

∫₀^π sin(x)dx=2

핵심: 짝수 n에서 Simpson 1/3 공식의 빠른 수렴

Web VPython 3.2
g=graph(title="Simpson Rule Convergence",xtitle="n",ytitle="absolute error")
err=gcurve(color=color.magenta,label="Simpson error")

for n in range(2,82,2):
    rate(12)
    h=pi/n
    s=sin(0)+sin(pi)
    for i in range(1,n):
        if i%2==1:
            s += 4*sin(i*h)
        else:
            s += 2*sin(i*h)
    S=s*h/3
    err.plot(n,abs(2-S))
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 18

18. 미적분학의 기본정리

F(x)=∫₀ˣcos(t)dt, F'(x)=cos(x)

핵심: 누적함수 F와 원함수 f의 변화율 관계

Web VPython 3.2
g=graph(title="FTC: F(x)=∫0^x cos(t)dt and f(x)=cos(x)",xtitle="x",ytitle="value")
fcurve=gcurve(color=color.cyan,label="f(x)=cos(x)")
Fcurve=gcurve(color=color.yellow,label="F(x) numerical")

dx=0.01
area=0
x=0
while x<=2*pi:
    rate(60)
    area += cos(x)*dx
    fcurve.plot(x,cos(x))
    Fcurve.plot(x,area)
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 19

19. 곡선 사이 넓이

A(b)=∫₀ᵇ[(2x+2)-x²]dx

핵심: 위 함수와 아래 함수의 차이를 적분

Web VPython 3.2
scene.width=900
scene.height=430
scene.background=color.black
scene.title="Area between y=2x+2 and y=x²\n"
scene.center=vec(1.5,2.5,0)
scene.range=4
scene.autoscale=False
top=curve(color=color.yellow,radius=0.012)
bot=curve(color=color.cyan,radius=0.012)
for x in arange(0,3.01,0.02):
    top.append(pos=vec(x,2*x+2,0))
    bot.append(pos=vec(x,x*x,0))
info=label(pos=vec(1.5,7,0),text="",box=False)
A=0
dx=0.02
x=0
while x<=2:
    rate(35)
    y1=2*x+2
    y2=x*x
    A += (y1-y2)*dx
    box(pos=vec(x,(y1+y2)/2,-0.04),size=vec(dx*0.9,y1-y2,0.04),
        color=color.green,opacity=0.4)
    info.text="b="+str(round(x,2))+"   area≈"+str(round(A,5))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 20

20. 평균값 정리와 함수 평균

f_avg=(1/(b-a))∫ₐᵇf(x)dx

핵심: 평균 높이와 같은 넓이의 직사각형

Web VPython 3.2
scene.width=900
scene.height=430
scene.background=color.black
scene.title="Integral average value of f(x)=1+sin(x) on [0,b]\n"
scene.center=vec(3.2,1,0)
scene.range=4.5
scene.autoscale=False
fc=curve(color=color.cyan,radius=0.012)
for x in arange(0,2*pi+0.01,0.02):
    fc.append(pos=vec(x,1+sin(x),0))
avgline=curve(pos=[vec(0,0,0),vec(0,0,0)],color=color.yellow,radius=0.018)
info=label(pos=vec(pi,2.8,0),text="",box=False)

dx=0.01
A=0
b=0.05
while b<=2*pi:
    rate(50)
    A += (1+sin(b))*dx
    avg=A/b
    avgline.clear()
    avgline.append(pos=vec(0,avg,0.05))
    avgline.append(pos=vec(b,avg,0.05))
    info.text="b="+str(round(b,2))+"   average≈"+str(round(avg,4))
    b += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 21

21. 원판법 회전체 부피 누적

V(b)=π∫₀ᵇ(√x)²dx

핵심: 정적분으로 회전체 부피를 누적

Web VPython 3.2
scene.width=900
scene.height=430
scene.background=color.black
scene.title="Disk method: rotate y=sqrt(x) about x-axis\n"
scene.center=vec(2,0,0)
scene.range=4
scene.autoscale=False
curve(pos=[vec(0,0,0),vec(4.3,0,0)],color=color.white)
info=label(pos=vec(2,2.7,0),text="",box=False)

dx=0.04
V=0
x=0.02
while x<=4:
    rate(30)
    r=sqrt(x)
    V += pi*r*r*dx
    cylinder(pos=vec(x,0,0),axis=vec(dx,0,0),radius=r,
             color=color.cyan,opacity=0.15)
    info.text="b="+str(round(x,2))+"   volume≈"+str(round(V,4))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 22

22. 원통껍질법 부피

V=2π∫₀²x(4-x²)dx

핵심: shell method를 3D 원통껍질로 표현

Web VPython 3.2
scene.width=900
scene.height=430
scene.background=color.black
scene.title="Cylindrical shell method: y=4-x², 0≤x≤2\n"
scene.center=vec(0,2,0)
scene.range=4.5
scene.autoscale=False
info=label(pos=vec(0,5,0),text="",box=False)

dx=0.04
V=0
x=dx
while x<=2:
    rate(18)
    h=4-x*x
    dV=2*pi*x*h*dx
    V += dV
    cylinder(pos=vec(0,0,0),axis=vec(0,h,0),radius=x,
             thickness=dx, color=color.orange,opacity=0.22)
    info.text="radius="+str(round(x,2))+"   accumulated V≈"+str(round(V,4))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 23

23. 정규분포 누적확률

P(0≤X≤b)=∫₀ᵇ φ(x)dx

핵심: 정적분과 누적분포함수(CDF)의 관계

Web VPython 3.2
g=graph(title="Standard normal: density and accumulated probability",xtitle="x",ytitle="value")
pdf=gcurve(color=color.cyan,label="pdf")
cdf=gcurve(color=color.yellow,label="∫0^x pdf")

def phi(x):
    return exp(-x*x/2)/sqrt(2*pi)

dx=0.01
A=0
x=0
while x<=4:
    rate(70)
    A += phi(x)*dx
    pdf.plot(x,phi(x))
    cdf.plot(x,A)
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 24

24. 로지스틱 함수 누적

F(b)=∫₋₆ᵇ L(x)dx

핵심: S자 함수의 누적량을 움직이며 관찰

Web VPython 3.2
g=graph(title="Integral of logistic function",xtitle="x",ytitle="value")
f=gcurve(color=color.cyan,label="L(x)")
F=gcurve(color=color.green,label="accumulated integral")
def L(x):
    return 1/(1+exp(-x))
dx=0.02
A=0
x=-6
while x<=6:
    rate(60)
    A += L(x)*dx
    f.plot(x,L(x))
    F.plot(x,A)
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 25

25. 매개변수 a 변화

I(a)=∫₀³e^(-ax)dx

핵심: 매개변수 변화가 정적분 값에 미치는 영향

Web VPython 3.2
g=graph(title="Parameter integral I(a)=∫0^3 exp(-a x) dx",xtitle="a",ytitle="I(a)")
gc=gcurve(color=color.yellow,label="numerical I(a)")
a=0.1
while a<=4:
    rate(20)
    dx=0.005
    x=0
    s=0
    while x<=3:
        s += exp(-a*x)*dx
        x += dx
    gc.plot(a,s)
    a += 0.03
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 26

26. 주파수 k 변화

I(k)=∫₀^π sin(kx)dx

핵심: 고주파 진동에서 상쇄가 커지는 현상

Web VPython 3.2
g=graph(title="Oscillatory integral I(k)=∫0^π sin(kx) dx",xtitle="k",ytitle="I(k)")
gc=gcurve(color=color.cyan,label="I(k)")
k=0.2
while k<=12:
    rate(25)
    dx=0.002
    x=0
    s=0
    while x<=pi:
        s += sin(k*x)*dx
        x += dx
    gc.plot(k,s)
    k += 0.05
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 27

27. 적분 오차 비교

Left vs Trapezoid vs Simpson

핵심: 세 수치적분법의 오차 감소 속도 비교

Web VPython 3.2
g=graph(title="Numerical integration errors for ∫0^1 exp(x) dx",xtitle="n",ytitle="absolute error")
L=gcurve(color=color.red,label="Left")
T=gcurve(color=color.orange,label="Trapezoid")
S=gcurve(color=color.green,label="Simpson")
exact=exp(1)-1

for n in range(2,82,2):
    rate(10)
    h=1/n
    left=0
    for i in range(n):
        left += exp(i*h)*h
    trap=0.5*(exp(0)+exp(1))
    for i in range(1,n):
        trap += exp(i*h)
    trap *= h
    sim=exp(0)+exp(1)
    for i in range(1,n):
        sim += (4 if i%2==1 else 2)*exp(i*h)
    sim *= h/3
    L.plot(n,abs(exact-left))
    T.plot(n,abs(exact-trap))
    S.plot(n,abs(exact-sim))
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 28

28. 이동평균 적분

M(t)=1/2∫ₜ₋₁ᵗ⁺¹ sin(x²)dx

핵심: 적분을 이용한 smoothing/이동평균

Web VPython 3.2
g=graph(title="Moving-average integral of sin(x²)",xtitle="t",ytitle="value")
raw=gcurve(color=color.cyan,label="sin(t²)")
avg=gcurve(color=color.yellow,label="moving average")
t=-3
while t<=3:
    rate(30)
    dx=0.01
    x=t-1
    s=0
    while x<=t+1:
        s += sin(x*x)*dx
        x += dx
    raw.plot(t,sin(t*t))
    avg.plot(t,s/2)
    t += 0.03
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 29

29. 컨볼루션형 적분

C(t)=∫e^(-x²)e^(-(t-x)²)dx

핵심: 두 함수가 겹치는 정도를 이동시키며 측정

Web VPython 3.2
g=graph(title="Convolution-like integral of two Gaussians",xtitle="t",ytitle="C(t)")
gc=gcurve(color=color.magenta,label="overlap integral")
t=-4
while t<=4:
    rate(30)
    dx=0.02
    x=-5
    s=0
    while x<=5:
        s += exp(-x*x)*exp(-(t-x)*(t-x))*dx
        x += dx
    gc.plot(t,s)
    t += 0.04
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.

예제 30

30. 적분으로 정의된 함수의 접선

F(x)=∫₀ˣ e^(-t²)dt

핵심: F'(x)=e^(-x²)를 수치적으로 확인

Web VPython 3.2
g=graph(title="Integral-defined function and numerical derivative",xtitle="x",ytitle="value")
Fcurve=gcurve(color=color.yellow,label="F(x)")
Dcurve=gcurve(color=color.green,label="numerical F'(x)")
fcurve=gcurve(color=color.cyan,label="e^(-x²)")
dx=0.01
A=0
prevA=0
x=0
while x<=3:
    rate(60)
    prevA=A
    A += exp(-x*x)*dx
    derivative=(A-prevA)/dx
    Fcurve.plot(x,A)
    Dcurve.plot(x,derivative)
    fcurve.plot(x,exp(-x*x))
    x += dx
수업용 상세 해설

관찰 포인트 1. rate()가 반복문의 진행 속도를 제한하여 그래프나 적분값이 시간에 따라 변하는 모습을 보여 줍니다.

관찰 포인트 2. 정적분은 작은 구간의 넓이 f(x)*dx를 계속 더하는 방식으로 수치적으로 근사합니다.

관찰 포인트 3. 함수가 x축 아래에 있으면 부호 있는 넓이는 음수이므로 누적값이 감소할 수 있습니다.

탐구 과제. 구간, 함수식, dx, 애니메이션 속도를 바꾸고 근삿값이 어떻게 달라지는지 비교해 보세요.