p150からp151
from IPython.display import display, Math, Markdown
import numpy as np
# ▼ 1. 速度の計算(単位:m/s)
# 3秒間に15メートル進んだときの速度を計算する
# Calculate speed when an object moves 15 meters in 3 seconds
distance = 15 # [m] 移動距離 / distance moved in meters
time = 3 # [s] 時間 / time in seconds
speed = distance / time
# LaTeX形式で速度の式と結果を表示 / Display the formula and result using LaTeX
display(Math(r"\text{Speed} = \frac{15\ \mathrm{m}}{3\ \mathrm{s}} = %.1f\ \mathrm{m/s}" % speed))
# ▼ 2. 単位変換:1 g/cm^3 → kg/m^3
# 水の密度などでよく出る単位の変換を行う
# Convert density from gram per cubic centimeter to kilogram per cubic meter
g_to_kg = 1e-3 # 1g = 10^-3 kg
cm_to_m = 1e-2 # 1cm = 10^-2 m
# 密度変換:g/cm^3 → kg/m^3
# Density conversion: g/cm^3 → kg/m^3
conversion = g_to_kg / (cm_to_m**3)
# 結果の表示:1 g/cm^3 = 1000 kg/m^3
display(Math(r"1\ \mathrm{g/cm^3} = 10^{-3}\ \mathrm{kg} / (10^{-2}\ \mathrm{m})^3 = %.0f\ \mathrm{kg/m^3}" % conversion))
# ▼ 3. 力の次元:F = ma → [MLT^{-2}]
# 力は質量×加速度なので、次元で表すと [M][L][T^{-2}]
# Force is mass × acceleration → [M][L][T^{-2}]
display(Math(r"[F] = [M][L][T]^{-2}"))
# ▼ 4. 万有引力定数Gの次元:G = F r^2 / (m1 m2)
# 万有引力の法則 F = G * (m1 * m2) / r^2 より G の次元を導出
# From the universal law of gravitation, derive the dimensional formula of G
# G = F * r^2 / (m1 * m2) → 次元は [MLT^{-2}] * [L^2] / [M^2] = [M^{-1}L^3T^{-2}]
display(Math(r"[G] = \frac{[F] \cdot [L^2]}{[M]^2} = \frac{[MLT^{-2}] \cdot [L^2]}{[M]^2} = [M^{-1}L^3T^{-2}]"))
# ▼ 5. 加速度の式:a = m / (m + M) * g
# 力のつり合いに基づいた加速度の導出式。たとえば滑車や衝突などで使う
# Derive acceleration formula in a two-mass system (e.g. pulley or collision problems)
m = 2.0 # 小さい質量 / smaller mass [kg]
M = 3.0 # 大きい質量 / larger mass [kg]
g = 9.8 # 重力加速度 / acceleration due to gravity [m/s^2]
# a = (m / (m + M)) * g の式に代入して加速度を計算
a = (m / (m + M)) * g
# 結果をLaTeXで表示
display(Math(
r"a = \frac{m}{m + M} g = \frac{%.1f}{%.1f + %.1f} \cdot %.1f = %.2f\ \mathrm{m/s^2}" % (m, m, M, g, a)
))
p154まで
from IPython.display import display, Math
import numpy as np
print("【有効数字のルールまとめ】")
print("1. 掛け算・割り算では、有効数字の桁数が最も少ないものに合わせて結果を丸める。")
print("2. 足し算・引き算では、小数点以下の桁数が最も少ないものに合わせて結果を丸める。")
print("3. 最終的な答えは四捨五入(四捨五入)して表す。\n")
# ▼ 1. 掛け算の例:2.10 × 3.42096(有効数字3桁)
a = 2.10 # 有効数字3桁
b = 3.42096
product = a * b
# 有効数字3桁で丸める
product_rounded = round(product, 3 - int(np.floor(np.log10(abs(product)))) - 1)
print("【例1】掛け算:2.10 × 3.42096")
print(f"計算結果(そのまま): {product:.5f}")
print(f"有効数字3桁に丸めると: {product_rounded:.2f}\n")
display(Math(r"2.10 \times 3.42096 = %.5f \approx %.2f\ (\text{有効数字3桁})" % (product, product_rounded)))
# ▼ 2. 掛け算の例:π × 20.0 × 0.32(有効数字2桁にする)
c = np.pi # π = 3.14159...
d = 20.0 # 有効数字3桁
e = 0.32 # 有効数字2桁
result = c * d * e
# 有効数字2桁で丸める
result_rounded = round(result, 2 - int(np.floor(np.log10(abs(result)))) - 1)
print("【例2】掛け算:π × 20.0 × 0.32")
print(f"計算結果(そのまま): {result:.3f}")
print(f"有効数字2桁に丸めると: {result_rounded:.1e}\n")
display(Math(r"\pi \times 20.0 \times 0.32 = %.3f \approx %.1e\ (\text{有効数字2桁})" % (result, result_rounded)))
# ▼ 3. 足し算の例:263.1724 + 15.2(小数点以下の桁に注意)
f = 263.1724 # 小数点以下4桁
g = 15.2 # 小数点以下1桁
sum_result = f + g
sum_rounded = round(sum_result, 1)
print("【例3】足し算:263.1724 + 15.2")
print(f"計算結果(そのまま): {sum_result:.4f}")
print(f"小数第1位まで有効 → 答えは: {sum_rounded:.1f}\n")
display(Math(r"263.1724 + 15.2 = %.4f \approx %.1f\ (\text{小数点以下1桁})" % (sum_result, sum_rounded)))
# ▼ 4. 足し算と引き算の例:15.03 + 3.827 - 2.154
h = 15.03 # 小数点以下2桁
i = 3.827 # 小数点以下3桁
j = 2.154 # 小数点以下3桁
add_sub_result = h + i - j
add_sub_rounded = round(add_sub_result, 2) # 最小の小数点以下2桁に合わせる
print("【例4】足し算と引き算:15.03 + 3.827 - 2.154")
print(f"計算結果(そのまま): {add_sub_result:.3f}")
print(f"小数第2位まで有効 → 答えは: {add_sub_rounded:.2f}\n")
display(Math(r"15.03 + 3.827 - 2.154 = %.3f \approx %.2f\ (\text{小数点以下2桁})" % (add_sub_result, add_sub_rounded)))
from IPython.display import display, Math, Markdown
print("【物理の代表的な定数とその意味】")
print("物理では定数を覚えていなくてもよいが、近似値を知っておくと便利。")
print("以下の定数は代表的で、計算や常識チェックに役立つ。\n")
# ▼ 1. 光速 c
c = 3e8 # [m/s]
display(Math(r"c = 3 \times 10^8\ \mathrm{m/s} \quad \text{(speed of light in vacuum)}"))
print("真空中の光速 c ≒ 3.0 × 10^8 m/s\n")
# ▼ 2. アボガドロ定数 NA
NA = 6e23 # [/mol]
display(Math(r"N_\mathrm{A} = 6 \times 10^{23}\ \mathrm{/mol} \quad \text{(Avogadro's constant)}"))
print("アボガドロ定数 NA ≒ 6.0 × 10^23 /mol\n")
# ▼ 3. 重力加速度 g
g = 9.8 # [m/s^2]
display(Math(r"g = 9.8\ \mathrm{m/s^2} \quad \text{(acceleration due to gravity)}"))
print("地球上の重力加速度 g ≒ 9.8 m/s²\n")
# ▼ 4. 水の密度・融点・沸点
rho_water = 1 # [g/cm^3]
melting_point = 0 # [°C]
boiling_point = 100 # [°C]
display(Math(r"\rho_\mathrm{water} = 1\ \mathrm{g/cm^3}, \quad 0^\circ C \ (\text{melting}), \quad 100^\circ C \ (\text{boiling})"))
print("水の密度 ≒ 1 g/cm³, 融点 0°C, 沸点 100°C(標準大気圧)\n")
# ▼ 5. 音速の常識値
v_sound = 340 # [m/s]
print(f"音速は空気中で約 {v_sound} m/s 程度。3.5 m/s のような異常な値には注意が必要。\n")
# ▼ 6. 可視光の波長(目安)
lambda_min = 400 # [nm]
lambda_max = 800 # [nm]
display(Math(r"\lambda_\mathrm{visible} \approx 400 \sim 800\ \mathrm{nm} \quad \text{(visible light wavelength)}"))
print("可視光の波長はおおよそ 400~800 nm 程度。\n")
print("【注意】数値を扱うときは、その値が「もっともらしい」かを常に確認しましょう。")
print("たとえば、音速が3.5 m/sのように著しく外れていないか注意。\n")
from IPython.display import display, Math
import numpy as np
print("【近似式の基礎】")
print("微小量(たとえば x や y)が 0.01 や 0.001 のような小さな値のとき、")
print("式の中に出てくる x² や xy のような「2次以上の項」は非常に小さいため無視できます。")
print("よって 1次の項(x や y)だけを使った近似計算が有効です。\n")
# ▼ 1. (1 + x)(1 + y) ≈ 1 + x + y
x = 0.01
y = 0.02
lhs = (1 + x) * (1 + y)
rhs = 1 + x + y
print("【例1】(1 + x)(1 + y) ≈ 1 + x + y(xyを無視)")
print(f"(1 + {x}) * (1 + {y}) = {lhs:.5f}")
print(f"1 + {x} + {y} = {rhs:.5f}")
print(f"→ 誤差 = {abs(lhs - rhs):.5e}(十分小さいので近似成立)\n")
display(Math(r"(1 + x)(1 + y) \approx 1 + x + y"))
# ▼ 2. (1 + x)^n ≈ 1 + nx
n = 3
x = 0.03
approx2 = (1 + x)**n
near2 = 1 + n * x
print("【例2】(1 + x)^n ≈ 1 + nx(べき乗の近似)")
print(f"(1 + {x})^{n} = {approx2:.5f}")
print(f"1 + {n} × {x} = {near2:.5f}")
print("→ これはテイラー展開の初項と同じで、xが小さいほど精度が高い。\n")
display(Math(r"(1 + x)^n \approx 1 + nx"))
# ▼ 3. 1 / (1 + x) ≈ 1 - x
x = 0.05
lhs3 = 1 / (1 + x)
rhs3 = 1 - x
print("【例3】1 / (1 + x) ≈ 1 - x(逆数の近似)")
print(f"1 / (1 + {x}) = {lhs3:.5f}")
print(f"1 - {x} = {rhs3:.5f}")
print("→ x ≪ 1 のとき、分母が1+xでも逆数は 1−x で近似可能。\n")
display(Math(r"\frac{1}{1 + x} \approx 1 - x"))
# ▼ 4. (a + x)^n ≈ a^n (1 + nx/a)
a = 2.0
x = 0.02
n = -2
lhs4 = (a + x)**n
rhs4 = a**n * (1 + (n * x / a))
print("【例4】(a + x)^n ≈ a^n (1 + nx/a)(aに比べてxが小さい場合)")
print(f"({a} + {x})^{n} = {lhs4:.5f}")
print(f"{a}^{n}(1 + {n} × {x}/{a}) = {rhs4:.5f}")
print("→ xがaよりもずっと小さいとき、近似式が使える。\n")
display(Math(r"(a + x)^n \approx a^n \left(1 + \frac{nx}{a} \right)"))
# ▼ 5. 微小角近似:sinθ ≈ θ, cosθ ≈ 1, tanθ ≈ θ(θはラジアン)
theta_deg = 5
theta_rad = np.deg2rad(theta_deg)
sin_approx = np.sin(theta_rad)
print("【例5】微小角の三角関数近似(θ ≪ 1 [rad])")
print(f"θ = {theta_deg}° = {theta_rad:.5f} rad")
print(f"sin(θ) ≈ θ = {theta_rad:.5f}")
print(f"実際の sin(θ) = {sin_approx:.5f} → 誤差 = {abs(sin_approx - theta_rad):.5e}")
print("→ θが十分小さいとき、sinθ ≈ θ, tanθ ≈ θ, cosθ ≈ 1 が成り立つ。\n")
display(Math(r"\sin \theta \approx \theta,\quad \cos \theta \approx 1,\quad \tan \theta \approx \theta"))
print("【まとめ】")
print("・1次の微小量(0.01程度)なら近似可能。")
print("・2次(例: 0.01 × 0.01 = 0.0001)は無視できる。")
print("・(1 + 微小量) の形に変形してから近似するのがポイント。")
print("・角度は必ずラジアン単位にしてから近似式を使う!")
import numpy as np
import matplotlib.pyplot as plt
# xの範囲(微小領域に限定)
x = np.linspace(-0.2, 0.2, 400)
# ▼ 1. sqrt(1 + x) ≈ 1 + x/2
y_exact1 = np.sqrt(1 + x)
y_approx1 = 1 + x / 2
error1 = np.abs(y_exact1 - y_approx1) # 誤差計算
plt.figure()
plt.plot(x, y_exact1, label=r'$\sqrt{1 + x}$')
plt.plot(x, y_approx1, '--', label=r'$1 + \frac{x}{2}$ (approx)')
plt.title(r'Approximation: $\sqrt{1 + x} \approx 1 + \frac{x}{2}$')
plt.xlabel('x')
plt.ylabel('Value')
plt.legend()
plt.grid(True)
plt.show()
# 誤差表示
print("【1】sqrt(1 + x) ≈ 1 + x/2 の誤差(最大値):")
print(f"最大誤差: {np.max(error1):.5e}")
# ▼ 2. (1 + x)^n ≈ 1 + nx
n = 0.5
y_exact2 = (1 + x)**n
y_approx2 = 1 + n * x
error2 = np.abs(y_exact2 - y_approx2) # 誤差計算
plt.figure()
plt.plot(x, y_exact2, label=rf'$(1 + x)^{{{n}}}$')
plt.plot(x, y_approx2, '--', label=rf'$1 + {n}x$ (approx)')
plt.title(rf'Approximation: $(1 + x)^{{{n}}} \approx 1 + {n}x$')
plt.xlabel('x')
plt.ylabel('Value')
plt.legend()
plt.grid(True)
plt.show()
# 誤差表示
print("【2】(1 + x)^n ≈ 1 + nx の誤差(最大値):")
print(f"最大誤差: {np.max(error2):.5e}")
# ▼ 3. sin(θ) ≈ θ
theta = np.linspace(-0.3, 0.3, 400)
y_exact3 = np.sin(theta)
y_approx3 = theta
error3 = np.abs(y_exact3 - y_approx3) # 誤差計算
plt.figure()
plt.plot(theta, y_exact3, label=r'$\sin \theta$')
plt.plot(theta, y_approx3, '--', label=r'$\theta$ (approx)')
plt.title(r'Approximation: $\sin \theta \approx \theta$')
plt.xlabel(r'$\theta$ [rad]')
plt.ylabel('Value')
plt.legend()
plt.grid(True)
plt.show()
# 誤差表示
print("【3】sin(θ) ≈ θ の誤差(最大値):")
print(f"最大誤差: {np.max(error3):.5e}")
# ▼ 4. cos(θ) ≈ 1
y_exact4 = np.cos(theta)
y_approx4 = np.ones_like(theta)
error4 = np.abs(y_exact4 - y_approx4) # 誤差計算
plt.figure()
plt.plot(theta, y_exact4, label=r'$\cos \theta$')
plt.plot(theta, y_approx4, '--', label=r'$1$ (approx)')
plt.title(r'Approximation: $\cos \theta \approx 1$')
plt.xlabel(r'$\theta$ [rad]')
plt.ylabel('Value')
plt.legend()
plt.grid(True)
plt.show()
# 誤差表示
print("【4】cos(θ) ≈ 1 の誤差(最大値):")
print(f"最大誤差: {np.max(error4):.5e}")
ベクトル
import numpy as np
import matplotlib.pyplot as plt
# ベクトル A と B を定義
A = np.array([3, 2]) # ベクトル A
B = np.array([2, 4]) # ベクトル B
# ▼ 1. ベクトル A + B の合成
C = A + B
# 合成ベクトルの表示
print(f"【1】ベクトル A + B の合成")
print(f"ベクトル A: {A}")
print(f"ベクトル B: {B}")
print(f"ベクトル A + B の合成: C = {C}")
print(f"合成ベクトルの長さ |C| = {np.linalg.norm(C):.2f}\n")
# グラフの設定
plt.figure(figsize=(6, 6))
plt.quiver(0, 0, A[0], A[1], angles='xy', scale_units='xy', scale=1, color='r', label=r'$\mathbf{A}$')
plt.quiver(0, 0, B[0], B[1], angles='xy', scale_units='xy', scale=1, color='b', label=r'$\mathbf{B}$')
plt.quiver(0, 0, C[0], C[1], angles='xy', scale_units='xy', scale=1, color='g', label=r'$\mathbf{A} + \mathbf{B}$')
plt.xlim(-1, 6)
plt.ylim(-1, 6)
plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)
plt.grid(True)
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.title("Vector Addition: $\mathbf{A} + \mathbf{B}$")
plt.show()
# ▼ 2. ベクトル A を A と B に分解する
Ax = A[0] # A の x 成分
Ay = A[1] # A の y 成分
# 分解ベクトルの表示
print(f"【2】ベクトル A の分解")
print(f"ベクトル A の x 成分 (Ax): {Ax}")
print(f"ベクトル A の y 成分 (Ay): {Ay}\n")
# グラフの設定
plt.figure(figsize=(6, 6))
plt.quiver(0, 0, A[0], A[1], angles='xy', scale_units='xy', scale=1, color='r', label=r'$\mathbf{A}$')
plt.quiver(0, 0, Ax, 0, angles='xy', scale_units='xy', scale=1, color='c', label=r'$A_x$')
plt.quiver(0, 0, 0, Ay, angles='xy', scale_units='xy', scale=1, color='m', label=r'$A_y$')
plt.xlim(-1, 6)
plt.ylim(-1, 6)
plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)
plt.grid(True)
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.title("Vector Decomposition of $\mathbf{A}$ into $A_x$ and $A_y$")
plt.show()
# ▼ 3. 平行移動したベクトル B - A
B_minus_A = B - A # B - A
# 平行移動ベクトルの表示
print(f"【3】ベクトル B - A の平行移動")
print(f"ベクトル B: {B}")
print(f"ベクトル A: {A}")
print(f"ベクトル B - A: {B_minus_A}")
print(f"平行移動したベクトルの長さ |B - A| = {np.linalg.norm(B_minus_A):.2f}\n")
# グラフの設定
plt.figure(figsize=(6, 6))
plt.quiver(0, 0, A[0], A[1], angles='xy', scale_units='xy', scale=1, color='r', label=r'$\mathbf{A}$')
plt.quiver(0, 0, B[0], B[1], angles='xy', scale_units='xy', scale=1, color='b', label=r'$\mathbf{B}$')
plt.quiver(0, 0, B_minus_A[0], B_minus_A[1], angles='xy', scale_units='xy', scale=1, color='g', label=r'$\mathbf{B} - \mathbf{A}$')
plt.xlim(-1, 6)
plt.ylim(-1, 6)
plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)
plt.grid(True)
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.title("Vector Subtraction: $\mathbf{B} - \mathbf{A}$")
plt.show()
# ▼ 4. x, y 成分の分解(Ax, Ay)
# ベクトル A の x 成分と y 成分
print(f"【4】ベクトル A の x, y 成分分解")
print(f"ベクトル A の x 成分: {Ax}")
print(f"ベクトル A の y 成分: {Ay}\n")
# グラフの設定
plt.figure(figsize=(6, 6))
plt.quiver(0, 0, A[0], A[1], angles='xy', scale_units='xy', scale=1, color='r', label=r'$\mathbf{A}$')
plt.quiver(0, 0, Ax, 0, angles='xy', scale_units='xy', scale=1, color='c', label=r'$A_x$')
plt.quiver(0, 0, 0, Ay, angles='xy', scale_units='xy', scale=1, color='m', label=r'$A_y$')
plt.xlim(-1, 6)
plt.ylim(-1, 6)
plt.axhline(0, color='black',linewidth=1)
plt.axvline(0, color='black',linewidth=1)
plt.grid(True)
plt.gca().set_aspect('equal', adjustable='box')
plt.legend()
plt.title("Decomposition of $\mathbf{A}$ into Components $A_x$ and $A_y$")
plt.show()
Pythonコードでの再現
import numpy as np
import matplotlib.pyplot as plt
# 変化量の定理:y = ax から Δy = aΔx が成り立つ
a = 2 # 定数 a
x = np.linspace(0, 10, 100) # xの範囲
y = a * x # y = ax
dy = a * np.diff(x) # Δy = aΔx
# 1. y = ax のグラフ
plt.figure(figsize=(6, 6))
plt.plot(x, y, label=r'$y = ax$')
plt.title(r'Linear Relationship: $y = ax$')
plt.xlabel(r'$x$')
plt.ylabel(r'$y$')
plt.grid(True)
plt.legend()
plt.show()
# 2. 変化量の定理に従って Δy = aΔx を計算し、棒グラフを表示
plt.figure(figsize=(6, 6))
plt.bar(x[:-1], dy, width=0.1, color='orange', label=r'$\Delta y = a\Delta x$')
plt.title(r'Change in y: $\Delta y = a\Delta x$')
plt.xlabel(r'$x$')
plt.ylabel(r'$\Delta y$')
plt.grid(True)
plt.legend()
plt.show()
# 3. 直線グラフ:f(x) = kx の場合、積分による面積の計算
k = 3 # 定数 k
x_vals = np.linspace(0, 10, 100) # xの範囲
y_vals = k * x_vals # f(x) = kx
# グラフの表示
plt.figure(figsize=(6, 6))
plt.plot(x_vals, y_vals, label=r'$f(x) = kx$')
plt.fill_between(x_vals, 0, y_vals, alpha=0.2, color='skyblue', label='Area under curve')
plt.title(r'Area under $f(x) = kx$: $\int_0^x kx \, dx$')
plt.xlabel(r'$x$')
plt.ylabel(r'$f(x)$')
plt.grid(True)
plt.legend()
plt.show()
# 4. 棒グラフの合成(例:時間 vs 仕事)
time = np.linspace(0, 10, 100)
force = 3 * np.sin(time) # 力の時間に対する関係
work = np.cumsum(force) * (time[1] - time[0]) # 力積分による仕事
# グラフ表示
plt.figure(figsize=(6, 6))
plt.plot(time, work, label=r'Work: $\int F dt$')
plt.fill_between(time, 0, work, alpha=0.2, color='lightgreen', label='Area under curve')
plt.title(r'Work done by force: $\int_0^t F(t) dt$')
plt.xlabel(r'Time $t$')
plt.ylabel(r'Work')
plt.grid(True)
plt.legend()
plt.show()
# 5. xとyの積分関係に基づく平均
x_vals = np.linspace(0, 10, 100)
y1 = 2 * x_vals # y1 = 2x
y2 = 3 * x_vals # y2 = 3x
# 平均の計算
average_y = (y1 + y2) / 2
# グラフ表示
plt.figure(figsize=(6, 6))
plt.plot(x_vals, y1, label=r'$y_1 = 2x$')
plt.plot(x_vals, y2, label=r'$y_2 = 3x$')
plt.plot(x_vals, average_y, '--', label=r'$average \, y = \frac{y_1 + y_2}{2}$')
plt.title(r'Average of $y_1$ and $y_2$')
plt.xlabel(r'$x$')
plt.ylabel(r'$y$')
plt.grid(True)
plt.legend()
plt.show()
微分積分
import numpy as np
import matplotlib.pyplot as plt
# 時間の範囲
t = np.linspace(0, 10, 100) # 時間 [秒]
A = 2 # 定数 A (例: 振幅)
omega = 1 # 周波数 (角周波数)
theta0 = 0 # 初期位相
# 速度の計算: v = dx/dt
# 単振動の式: x = A * sin(omega * t + theta0)
x = A * np.sin(omega * t + theta0)
v = np.gradient(x, t) # dx/dt
# 加速度の計算: a = dv/dt
a = np.gradient(v, t) # dv/dt
# 速度と加速度を表示するためのプロット
plt.figure(figsize=(8, 6))
plt.subplot(2, 1, 1)
plt.plot(t, v, label=r"$v = \frac{dx}{dt}$ (Velocity)", color='r')
plt.title("Velocity vs Time")
plt.xlabel("Time [s]")
plt.ylabel("Velocity [m/s]")
plt.grid(True)
plt.legend()
plt.subplot(2, 1, 2)
plt.plot(t, a, label=r"$a = \frac{dv}{dt}$ (Acceleration)", color='b')
plt.title("Acceleration vs Time")
plt.xlabel("Time [s]")
plt.ylabel("Acceleration [m/s²]")
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
# 速度と加速度の最大値
print(f"最大速度: {np.max(v):.2f} m/s")
print(f"最大加速度: {np.max(a):.2f} m/s²")
# 2. v-tグラフにおける傾き(加速度の意味)を確認するための積分
# v = dx/dt において、面積は距離(x)を表す
distance = np.cumsum(v) * (t[1] - t[0]) # 距離の積分
# 距離のプロット
plt.figure(figsize=(8, 6))
plt.plot(t, distance, label=r"$\int v \, dt$ (Distance)", color='g')
plt.title("Distance vs Time")
plt.xlabel("Time [s]")
plt.ylabel("Distance [m]")
plt.grid(True)
plt.legend()
plt.show()
# 3. 物理的な事例:電流と電気量の関係
# 電流 I = dQ/dt から、電気量 Q は積分で得られる
# I = 2 * np.sin(t) と仮定(周期的な変化)
I = 2 * np.sin(t) # 電流
Q = np.cumsum(I) * (t[1] - t[0]) # 電気量の積分
# 電気量のプロット
plt.figure(figsize=(8, 6))
plt.plot(t, Q, label=r"$\int I \, dt$ (Charge)", color='purple')
plt.title("Charge vs Time")
plt.xlabel("Time [s]")
plt.ylabel("Charge [C]")
plt.grid(True)
plt.legend()
plt.show()
# 電流の最大値と電気量の最大値
print(f"最大電流: {np.max(I):.2f} A")
print(f"最大電気量: {np.max(Q):.2f} C")