Question: Global and local in module

I have a global matrix with a default value set in a module. I also need the inverse of the matrix. Can the module do this?  I don't really want to have to get routines to calculate the inverse every time they are called.

restart

``

TM := module () local invMetric; export foo, bar; global Metric;  Metric := Matrix(3, shape = symmetric, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]); invMetric := LinearAlgebra:-MatrixInverse(rtable_eval(Metric, 'inplace')); foo := proc () print('Metric' = Metric) end proc; bar := proc () print('invMetric' = invMetric) end proc end module

_m2278573910560

(1)

TM:-foo()

Metric = Matrix(%id = 36893490426002737860)

(2)

TM:-bar()

invMetric = Matrix(%id = 36893490426002738460)

(3)

Metric := Matrix(3, 3, {(1, 1) = 1, (1, 2) = 0, (1, 3) = 0, (2, 1) = 0, (2, 2) = 1, (2, 3) = 0, (3, 1) = 0, (3, 2) = 0, (3, 3) = -2})

Matrix(%id = 36893490426002715820)

(4)

TM:-foo()

Metric = Matrix(%id = 36893490426002715820)

(5)

TM:-bar()

invMetric = Matrix(%id = 36893490426002738460)

(6)

NULL

Download 2024-12-30_Q_Module_Global_and_Local.mw

Please Wait...