如果您还没有符号包,请下载它。从 Octave 命令行或 gui 命令行。例如
octave> pkg install -forge symbolic
如果您安装了 python 和 sympy,它将从 octave forge 为您安装软件包。我用谷歌来弄清楚如何安装 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(θ) ⎦