ばねAとばねBの交点を行列で求める(単位付き)
■ 問題の背景
グラフから、2本のばねA・Bの**長さ(cm)**が、**重さ(g)**に応じて一次的に変化していることがわかります。
それぞれの関係式は次のような形です:
$$
\begin{aligned}
\text{ばねA: } & y = a_1 x + b_1 \
\text{ばねB: } & y = a_2 x + b_2
\end{aligned}
$$
- $x$: 重さ [g](入力)
- $y$: ばねの長さ [cm](出力)
- $a_1, a_2$: のび率 [cm/g]
- $b_1, b_2$: 自然長(無負荷状態の長さ)[cm]
■ 交点の導出
2本のばねの長さが等しくなるとき:
$$
a_1 x + b_1 = a_2 x + b_2
\Rightarrow x = \frac{b_2 - b_1}{a_1 - a_2}
$$
このときの長さ $y$ は:
$$
y = a_1 x + b_1 = a_1 \cdot \frac{b_2 - b_1}{a_1 - a_2} + b_1
$$
■ 行列で表す
連立方程式:
$$
\begin{cases}
-a_1 x + y = b_1 \
-a_2 x + y = b_2
\end{cases}
$$
行列形式:
$$
\begin{bmatrix}
-a_1 & 1 \
-a_2 & 1
\end{bmatrix}
\begin{bmatrix}
x \
y
\end{bmatrix}
\begin{bmatrix}
b_1 \
b_2
\end{bmatrix}
$$
■ Pythonコードによる交点の計算
# Program Name: spring_intersection_solver.py
# Creation Date: 20250721
# Overview: Solve for the intersection of two spring extension lines using linear algebra
# Usage: Run to compute intersection point (weight x and length y) where spring A and B are equal
import numpy as np
# すべての数値・単位は変数で管理
# 単位: [cm] for length, [g] for weight
a1 = 0.3 # ばねAののび率 [cm/g]
b1 = 10.0 # ばねAの自然長 [cm]
a2 = 0.5 # ばねBののび率 [cm/g]
b2 = 5.0 # ばねBの自然長 [cm]
# 係数行列と定数ベクトル / Coefficient matrix and RHS vector
A = np.array([[-a1, 1],
[-a2, 1]])
b = np.array([b1, b2])
# 連立方程式を解く / Solve the linear system
solution = np.linalg.solve(A, b)
x, y = solution
# 結果表示 / Output result
print(f"Intersection Point (Weight x, Length y): ({x:.2f} g, {y:.2f} cm)")
■ 出力結果(例)
Intersection Point (Weight x, Length y): (25.00 g, 17.50 cm)
■ まとめ
- 式を行列化すれば複雑な交点も一般化して計算できる
- Pythonの
numpy.linalg.solve
で簡潔に解ける - グラフの交点は「物理量の一致点」で、実験・構造設計・物性評価などにも応用可能
必要に応じてグラフ描画や他条件追加も可能です。希望があれば追記対応できます。