シンボリック パッケージをまだ持っていない場合は、ダウンロードします。Octave コマンド ラインまたは gui コマンド ラインから。例えば
octave> pkg install -forge symbolic
Python と sympy がインストールされている場合は、octave forge からパッケージがインストールされます。Google を使用して sympy をインストールする方法を見つけました。助けが必要な場合は私に連絡してください。
シンボリック パッケージがインストールされている状態で、"pkg load" を使用してパッケージ関数をインポートし、syms 関数を使用してシンボルを宣言します。
octave> pkg load symbolic
octave> syms a b
これにより、シンボル a と b が定義されました。
octave> syms
Symbolic variables in current scope:
a
b
「syms」自体は、定義したすべてのシンボルを出力します。
octave> mat = [a,b]
mat = (sym) [a b] (1×2 matrix)
octave:34> mat * 2
ans = (sym) [2⋅a 2⋅b] (1×2 matrix)
このパッケージは、私の Robotic Manipulators クラスの回転行列を計算するのに非常に役立ちました。お役に立てれば。
他の例のスクリプトの一部を次に示します。
pkg load symbolic
syms psi phi theta psidot phidot thetadot
RzPsi = [[cos(psi), -sin(psi), 0]; [sin(psi), cos(psi), 0]; [0,0,1]]
RyTheta = [[cos(theta), 0, sin(theta)];[0,1,0];[-sin(theta), 0, cos(theta)]]
RzPhi = [[cos(phi), -sin(phi), 0]; [sin(phi), cos(phi), 0]; [0,0,1]]
RzPsi = (sym 3×3 matrix)
⎡cos(ψ) -sin(ψ) 0⎤
⎢ ⎥
⎢sin(ψ) cos(ψ) 0⎥
⎢ ⎥
⎣ 0 0 1⎦
RyTheta = (sym 3×3 matrix)
⎡cos(θ) 0 sin(θ)⎤
⎢ ⎥
⎢ 0 1 0 ⎥
⎢ ⎥
⎣-sin(θ) 0 cos(θ)⎦
RzPhi = (sym 3×3 matrix)
⎡cos(φ) -sin(φ) 0⎤
⎢ ⎥
⎢sin(φ) cos(φ) 0⎥
⎢ ⎥
⎣ 0 0 1⎦
octave> RzPhi * RyTheta
ans = (sym 3×3 matrix)
⎡cos(φ)⋅cos(θ) -sin(φ) sin(θ)⋅cos(φ)⎤
⎢ ⎥
⎢sin(φ)⋅cos(θ) cos(φ) sin(φ)⋅sin(θ)⎥
⎢ ⎥
⎣ -sin(θ) 0 cos(θ) ⎦