25

MatLabでは、シンボルを非常に簡単に宣言できます。

syms a,b
mat = [a,b]

ただし、これをOctaveで複製しようとすると、エラーが発生します。これは私が使用しているコードです:

> symbols
> a = sym("a")
a =

a
> b = sym("b")
b =

b
> mat = [a,b]
error: octave_base_value::resize (): wrong type argument `ex'
error: octave_base_value::resize (): wrong type argument `<unknown type>'
octave-3.2.3.exe:4:C:\Octave\3.2.3_gcc-4.4.0\bin

オクターブでシンボリック行列をどのように宣言しますか?

4

6 に答える 6

17

シンボリック パッケージをまだ持っていない場合は、ダウンロードします。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(θ)    ⎦
于 2016-03-09T05:30:22.070 に答える
9

これは役に立ちますか?

シンボリック ツールボックス パッケージが必要なようです。こちらを参照してください。

于 2010-04-07T21:56:19.570 に答える
7

シンボリック ツールボックスをインストールした後 (一部の環境では を発行して実行できますsudo apt-get install octave-symbolic)、次の手順を実行する必要があります。

symbols
x = sym('x')

しかし、シンボリック式を操作するための Octave の関数は、MATLAB の関数よりもはるかに悪いことに注意してください。

于 2013-02-28T23:09:28.897 に答える
1

Octave の Symbolic Toolbox は多かれ少なかれ役に立ちません。あなたの場合のように行列のサイズを変更することはできません。「-」演算子は使用できません。たとえば、単純な記号演算を区別できます。

octave:1> symbols
octave:2> q1 = sym("q1");
octave:3> differentiate(Sin(q1)*Cos(q1),q1)
ans =

-sin(q1)^2+cos(q1)^2

しかし、これをやろうとすると:

octave:6> -Sin(q1)
error: unary operator `-' not implemented for `ex' operands
octave:6> -q1
error: unary operator `-' not implemented for `ex' operands

あなたの場合も同じことが起こります。つまり、シンボリック値を含む行列のサイズを変更します

于 2015-01-08T10:23:10.540 に答える
0

ハンドルの配列

Octave Struct Arrayを使用して、次のような記号行列を作成できます。

b(1,1).vector = @sin;
b(1,2).vector = @cos;
b(2,1).vector = @sec;
b(2,2).vector = @csc;

b
b.vector

printf( "\n\nCalling each element:\n" )
b(1,1).vector
b(1,2).vector
b(2,1).vector
b(2,2).vector

printf( "\nCalculatin the sin of 1:\n" )
b(1,1).vector(1)

上記を実行すると、以下が返されます。

b =

  2x2 struct array containing the fields:

    vector

ans = @sin
ans = @sec
ans = @cos
ans = @csc


Calling each element:
ans = @sin
ans = @cos
ans = @sec
ans = @csc

Calculatin the sin of 1:
ans =  0.841470984807897

シンボルの配列

、 などを、@sin、などに置き換えることができます。@cossym("a")sym("b")sym("c")

pkg load symbolic;

b(1,1).vector = sym("a");
b(1,2).vector = sym("b");
b(2,1).vector = sym("c");
b(2,2).vector = sym("d");

b
b.vector

printf( "\n\nCalling each element:\n" )
b(1,1).vector
b(1,2).vector
b(2,1).vector
b(2,2).vector

上記を実行すると、以下が返されます。

b =

  2x2 struct array containing the fields:

    vector

ans = (sym) a
ans = (sym) c
ans = (sym) b
ans = (sym) d


Calling each element:
ans = (sym) a
ans = (sym) b
ans = (sym) c
ans = (sym) d

参考文献:

  1. https://www.gnu.org/software/octave/doc/v4.0.0/Structure-Arrays.html
  2. http://mattpap.github.io/scipy-2011-tutorial/html/installing.html
  3. https://github.com/cbm755/octsympy
  4. https://askubuntu.com/questions/737746/installing-symbolic-package-in-octave
  5. https://github.com/sympy/sympy
于 2016-11-26T23:18:57.427 に答える