Ask Your Question
0

Displaying a matrix with scalar fields

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

tolga gravatar image

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

reset()
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=M.scalar_field(function('f')(*BL))
g=M.scalar_field(function('g')(*BL))
h=M.scalar_field(function('h')(*BL))
h=0
mymatrix=matrix([[f+g,g,h],[f,h,g],[h,g,f]])

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

Comments

1

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 +0100 )edit

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

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

1 Answer

Sort by ยป oldest newest most voted
2

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

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

Comments

That solves my problem. Thank you.

tolga gravatar imagetolga ( 2023-08-02 16:23:28 +0100 )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

Stats

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

Seen: 193 times

Last updated: Aug 02 '23