On May 27, 2:29 pm, "Mateusz Paprocki" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> to improve computations speed in case of symbolic matrices (as g_dd
> is) it would be convenient to use M.berkowitz_det() rather that
> M.det():
>
> [EMAIL PROTECTED] ~/hg/sympy $ SYMPY_USE_CACHE=no ./bin/isympy -q
> Python 2.5.2 console for SymPy 0.5.15-hg (cache: off)
>
> In [1]: var("t omega")
> Out[1]: (t, ω)
>
> In [2]: g_dd = Matrix([(-1+omega*(x**2+y**2),2*omega*y,-2*omega*x,0),
> ...: (2*omega*y, 1, 0, 0), (-2*omega*x, 0, 1, 0), (0, 0, 0, 1)])
>
> In [3]: time a = g_dd.berkowitz_det()
> CPU times: user 0.26 s, sys: 0.00 s, total: 0.27 s
> Wall time: 0.28 s
>
> In [5]: time b = g_dd.det()
> CPU times: user 6.99 s, sys: 0.06 s, total: 7.04 s
> Wall time: 7.19 s
>
> In [7]: a == b
> Out[7]: True
Indeed. I sent patches for a review, please review them.
I can now do this:
t=Symbol("t")
x=Symbol("x")
y=Symbol("y")
z=Symbol("z")
omega = Symbol("omega")
X=(t,x,y,z)
A = Matrix([
[1, 0, 0, 0],
[0, cos(omega*t), sin(omega*t), 0],
[0, -sin(omega*t), cos(omega*t), 0],
[0, 0, 0, 1],
])
Ainv = A.subs(t, -t)
x = Matrix(X)
x_prime = A*x
M = Matrix(4,4, lambda i,j: x_prime[i].diff(x[j]))
print "A:"
pprint(A)
print "A * Ainv should be one:"
pprint((A*Ainv).applyfunc(trigsimp))
print "x:"
pprint(x)
print "x':"
pprint(x_prime)
print "M:"
pprint(M)
gdd = eye(4)
gdd[0,0] = -1
print "g_dd:"
pprint(gdd)
gddp = (M.T*gdd*M).applyfunc(trigsimp)
print "g_dd':"
pprint(gddp)
guup = gddp.inv("ADJ")
print "g_uu':"
pprint(guup)
pprint(guup*gddp)
And the output:
A:
⎡ 1 0 0 0⎤
⎢ 0 cos(ω*t) sin(ω*t) 0⎥
⎢ 0 -sin(ω*t) cos(ω*t) 0⎥
⎣ 0 0 0 1⎦
A * Ainv should be one:
⎡1 0 0 0⎤
⎢0 1 0 0⎥
⎢0 0 1 0⎥
⎣0 0 0 1⎦
x:
⎡t⎤
⎢x⎥
⎢y⎥
⎣z⎦
x':
⎡ t⎤
⎢x*cos(ω*t) + y*sin(ω*t)⎥
⎢y*cos(ω*t) - x*sin(ω*t)⎥
⎣ z⎦
M:
⎡ 1
0
⎢ ω*y*cos(ω*t) - ω*x*sin(ω*t)
cos(ω*t)
⎢-ω*x*cos(ω*t) - ω*y*sin(ω*t) -
sin(ω*t)
⎣ 0
0
0 0⎤
sin(ω*t) 0⎥
cos(ω*t) 0⎥
0 1⎦
g_dd:
⎡-1 0 0 0⎤
⎢ 0 1 0 0⎥
⎢ 0 0 1 0⎥
⎣ 0 0 0 1⎦
g_dd':
⎡ 2 2 2
2 ⎤
⎢-1 + ω *x + ω *y ω*y -
ω*x 0⎥
⎢
⎥
⎢ ω*y 1
0 0⎥
⎢
⎥
⎢ -ω*x 0
1 0⎥
⎢
⎥
⎣ 0 0
0 1⎦
g_uu':
⎡ ⎤
⎢ -1 ω*y -ω*x 0⎥
⎢ 2 2 2 ⎥
⎢ ω*y 1 - ω *y x*y*ω 0⎥
⎢ 2 2 2 ⎥
⎢ -ω*x x*y*ω 1 - ω *x 0⎥
⎢ ⎥
⎣ 0 0 0 1⎦
⎡1 0 0 0⎤
⎢0 1 0 0⎥
⎢0 0 1 0⎥
⎣0 0 0 1⎦
Very nice. I always wanted to play with things like this easily and
now I finally can. :)
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---