Ask Your Question
0

How to change/set variables?

asked 2019-06-19 19:57:49 +0200

sum8tion gravatar image

updated 2019-06-25 18:46:40 +0200

I created a list of formal variables that I want to work with under addition, multiplication etc. in the following way:

g = list(var('g_%d' % i) for i in rang(4))

Specifically I'm working with differential forms

M = Manifold(4, 'M', field='complex')
U = M.open_subset('U')
c_xyXY<x, y, X, Y>=U.chart()
eU = c_xyXY.frame()
d = [[M.diff_form(2, name='d_{}{}'.format(j, i)) for i in range(2)] for j in range(2)]
d[0][0] [eU, 2, 0] = g[0]
d[0][1] [eU, 3, 0] = g[1]
d[1][0] [eU, 2, 1] = g[2]
d[1][1] [eU, 3, 1] = g[3]

I then want to set the variables to something specific like

g[0] = x^2

but when I try to display this I get

d[0][0].display(eU)
d_00 = -g_0dx/\dX

What I want is

d_00 = -x^2dx/\dX

EDIT: The question as originally asked has been sufficiently answered by eric_g below. However I'm still having difficulty with a more complicated version of the same set-up, which I present here: https://ask.sagemath.org/question/469...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-06-20 14:53:04 +0200

eric_g gravatar image

updated 2019-06-20 14:53:26 +0200

Well, in Python, when you write

g[0] = x^2

this means that the element 0 in the list g, which was initialized to g_0, is replaced by x^2. The symbolic variable g_0 remains unchanged; simply it is no longer the element 0 of g:

sage: g = list(var('g_%d' % i) for i in range(4))
sage: g
[g_0, g_1, g_2, g_3]
sage: g[0] = x^2
sage: g
[x^2, g_1, g_2, g_3]
sage: g_0
g_0

In particular, g_0 is still there in d_00. If you want to replace it by x^2, you have to run d[0][0] [eU, 2, 0] = g[0] again:

sage: d[0][0] [eU, 2, 0] = g[0]
sage: d[0][0].display(eU)
d_00 = -x^2 dx/\dX
edit flag offensive delete link more

Comments

Thanks, this seems to work for this example. However, I'm still having trouble with a more complicated version of the same task. I'll edit the question to add it in.

sum8tion gravatar imagesum8tion ( 2019-06-21 15:43:31 +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

Stats

Asked: 2019-06-19 19:57:49 +0200

Seen: 622 times

Last updated: Jun 25 '19