ChatGPTにお願いして、3変数の一次方程式のグラフを書いてもらいました。
方程式は3本あり、(自明な)解もプロットしてあります。
plotlyパッケージを使っているため動かせます。
内容
import numpy as np import plotly.graph_objects as go # 連立方程式の係数行列 A と定数ベクトル B A = np.array([[1, 2, 1], [2, 3, 3], [-1, 1, 4]]) B = np.array([0, 0, 0]) # 未知変数ベクトルの値域を指定 x_range = np.linspace(-10, 10, 100) y_range = np.linspace(-10, 10, 100) # 未知変数の値域で方程式を解く X, Y = np.meshgrid(x_range, y_range) Z1 = (-A[0, 0] * X - A[0, 1] * Y + B[0]) / A[0, 2] Z2 = (-A[1, 0] * X - A[1, 1] * Y + B[1]) / A[1, 2] Z3 = (-A[2, 0] * X - A[2, 1] * Y + B[2]) / A[2, 2] # 連立方程式の解(交点)の座標 solution = np.linalg.solve(A, B) solution_x = solution[0] solution_y = solution[1] solution_z = solution[2] # グラフのデータ作成 surface1 = go.Surface(x=X, y=Y, z=Z1, showscale=False, opacity=0.5, colorscale='Reds') surface2 = go.Surface(x=X, y=Y, z=Z2, showscale=False, opacity=0.5, colorscale='Blues') surface3 = go.Surface(x=X, y=Y, z=Z3, showscale=False, opacity=0.5, colorscale='Greens') scatter = go.Scatter3d(x=[solution_x], y=[solution_y], z=[solution_z], mode='markers', marker=dict(color='red', size=5), name='Intersection') # レイアウト設定 layout = go.Layout(scene=dict(xaxis_title='x1', yaxis_title='x2', zaxis_title='x3'), showlegend=True) # グラフの描画 fig = go.Figure(data=[surface1, surface2, surface3, scatter], layout=layout) fig.show()
結果