Ask Your Question

Displaying a matrix with scalar fields

asked 2023-08-02 13:12:05 +0200

tolga gravatar image

I have some scalar fields and a matrix whose elements are these scalar fields. A sample code is the following:

M=Manifold(4, 'M', r'\mathcal{M}')
BL.<t,r,th,ph> = M.chart(r't r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')

f, g, or h can be zero or nonzero (according to some calculations).

When I try to display my matrix with show(mymatrix) or print(mymatrix), I see Scalar field on the 4-dimensional differentiable manifold M instead of the non-zero elements.

What should I do to display my matrix as

[f+g g 0]
[f 0 g]
[0 g f]

preferably without using loops, etc?

edit retag flag offensive close merge delete



If you accept arguments, then try

matrix(3,3,lambda i,j: mymatrix[i,j].expr())
achrzesz gravatar imageachrzesz ( 2023-08-02 16:13:40 +0200 )edit

Thank you @achrzesz. This is a solution to my problem.

tolga gravatar imagetolga ( 2023-08-02 16:27:53 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-08-02 16:12:22 +0200

rburing gravatar image
sage: mymatrix.apply_map(lambda z: z.expr())
[f(t, r, th, ph) + g(t, r, th, ph)                   g(t, r, th, ph)                                 0]
[                  f(t, r, th, ph)                                 0                   g(t, r, th, ph)]
[                                0                   g(t, r, th, ph)                   f(t, r, th, ph)]
edit flag offensive delete link more


That solves my problem. Thank you.

tolga gravatar imagetolga ( 2023-08-02 16:23:28 +0200 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2023-08-02 13:12:05 +0200

Seen: 96 times

Last updated: Aug 02 '23