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?

「2変数2階偏微分方程式の標準形への変形法を教えて下さい。」をAI先生に聞きました。sympyのソースコードで。

Posted at

(本日の)ChatGPT先生へ

質問リスト

# 質問リスト
1. 2変数2階偏微分方程式の標準形への変形法を教えて下さい。
2. 波動方程式をsympy のソースコードで教えて下さい。
3. グラフ表示を教えて下さい。
4. アニメーションを教えて下さい。
5. 私の質問をMarkdown形式でリスト化して出力して。Markdown形式でリストからアスタリスクは削除して。1行目に、# 質問リスト の文字を出力して。最後の質問も追加して下さい。追番を追加して下さい。Markdown形式で。

(回答抜粋)

  1. 一般形の2変数2階線形偏微分方程式
  2. 分類(判別式)
    ・楕円型(Elliptic):  $D < 0$(例:ラプラス方程式)
    ・放物型(Parabolic): $D = 0$(例:熱方程式)
    ・双曲型(Hyperbolic): $D > 0$(例:波動方程式)
  3. 標準形への変換
  4. 例(波動方程式)
    SymPy を使って 1次元波動方程式 を表現し、変数変換して標準形に変えるソースコードは以下の通りです。
from sympy import symbols, Function, diff, simplify
from sympy.abc import x, t

# 1. 未知関数 u(x, t)
u = Function('u')(x, t)

# 2. 波動方程式の定義: ∂²u/∂t² - c²∂²u/∂x² = 0
c = symbols('c', positive=True)
wave_eq = diff(u, t, 2) - c**2 * diff(u, x, 2)

print("波動方程式:")
print(wave_eq)

■ 変数変換:ξ = x - ct, η = x + ct による標準形への変換

# 3. 新しい変数の定義
xi, eta = symbols('xi eta')
u_new = Function('U')(xi, eta)  # U(ξ,η)

# 4. x = (η + ξ)/2, t = (η - ξ)/(2c) による逆変換
x_expr = (eta + xi)/2
t_expr = (eta - xi)/(2*c)

# 5. u(x,t) を U(ξ,η) で表現
# ∂²u/∂t² - c²∂²u/∂x² を ξ, η に変換
from sympy import diff

# U(ξ,η) を x, t に引き戻して連鎖律適用
Ux = diff(u_new.subs({xi: x - c*t, eta: x + c*t}), x, 2)
Ut = diff(u_new.subs({xi: x - c*t, eta: x + c*t}), t, 2)
wave_transformed = simplify(Ut - c**2 * Ux)

print("\n変数変換後の波動方程式(標準形):")
print(wave_transformed)

出力例(簡略化):

波動方程式:
Derivative(u(x, t), t, t) - c**2*Derivative(u(x, t), x, x)

変数変換後の波動方程式(標準形):
4*c**2*Derivative(U(x - c*t, x + c*t), (x - c*t), (x + c*t))

...
■ 波動方程式の解のアニメーション(Pythonコード)
(省略)

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

# パラメータ
c = 1.0  # 波の速さ
x = np.linspace(-10, 10, 400)  # 空間範囲
t_max = 10  # アニメーションの長さ(時間)
frames = 100  # フレーム数

# 波動方程式の具体解(例):u(x,t) = sin(x - ct) + cos(x + ct)
def u(x, t):
    return np.sin(x - c * t) + np.cos(x + c * t)

# グラフの初期設定
fig, ax = plt.subplots()
line, = ax.plot(x, u(x, 0))
ax.set_ylim(-2, 2)
ax.set_xlim(x[0], x[-1])
ax.set_title("波動方程式のアニメーション")
ax.set_xlabel("x")
ax.set_ylabel("u(x, t)")
ax.grid(True)

# フレームごとの更新関数
def update(frame):
    t = t_max * frame / frames
    line.set_ydata(u(x, t))
    ax.set_title(f"t = {t:.2f}")
    return line,

# アニメーション作成
ani = FuncAnimation(fig, update, frames=frames, blit=True, interval=50)

plt.show()

Gemini先生へ

copilot先生へ

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

(テンプレート)

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

wikipedia

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?