Often when I'm writing a project in Mathematica, the number of arguments I must provide to functions spins out of control.
I need a sort of object-oriented encapsulation approach. I've already had a go at doing this in Java, and now believe than an object-oriented language is not well suited to my needs.
Example:
Here I fetch data for the geodesic of a test particle in a pseudo-Riemannian manifold. The user must supply the metric in matrix form, the initial positions and velocities, and other miscellaneous things:
NGeodesicData[( {
{(1 - (1/#2)) &, 0 &, 0 &},
{0 &, -(1 - 1/#2)^-1 &, 0 &}, (*Matrix of real functions*)
{0 &, 0 &, (-#2^2) &}
} ) ,
{{0, 50, 0.}, {Null, 0., .0008}}, (*Initial position and velocity*)
{1, True, True}, (*Miscellaneous*)
2500, .01, 1] (*Numerical integration settings*)
All of these arguments are necessary, and I would like to structure them in a more manageable format.
Specifically, I would like a head called TangentVector
which consists of:
- An n x n matrix of real functions of n variables each. (The matrix of real functions)
- A list of two n-dimensional vectors. (the initial position and velocity; a tangent vector)
I am used to object-oriented languages where I can program a constructor in which I can perform checks, throw exceptions or warnings if I need to, and store a couple of fields based on the input. Basically, I'm looking to do the same thing here.
How can I create such a TangentVector
structure, and make a constructor for it?
I believe I have already found a solution to complicated pattern-matching (on the inputs to the constructor) here.
TangentVector
structure based on that. The reason that I want this structure is so that other functions can take inTangentVector
s as inputs. The best way I know of to do this is to create a custom head. I will be happy with any encapsulation approach though. $\endgroup$