Ask Your Question
1

How to do symbolic computation with quaternions

asked 2013-01-22 03:37:05 +0100

Gilles Falquet gravatar image

I need to do symbolic computations with quaternions. Ideally I'd like to enter something like

Q.<i,j,k> = QuaternionAlgebra(QQ,-1,-1)
a=var('a')
b=var('b')
c=var('c')
q = a*i+b*j+c*k

But it doesn't work : TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'Quaternion Algebra (-1, -1) with base ring Rational Field'

Looks like SAGE doesn't know how to multiply a variable and a quaternion. Or should I specify the types of the variables ? How ?

Thanks for your help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
5

answered 2013-01-22 14:00:21 +0100

benjaminfjones gravatar image

You should define Q as a QuaternionAlgebra over the symbolic ring SR instead of over the rationals:

sage: Q.<i,j,k> = QuaternionAlgebra(SR, -1, -1)
sage: q = a*i + b*j + c*k
sage: q
a*i + b*j + c*k
sage: q^2
-a^2 - b^2 - c^2
edit flag offensive delete link more
0

answered 2015-07-31 03:24:24 +0100

uutzinger gravatar image

updated 2015-07-31 03:24:53 +0100

N.<c,d,a1,a2,a3,a4,b1,b2,b3,b4,s> = QQ[]
H.<i,j,k> = QuaternionAlgebra(c,d)
a = a1 + a2 * i + a3 * j + a4 * k
b = b1 + b2 * i + b3 * j + b4 * k
a+b
a*b

From http://www.wstein.org/edu/2010/414/pr...

Seems to give better results

Now I just need to figure out how to define vector and rotate it with quaternion.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-01-22 03:37:05 +0100

Seen: 2,446 times

Last updated: Jul 31 '15