0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(途中)2025 中部大学 様の数学の1問「四角形の面積の最小値」ChatGPT先生に聞きました。(その2/4) scipyで。

Last updated at Posted at 2025-12-22

(その1/4) sympyで。
(その2/4) 本ページ
(その3/4) 81通り(=3^4)で。
(その4/4 作成中)

・scipyで。私は、sympyを指定していません。

(本日の)ChatGPT先生へ

以下を,scipyを使って解いて下さい。
(問題文省略)
一つにして下さい。

回答抜粋
(Chromebook + SciPy 実行前提で、そのまま動くコードです)
以下が 完全統合コード です。

# ver2.1
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize_scalar

# --- 基本点 ---
A = np.array([0.0, 0.0])
B = np.array([8.0, 0.0])
C = np.array([5*np.cos(np.pi/3), 5*np.sin(np.pi/3)])

# --- 可動点 ---
def D(x):
    return np.array([x/2, np.sqrt(3)*x/2])

def E(x):
    return np.array([8-2*x, 0])

# --- 多角形面積(靴紐公式) ---
def polygon_area(P):
    x, y = P[:,0], P[:,1]
    return 0.5*np.abs(np.dot(x,np.roll(y,-1))-np.dot(y,np.roll(x,-1)))

# --- 面積関数 ---
def S(x):
    P = np.array([C, D(x), E(x), B])
    return polygon_area(P)

# --- 最小値探索 ---
res = minimize_scalar(S, bounds=(0,4), method='bounded')

print("最小となる x =", res.x)
print("最小値 S(x) =", res.fun)

# --- グラフ ---
xs = np.linspace(0,4,400)
ys = [S(x) for x in xs]

plt.figure()
plt.plot(xs, ys)
plt.scatter([4],[S(4)])
plt.xlabel("x")
plt.ylabel("S(x)")
plt.grid()
plt.title("Area S(x)")
plt.show()

000.png

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

Qiita内

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?