Filling a matrix with functions

36 views
Skip to first unread message

Oscar Alberto Castillo Felisola

unread,
Mar 24, 2015, 6:05:21 AM3/24/15
to sage-s...@googlegroups.com
Hi. I know that one can define a function by declaring

sage: f = function('f', t,r)

However, I'm interested in declaring a matrix filled with different functions. Of course, for a small matrix I can do it by hand, but for "huge" matrices it is boring and make no sense.

Is it possible to do what I need?

Harald Schilly

unread,
Mar 24, 2015, 6:37:16 AM3/24/15
to sage-s...@googlegroups.com


On Tuesday, March 24, 2015 at 11:05:21 AM UTC+1, Oscar Alberto Castillo Felisola wrote:
but for "huge" matrices it is boring and make no sense.

Can you describe a rule or pattern how this matrix should be filled? 

Oscar Alberto Castillo Felisola

unread,
Mar 24, 2015, 7:49:57 AM3/24/15
to sage-s...@googlegroups.com
I'd like to obtain something like

f11 = function('f11', t,r)
f12
= function('f12', t,r)
f21
= function('f21', t,r)
f22
= function('f22', t,r)
M
= matrix(2,2, [[f11, f12], [f21, f22]])

Note that in principle all the functions depend on the same variables.

If the assignation of functions could be used as components of a metric of sagemanifold, would be even better.

Harald Schilly

unread,
Mar 24, 2015, 8:05:25 AM3/24/15
to sage-s...@googlegroups.com


On Tuesday, March 24, 2015 at 12:49:57 PM UTC+1, Oscar Alberto Castillo Felisola wrote:
I'd like to obtain something like

f11 = function('f11', t,r)
f12
= function('f12', t,r)
f21
= function('f21', t,r)
f22
= function('f22', t,r)
M
= matrix(2,2, [[f11, f12], [f21, f22]])


 
Since this is doable via a functional mapping from the indices to the desired objects, you can use the matrix to do this via the lambda operator:

sage: var("t r")
(t, r)
sage
: matrix(5, 5, lambda x,y : function("f%s%s" % (x,y), t, r))
[f00(t, r) f01(t, r) f02(t, r) f03(t, r) f04(t, r)]
[f10(t, r) f11(t, r) f12(t, r) f13(t, r) f14(t, r)]
[f20(t, r) f21(t, r) f22(t, r) f23(t, r) f24(t, r)]
[f30(t, r) f31(t, r) f32(t, r) f33(t, r) f34(t, r)]
[f40(t, r) f41(t, r) f42(t, r) f43(t, r) f44(t, r)]

It's zero-based indexed, as everything else in Python, but you can fix it easily. Hope this helps.

-- Harald



Oscar Alberto Castillo Felisola

unread,
Mar 24, 2015, 8:14:07 AM3/24/15
to sage-s...@googlegroups.com
Thank you very much Harald!
Reply all
Reply to author
Forward
0 new messages