Category: SymPy & SPB
from sympy.abc import * する際の順番と追記事項
sympy.abc のコードには,
Caveats ======= 1. As of the time of writing this, the names ``O``, ``S``, ``I``, ``N``, ``E``, and ``Q`` are colliding with names defined in SymPy. If you import them from both ``sympy.abc`` and ``sympy``, the second import will "win". This is an issue only for * imports, which should only be used for short-lived code such as interactive sessions and throwaway scripts that do not survive until the next SymPy upgrade, where ``sympy`` may contain a different set of names.
とある。また,sympy.abc にはギリシャ文字の大文字が定義されていない。したがって,今後は以下のようにしたらどうか,というメモ。 続きを読む
SymPy Plotting Backends で少し込み入った関数をplotするときのエラー対応
SymPy Plotting Backends で”少し込み入った関数”を plot() するとき,思いもかけずにエラーとなった場合の対応。
以下の Issue で回答があった件:
高さ h からの斜方投射の最大水平到達距離を陰関数定理を使って求める
「高さ h からの斜方投射の最大到達距離を求める準備」のページを参照。
最大水平到達距離となる打ち出し角度 $\theta$ を,陰関数定理を使い,連立方程式の形にして SymPy や Maxima を使って求めてみる。 続きを読む
SymPy Plotting Backends で電場ベクトルの方向場を描く
正負の点電荷がつくる電場の向きを表す方向場を Python の SymPy Plotting Backends (SPB) で描く。
Python によるグラフ作成 SymPy Plotting Backends 編
Python を使って,関数のグラフを描くことができます。また,数値データもグラフにすることができます。
Python の2次元グラフ作成は matplotlib.pyplot.plot() でもできますが,ここでは,SymPy Plotting Backends (SPB) について説明します。
SPB でプロットできるオブジェクトは以下のとおりです。
- 陽関数 $y = f(x)$:
plot(f(x), (x, xmin, xmax))
- 陰関数 $f(x, y) = 0$:
plot_implicit(f(x, y), (x, xmin, xmax), (y, ymin, ymax))
- 媒介変数表示 $x(t), y(t)$:
plot_parametric(x(t), y(t), (t, tmin, tmax))
- 点,$x$ 座標 $y$ 座標の数値データ:
plot_list([x1, ..., xn], [y1, ..., yn])
- ベクトル
ax.quiver(X, Y, Vx, Vy)
また,2本の陽関数で挟まれた領域などを塗りつぶすこともできます。
SymPy Plotting Backends で正規分布をσごとに塗りわける
「gnuplot で正規分布をσごとに塗りわける」の SymPy Plotting Backends 版。
以下を参考に,標準正規分布がもつ確率密度関数のグラフを描いてみる。