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?

複素数平面「(その3/4)【1問多解】2025年 京都大(理系) 複素数の絶対値の最大・最小」様ををAI先生へ、xy平面を使った問題文に書き換えて下さい。

Last updated at Posted at 2025-04-10

・???(本日の)ChatGPT先生。いつも以上に気合が入っていました。
 作図がステキ。 アニメーションのコードは、実行していません。
・???mathjaxを教えてもらいましたが、私はわかりませんでした。

(再出)オリジナル

・問題文(mathjax テキスト形式)
 大学入試数学問題集成 様。いつもお世話になっております。
 2025 京都大学 前期MathJax理系【1】問1
 https://mathexamtest.web.fc2.com/2025/202510541/2025105410100mj.html
 https://mathexamtest.web.fc2.com/daigakubetumj/10541index.html#y2025

(本日の)ChatGPT先生へ

下記の複素数平面の問題文そのものをxy平面を使った問題文に書き換えて下さい。
<div class="qbody">
<p class="slevel"><a name="q-0101" 
id="q-0101"></a><span 
class="qnum">【1】</span> 次の各問に答えよ.</p>
<a name="s-0101" id="s-0101"></a><p class="s1level"><span 
class="shomon1">問1</span> <math>
<mi>i</mi><mspace width=".2em"></mspace>
</math>は虚数単位とする.複素数<math>
<mspace width=".2em"></mspace><mi>z</mi><mspace width=".2em"></mspace>
</math>が,絶対値が<math>
<mspace width=".2em"></mspace><mn>2</mn><mspace width=".2em"></mspace>
</math>である複素数全体を動くとき,<math>
<mrow><mo rspace=".2em">|</mo><mi>z</mi>
<mo>−</mo><mstyle displaystyle="true"><mfrac><mi>i</mi><mi>z</mi>
</mfrac></mstyle><mo lspace=".2em" rspace=".2em">|</mo></mrow>
</math>の最大値と最小値を求めよ.
</p>

質問リスト

・質問リストの追番は無視して下さい。1個ずつです。
 途中の回答表示は省略しています。

# 質問リスト
1. 下記の複素数平面の問題文そのものをxy平面を使った問題文に書き換えて下さい。  
2. 上記をmathjax形式でお願いします。  
3. 上記をsympy のソースコードで教えて下さい。  
4. 欲しいです。  
5. 興味あります。  
6. 停止の作図をお願いします。  
7. まず一枚作図して下さい。  
8. 私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。  
9. 追番を追加して。本コメントも含めて下さい。

・上記をmathjaxのソースコードで教えて下さい。

<div class="qbody"> <p class="slevel"><a name="q-0101" id="q-0101"></a><span class="qnum">【1】</span> 次の各問に答えよ.</p> <a name="s-0101" id="s-0101"></a><p class="s1level"><span class="shomon1">問1</span> xy平面上で、原点を中心とする半径2の円周上を動く点 \( P \) の座標を \( (x, y) \) とする。 このとき、点 \( P \) に対して定まる点 \( Q \) の座標を \[ Q = \left( \frac{y}{x^2 + y^2},\ -\frac{x}{x^2 + y^2} \right) \] とする。点 \( P \) と点 \( Q \) の距離 \[ |PQ| = \sqrt{\left(x - \frac{y}{x^2 + y^2}\right)^2 + \left(y + \frac{x}{x^2 + y^2}\right)^2} \] の最大値と最小値を求めよ。 </p>

・上記をsympy のソースコードで教えて下さい。

from sympy import symbols, cos, sin, simplify, sqrt, diff, solve, pi, Eq, Max, Min
from sympy import lambdify, N

# 変数定義
theta = symbols('theta', real=True)

# 点Pの座標(半径2の円周上)
x = 2 * cos(theta)
y = 2 * sin(theta)

# 点Qの座標
xq = y / (x**2 + y**2)
yq = -x / (x**2 + y**2)

# 距離PQ
PQ_squared = (x - xq)**2 + (y - yq)**2
PQ = simplify(sqrt(PQ_squared))

# 微分して臨界点を求める
dPQ = diff(PQ, theta)
critical_points = solve(Eq(dPQ, 0), theta)

# 区間[0, 2π]で評価する点(臨界点と周期端点)
eval_points = [0, pi, 2*pi] + critical_points

# 数値評価して最大・最小を求める
f = lambdify(theta, PQ, 'numpy')
values = [(pt, N(PQ.subs(theta, pt))) for pt in eval_points if pt.is_real]

# 最大・最小を抽出
max_val = max(values, key=lambda x: x[1])
min_val = min(values, key=lambda x: x[1])

# 結果表示
print("PQ =", PQ)
print("最大値:", max_val)
print("最小値:", min_val)

このコードを実行すると、最大値・最小値とそれが出現する角度が得られます。必要であればプロット付きの可視化バージョンも作れますよ。欲しいですか?

import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols, cos, sin, simplify, sqrt, lambdify

# シンボリック変数
theta = symbols('theta', real=True)

# 点Pの座標(半径2の円周上)
x = 2 * cos(theta)
y = 2 * sin(theta)

# 点Qの座標(z = x + iy に対して z の逆数の虚部)
xq = y / (x**2 + y**2)
yq = -x / (x**2 + y**2)

# 距離PQの式
PQ = simplify(sqrt((x - xq)**2 + (y - yq)**2))

# 数値関数に変換
PQ_func = lambdify(theta, PQ, modules=['numpy'])

# グラフ描画用に theta を 0 から 2π までとる
theta_vals = np.linspace(0, 2*np.pi, 1000)
PQ_vals = PQ_func(theta_vals)

# 最大値・最小値の位置と値
max_idx = np.argmax(PQ_vals)
min_idx = np.argmin(PQ_vals)

# グラフを描画
plt.figure(figsize=(10, 6))
plt.plot(theta_vals, PQ_vals, label=r'$|PQ|$', color='blue')
plt.scatter(theta_vals[max_idx], PQ_vals[max_idx], color='red', label='Max')
plt.scatter(theta_vals[min_idx], PQ_vals[min_idx], color='green', label='Min')
plt.title(r'Distance $|PQ|$ vs. $\theta$ on the circle $|z| = 2$')
plt.xlabel(r'$\theta$ (radians)')
plt.ylabel(r'$|PQ|$')
plt.legend()
plt.grid(True)
plt.show()

もっと見やすくしたり、円上のPとQの動きをアニメーションで見たいなどもできますよ。興味ありますか?

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

# パラメータ
r = 2  # 円の半径
theta_vals = np.linspace(0, 2 * np.pi, 360)  # 1周分

# 点PとQの軌跡を計算
xP = r * np.cos(theta_vals)
yP = r * np.sin(theta_vals)
denom = xP**2 + yP**2
xQ = yP / denom
yQ = -xP / denom

# アニメーションの準備
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_aspect('equal')
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_title("Motion of Points P and Q")
ax.grid(True)

# 描画要素
circle = plt.Circle((0, 0), r, color='lightgray', fill=False, linestyle='--')
pointP, = ax.plot([], [], 'bo', label='P (on circle)')
pointQ, = ax.plot([], [], 'ro', label='Q')
linePQ, = ax.plot([], [], 'k-', lw=1, label='Line PQ')
traceQ, = ax.plot([], [], 'r--', lw=0.5, alpha=0.5, label='Trace of Q')

# Qの軌跡を保存
xQ_trace = []
yQ_trace = []

def init():
    ax.add_patch(circle)
    pointP.set_data([], [])
    pointQ.set_data([], [])
    linePQ.set_data([], [])
    traceQ.set_data([], [])
    return pointP, pointQ, linePQ, traceQ

def update(frame):
    x_p, y_p = xP[frame], yP[frame]
    x_q, y_q = xQ[frame], yQ[frame]
    xQ_trace.append(x_q)
    yQ_trace.append(y_q)

    pointP.set_data(x_p, y_p)
    pointQ.set_data(x_q, y_q)
    linePQ.set_data([x_p, x_q], [y_p, y_q])
    traceQ.set_data(xQ_trace, yQ_trace)

    return pointP, pointQ, linePQ, traceQ

ani = animation.FuncAnimation(
    fig, update, frames=len(theta_vals),
    init_func=init, blit=True, interval=30, repeat=True
)

plt.legend()
plt.show()

停止の作図をお願いします。
📌 静止画バージョン:PとQの位置、Qの軌跡、PQの線分の作図

import numpy as np
import matplotlib.pyplot as plt

# パラメータ
r = 2  # 半径
theta_vals = np.linspace(0, 2 * np.pi, 360)

# 円周上の点P
xP_vals = r * np.cos(theta_vals)
yP_vals = r * np.sin(theta_vals)

# Qの座標(zの逆数にiをかけたもの)
denom = xP_vals**2 + yP_vals**2
xQ_vals = yP_vals / denom
yQ_vals = -xP_vals / denom

# 表示する角度(例えば θ = π/4)
index = 45  # θ = π/4 の近く(360分割で45番目)
xP = xP_vals[index]
yP = yP_vals[index]
xQ = xQ_vals[index]
yQ = yQ_vals[index]

# 作図
fig, ax = plt.subplots(figsize=(6, 6))
ax.set_aspect('equal')
ax.set_xlim(-3, 3)
ax.set_ylim(-3, 3)
ax.set_title("Static Plot: Points P and Q, and Path of Q")
ax.grid(True)

# 円
circle = plt.Circle((0, 0), r, color='lightgray', fill=False, linestyle='--')
ax.add_patch(circle)

# 点Pと点Q
ax.plot(xP, yP, 'bo', label='P')
ax.plot(xQ, yQ, 'ro', label='Q')

# 線分PQ
ax.plot([xP, xQ], [yP, yQ], 'k-', label='Line PQ')

# Qの軌跡
ax.plot(xQ_vals, yQ_vals, 'r--', lw=0.8, alpha=0.6, label='Trace of Q')

# 原点
ax.plot(0, 0, 'ko', markersize=4)

# 凡例
ax.legend()
plt.show()

まず一枚作図して下さい。

データ分析の制限に達しました。

vscodeの実行結果
111.png

Gemini先生へ

copilot先生へ

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

(テンプレート)

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

Qiita内

>MathMLの勉強を開始

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?