Skip to content

Commit 16e1772

Browse files
committed
add println code to jacobian2by2 to see output
1 parent fb6ea8c commit 16e1772

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

demos/book/9/jacobian2by2.jl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@ warn("This may use features of PyCall and/or SymPy which are not publicly availa
1010
using PyCall
1111
pyinitialize("/opt/local/bin/python2")
1212
using SymPy
13+
jacobian(Y,X) = Sym(Y[:reshape](1,length(Y))[:jacobian](X[:reshape](1,length(X))))
1314

1415
p,q,r,s, a,b,c,d, t, e1,e2 = Sym(:p,:q,:r,:s, :a,:b,:c,:d, :t, :e1,:e2)
1516
X = SymMatrix([p q; r s])
1617
A = SymMatrix([a b; c d])
17-
jacobian(Y,X) = Sym(Y[:reshape](1,length(Y))[:jacobian](X[:reshape](1,length(X))))
18-
Y = X^2; J = jacobian(Y,X); JAC_square = Sym(J[:det]()[:factor]())
19-
Y = X^3; J = jacobian(Y,X); JAC_cube = Sym(J[:det]()[:factor]())
20-
Y = X[:inv](); J = jacobian(Y,X); JAC_cube = Sym(J[:det]()[:factor]())
21-
Y = A*X; J = jacobian(Y,X); JAC_linear = Sym(J[:det]()[:factor]())
22-
Y = SymMatrix([p q; r/p X[:det]()/p]); J = jacobian(Y,X); JAC_lu = Sym(J[:det]()[:factor]())
18+
19+
Y = X^2; J = jacobian(Y,X); JAC_square = Sym(J[:det]()[:factor]()); println("square:\n", J, "\n\n", JAC_square, "\n\n")
20+
Y = X^3; J = jacobian(Y,X); JAC_cube = Sym(J[:det]()[:factor]()); println("cube:\n", J, "\n\n", JAC_cube, "\n\n")
21+
Y = X[:inv](); J = jacobian(Y,X); JAC_inv = Sym(J[:det]()[:factor]()); println("inv:\n", J, "\n\n", JAC_inv, "\n\n")
22+
Y = A*X; J = jacobian(Y,X); JAC_linear = Sym(J[:det]()[:factor]()); println("linear:\n", J, "\n\n", JAC_linear, "\n\n")
23+
Y = SymMatrix([p q; r/p X[:det]()/p]); J = jacobian(Y,X); JAC_lu = Sym(J[:det]()[:factor]()); println("lu:\n", J, "\n\n", JAC_lu, "\n\n")
2324

2425
x = SymMatrix([p, s, r])
2526
y = SymMatrix([sqrt(p), sqrt(s), r/(sqrt(p)*sqrt(s))])
2627
J = jacobian(y,x)
2728
JAC_DMD = Sym(J[:det]()[:factor]())
29+
println("DMD:\n", J, "\n\n", JAC_DMD, "\n\n")
2830

2931
x = SymMatrix([p, s])
3032
y = SymMatrix([sqrt(p^2 + s^2), atan(s/p)])
3133
J = jacobian(y,x)
3234
JAC_notrace = Sym(J[:det]()[:factor]())
35+
println("notrace:\n", J, "\n\n", JAC_notrace, "\n\n")
3336

3437
Q = SymMatrix([cos(t) -sin(t); sin(t) cos(t)])
3538
D = SymMatrix([e1 0; 0 e2])
@@ -38,11 +41,13 @@ y = SymMatrix([Y[1,1], Y[2,2], Y[1,2]])
3841
x = SymMatrix([t, e1, e2])
3942
J = jacobian(Y,X)
4043
JAC_symeig = Sym(J[:det]()[:factor]())
44+
println("symeig:\n", J, "\n\n", JAC_symeig, "\n\n")
4145

4246
X = SymMatrix([p s; s r])
4347
Y = Sym(A[:transpose]())*X*A
4448
y = SymMatrix([Y[1,1], Y[2,2], Y[1,2]])
4549
x = SymMatrix([p, r, s])
4650
J = jacobian(Y,X)
4751
JAC_symcong = Sym(J[:det]()[:factor]())
52+
println("symcong:\n", J, "\n\n", JAC_symcong, "\n\n")
4853

0 commit comments

Comments
 (0)