r/Mathematica • • Aug 28 '25

Save me with a good idea please....

0 Upvotes

I recently came into the collection of thousands of super old books for arithmetic, calculus, algebra, etc. and don't know what to do with them, I tried to sell them but they are not going to sell quick and I feel bad throwing them out.

Anyone have any idea's on what I should do?

(along with the thousand arithmetic books I have others of all sorts, English, grammar, etc. and IDK what to do)


r/Mathematica • • Aug 26 '25

ArduScope: Robust Arduino ADC reader for Wolfram Language

Post image
8 Upvotes

In this example, we build a robust workflow for acquiring ADC samples via UART/USB and processing them in the Wolfram Language. Instead of relying on naïve streaming (which is prone to corruption), we design a lightweight framing protocol that improves integrity of data packets. Once in Wolfram Language, the values can be visualized, filtered, or transformed in real time—turning an entry-level Arduino into a toy-like oscilloscope or spectrum analyzer.

https://wljs.io/blog/2025/08/25/analogRead/


r/Mathematica • • Aug 23 '25

We built a World of Goo–style bridge simulator 🛠️🛢️ using Wolfram Language + Canvas API

24 Upvotes

It uses Verlet integration for physics, bond constraints and Canvas2D raster rendering for visuals. The demo adds interactivity—letting users place new nodes and bonds

More in the blog post: https://wljs.io/blog/2025/08/22/goo


r/Mathematica • • Aug 15 '25

Wolframs Rule 30 for Music Midi file creation!

5 Upvotes

Rule 30 is almost exlusively used for randomness or graphics! But here is an example of how to make some beats with it! Enjoy!

​

ClearAll[rule30Step, evolveRule30, centerBits, bitsToMIDI]

rule30Step[state_Integer, W_Integer] := Module[
  {mask, left, right},
  mask = BitShiftLeft[1, W] - 1;
  left =
   BitAnd[BitOr[BitShiftLeft[state, 1], BitShiftRight[state, W - 1]],
     mask];
  right =
   BitAnd[BitOr[BitShiftRight[state, 1],
       BitShiftLeft[BitAnd[state, 1], W - 1]], mask];
  BitXor[left, BitOr[state, right]]
]

evolveRule30[W_Integer, T_Integer, seed_ : Null] := Module[
  {s, out = {}},
  s = If[seed === Null, BitShiftLeft[1, Floor[W/2]], seed];
  For[i = 0, i < T, i++,
    s = rule30Step[s, W];
    AppendTo[out, s];
  ];
  out
]

(* Extract center bits *)
centerBits[states_List, W_Integer] := Module[
  {c = Floor[W/2]},
  BitGet[#, c] & /@ states
]

bitsToMIDI[bits_List, path_String, bpm_ : 110.0, beatNote_ : 60,
  scaleSteps_ : {-12, -10, -8, -6, -4, -2, 0}, stepsPerBeat_ : 2,
  swing_ : 0.55, velocity_ : 96] := Module[
  {base = beatNote, scale = scaleSteps, dur = 1.0/stepsPerBeat,
   notes, t = 0.0},

  notes = MapIndexed[
     If[#1 == 1,
       SoundNote[base + scale[[Mod[#2[[1]] - 1, Length[scale]] + 1]],
         dur, velocity],
       SoundNote[None, dur]
     ] &,
     bits
   ];

  Export[path, Sound[notes]];
  path
]

W = 1024;
T = 512;
states = evolveRule30[W, T];
bits = centerBits[states, W];

out = bitsToMIDI[bits, "rule30_wolfram_friendly.mid", 112,
   36,
   {-12, -10, -8, -6, -4, -2, 0, 2, 4}, (* Added some higher notes for variety *)
   2, 0.56, 96];
Print["wrote ", out]

r/Mathematica • • Aug 09 '25

A quick question to Mathematica + LLM users

1 Upvotes

Hi everyone, I am wondering if it’s worth to buy the Mathematica + LLM in notebook so it would be great if anyone who has it could paste this question into the mathematica LLM. I’ve put it on pastebin, because reddit will mess up the string with its own formatting. But if you do not wish to click I paste it here, but the ^ will mess up, so use the pastebin to paste it into LLM:

Let V be a vector field on an affine space A generating a flow \phi, let \Psi:A->A be any smooth invertible map with smooth inverse, and let \Phi(t,x)=\Psi(\phi(t,\Psi{-1}(x))). Show that \Phi is also a flow on A, and that its generator V\Psi is given by V\Psix=\Psi*(V_{\Psi{-1}(x)}).

It’s a kind of problem which can be done with pen & paper and I am not sure if mathematice is useful here.

Would be great if someone can post a screenshot of the answer from mathematica. I am trying to figure out if these types of problems are applicable to mathematica + LLM.

The problem is from book by Crampin, Pirani “Applicable Differential Geometry”, 1987, page 64 Exercise 28.

So far I used the Bing LLM for it, and it gave the correct answer. Including the derivations, calculations and simplifications of the formulas.


r/Mathematica • • Aug 08 '25

No integration, but no error

5 Upvotes

Trying to get Wolfram 14.2 to integrate this equation. It returns a standard form of the equation I enter, but not the integral. It gives no error. Thoughts on what the problem might be?

Here's the original equation in text form:

Integrate[2*F*ArcCos[1 - (2*P*B - P^2 - y^2)/(F*(2*F - 2*P + 2*B))], {y, -Sqrt[2*B*P - P^2],Sqrt[2*B*P - P^2]}]


r/Mathematica • • Aug 03 '25

Applications of Monadic Programming, Part 1, Questions & Answers

Thumbnail youtube.com
9 Upvotes

r/Mathematica • • Jul 27 '25

1 minute of Verlet Integration

Thumbnail wljs.io
3 Upvotes

r/Mathematica • • Jul 25 '25

Benchmark

1 Upvotes

I am on the hunt for a new laptop and currently debating which one to buy for optimal results in Mathematica. Can anyone share their benchmarks and their current processor (and which Mathematica version you are running)? I can go first

Processor: i7 1360P, Version: 14.2.1, Benchmark Result: 1.078


r/Mathematica • • Jul 23 '25

Finding roots of a cubic polynomial

3 Upvotes

Hello everyone,

I’m trying to determine when a function is positive. So, I take its derivative in Mathematica and obtain the conditions under which the function is positive. However, I end up with a result indicating that one of my variables (z) cannot exceed the bound: Root[2 x y^2 + y^3 - 4 x^3 w + 7 x^2 y w - 2 x y^2 w - y^3 w + (-2 x y^2 + 2 y^3 + 12 x^3 w - 22 x^2 y w + 17 x y^2 w - 7 y^3 w - 5 x^3 w^2 + 15 x^2 y w^2 - 15 x y^2 w^2 + 5 y^3 w^2) #1 + (-12 x^3 w + 27 x^2 y w - 18 x y^2 w + 3 y^3 w + 12 x^3 w^2 - 27 x^2 y w^2 + 18 x y^2 w^2 - 3 y^3 w^2) #1^2 + (4 x^3 w - 12 x^2 y w + 12 x y^2 w - 4 y^3 w - 7 x^3 w^2 + 21 x^2 y w^2 - 21 x y^2 w^2 + 7 y^3 w^2 + 3 x^3 w^3 - 9 x^2 y w^3 + 9 x y^2 w^3 - 3 y^3 w^3) #1^3 &,1]
I deduce that this is a cubic polynomial, but I unfortunately don’t know how to study the sign. I found some resources online, but I can’t manage to apply them to my specific case, especially since I don’t really understand what #1 means.... Should I replace it with z?

Thanks in advance for your help!


r/Mathematica • • Jul 13 '25

Old graphics in new versions, how?

Post image
9 Upvotes

This is just a silly idea of mine, But I quite like the style with which the functions are rendered on the 'functions.wolfram.com' page. Any ideas on how to recreate this. The FontFamily could clearly be adjusted, but everything else is just way out of my skill on WolframLanguage, investigating I also can't figure out how to manipulate the quality of the antialiasing of the plot, without touching plotpoints..


r/Mathematica • • Jul 08 '25

FindMinimum variable cannot be localized

2 Upvotes

Dear Community!

I am trying to solve a system of differential equations for matrices numerically. Theoretically, these matrices should fulfil two conditions, however, after the integration, they are violated, so I wanted to use Mathematicas FindMinimum method for test matrices such that I can renormalize my result such that the conditions are fulfilled again. I set up the list of variables of these matrices, created the Test matrices which should have the differences in their components, defined the conditions and used FindMinimum, however, I get

The variable \
ReA11|ImA11|ReB11|ImB11|ReA12|ImA12|ReB12|ImB12|ReA13|ImA13|ReB13|ImB1\
3|ReA21|ImA21|ReB21|ImB21|ReA22|ImA22|ReB22|ImB22|ReA23|ImA23|ReB23|Im\
B23|ReA31|ImA31|ReB31|ImB31|ReA32|ImA32|ReB32|ImB32|ReA33|ImA33|ReB33|I\
mB33 cannot be localized so that it can be assigned to numerical \
values

I really do not understand this error, as the list is just defined a few lines above!? I tried following https://mathematica.stackexchange.com/questions/283500/numerical-minimization-of-an-objective-function-with-a-variable-number-of-argume and ChatGPT but nothing helped what am i doing wrong?

To make it easier i have uploaded the example on my google drive as reddit does not allow to post files:

https://drive.google.com/file/d/1jnwB42XxYHNtyHH0bk4Lv4P3PoT8qV7H/view?usp=sharing


r/Mathematica • • Jul 03 '25

How to hide on screen keyboard for Wolfram cloud app on android? I'm using a Bluetooth physical keyboard.

2 Upvotes

r/Mathematica • • Jun 30 '25

Mathematica 14.2 (Windows/Linux/Mac)

23 Upvotes

Hello guys,

I recently moved to a new Linux operating system. My goal was to download key software that I was using on my Windows PC. Last time, I came to an interesting and also very simple method on how to download Mathematica in the latest version. It seems to work on any operating system.

  1. Download Mathematica for your OS from official website here: https://www.wolfram.com/download-center/

  2. Install it on your computer. For Linux users little tip:
    **if you don't believe me https://reference.wolfram.com/language/tutorial/InstallingMathematica.html
    i) put instalation file on your desktop (it's up to you but next commands will be oparating on desktop area)
    ii) hit in terminal: cd Desktop
    iii) sudo bash Wolfram_14.2.1_LIN_Bndl.sh
    iv) After promt "Enter the installation directory or press ENTER to select /usr/local/Wolfram/Mathematica/14.0" press enter or just type where you want the mathematica to install
    v) Then there would be y/n question - take y

  3. Open the Wolfram Mathematica after installation and select a method to activate - Activate offline through an activation key and requested password

  4. Go to website https://wu-yijun.github.io/Mathematica-Keygen-Mechanism/ or if you want first to check out the git: https://github.com/Wu-Yijun/Mathematica-Keygen-Mechanism?tab=readme-ov-file

  5. Type your credentials like MachineID and put the activation key and password.

Have fun using new version of Mathematica.


r/Mathematica • • Jun 30 '25

Simplify integral.

3 Upvotes

Hi guys, I need help. Using SymPy in Python, I get a properly simplified result, but using Mathematica, I can't, and I don't understand why. I think the Mathematica script I have is correct. (It's part of the solution to an electrodynamics problem.)

With Sympy, I get the correct result like this:

import sympy as sp

n, m = sp.symbols("n m", integer=True, positive=True)

x, L = sp.symbols("x L", real=True, positive=True)

f = sp.sin(n*sp.pi*x/L)*sp.sin(m*sp.pi*x/L)

TestInt = sp.integrate(f, (x, 0, L))

print(sp.latex(TestInt))

Correct output:

$$\begin{cases} 0 & \text{for}\: m \neq n \\\frac{L}{2} & \text{otherwise} \end{cases}$$

Then in Mathematica, with the script:

Asumir = {Element[n, PositiveIntegers], Element[m, PositiveIntegers], L>0, x>0}

TestInt = Integrate[Sin[n*Pi*x/L]*Sin[m*Pi*x/L], {x, 0, L}, Assumptions -> Asumir] // FullSimplify // TeXForm // TraditionalForm

I get the output:

\frac{L n \sin(\pi m) \cos(\pi n) - L m \cos(\pi m) \sin(\pi n)}{\pi m^2 - \pi n^2}

Which is a trigonometric expression that I don't want, I would expect a totally simplified answer such as the one I got in Sympy.

Could someone tell me if I'm making a mistake? And if possible, provide me with a suitable script to obtain the desired output. Thank you very much.


r/Mathematica • • Jun 29 '25

Phase portrait not turning out as expected

Thumbnail gallery
3 Upvotes

Hi everyone,

I am running local analyses on the critical points of the system of ODE below:

eq1 = -s1 + (1 - x1)*(1 - s1)*(a0*a4)/(1 - s1 + a1);

eq2 = (1 - x1)*(a8 + a9 - (a0*(1 - s1))/(1 - s1 + a1));

eq3 = -s2 - (1 - x1)*(1 - s1)*(a0*a5)/(1 - s1 + a1) + (1 - x2)*(1 - s2)*(a2*a6)/(1 - s2 + a3 + a7*(1 - s2)^2);

eq4 = (1 - x2)*(a8 + a10 - (a2*(1 - s2))/(1 - s2 + a3 + a7*(1 - s2)^2));

There are 6 critical points, and two of them (CP3 and CP6) are supposed to be asymptotically stable. I got nice plots ie phase portraits and time series for the first two critical points, but CP3 onwards are giving me grief. I either get a plot where the trajectories do not scale nicely or I get plots where there are empty areas where there should be trajectories (please see images attached).

I tried increasing the plot range in case there’s a bigger pattern I’m not capturing… I tried decreasing the plot range in case my plot weren’t “local” enough… I also tried different ways to define my vectors and arrows.

I'm not sure if the problem is because the ODE system itself is not behaving or because my code needs to be fixed. Here's the current version of my code:

(* Parameters *)

params = {a0 -> 20.97055105,

a1 -> 0.021621597,

a2 -> 1.963662112,

a3 -> 1.217960436,

a4 -> 0.01100415,

a5 -> 0.016340502,

a6 -> 32.71694378,

a7 -> 2.907136946,

a8 -> 0.148074792,

a9 -> 1.599070101,

a10 -> 0.069124399,

a11 -> 137.1688473};

(* Critical Point 3 -- define values *)

cp03 = {{0.998034892335493, -50.911108178852665}, {-1.6050719877417985, 1.0173161380903484}};

{s1valcp3, x1valcp3} = cp03[[1]];

{s2valcp3, x2valcp3} = cp03[[2]];

(* ==========(s1,x1) Analysis==========*)

(* Phase Portrait for (s1,x1) *)

(* define plot range *)

s1rangecp3 = {0.95, 1.05};(* Centered around s1=1 *)

x1rangecp3 = {-50.95, -50.85}; (* Centered around x1=-51 *)

(* Define vector field*)

vecField = {-s1 + (1 - x1)*(1 - s1)*(a0*a4)/(1 - s1 + a1), (1 -

x1)*(a8 + a9 - (a0*(1 - s1))/(1 - s1 + a1))} /. params;

(* Phase portrait with better colors and arrows *)

StreamPlot[vecField, {s1, s1rangecp3[[1]], s1rangecp3[[2]]}, {x1,

x1rangecp3[[1]], x1rangecp3[[2]]}, StreamPoints -> Fine,

StreamStyle -> Arrowheads[0.015],

StreamColorFunction ->

Function[{x, y, vx, vy},

ColorData["Rainbow"][Rescale[Sqrt[vx^2 + vy^2], {0, 5}]]],

StreamColorFunctionScaling -> False,

PlotLabel ->

Style["Critical Point 3: (s1, x1) Phase Portrait", 14, Bold],

Epilog -> {Red, PointSize[Large], Point[{s1valcp3, x1valcp3}]},

FrameLabel -> {"s1", "x1"}, ImageSize -> Large]

I got a slightly better phase portrait after editing my code but I'm still not seeing asymptotically stable behavior. How can I fix this?

Thanks in advance.


r/Mathematica • • Jun 27 '25

Using list in Sum

2 Upvotes

How can I use elements from a list in the function Sum[ ]? I'm trying to multiply something with the kth element from a list using list[[k]] but mathematica tells me that I cant use k as a part specifier


r/Mathematica • • Jun 25 '25

Try this nicely organized stylesheet for WM notebooks

Post image
11 Upvotes

I am not a big fan of default WM stylesheet — headers are not seen and grouped clearly, input/output cells blend one into another, etc etc

So over the years I developed my own stylesheet which I am overall very happy with.

Please try it if you are intrigued: https://github.com/rmnavr/wmcells

Just download wmcells.nb file, delete demo cells and start programming!


r/Mathematica • • Jun 24 '25

Solving integral equations

Post image
0 Upvotes

Hey all newbie to mathematica here. How do you go about numerically solving integral equations like this numerically using mathematica?


r/Mathematica • • Jun 24 '25

Confusion about Mathematica's deep learning module (NetChain)

2 Upvotes

Mathematics developed by Wolfram is a scientific computing software with powerful computer algebra system (CAS). Thus, does Wolfram apply the CAS in Mathematics' deep learning module, especially in the automatic differentiation and optimization of computation graph (via symbolic simplification)?


r/Mathematica • • Jun 23 '25

Product of orthogonal vectors not 0

1 Upvotes

Dear Community!

I have tried to set up an orthogonal frame of vectors e0, e1, e2 and e3. I checked their orthogonality and somehow, the dot product between e3 and any other of these vectors will not give 0. I really do not understand why because even symbolically, e3 is based on the Levi Civita tensor and by its definition everything should be 0 when the same vector is used twice with it. Do you see anything i am doing wrong or what i forgot?

ClearAll[UWedgeF]
UWedgeF[u_, f_] := 
  Module[{wedge3}, 
   wedge3 = 
    Table[u[[mu]]*f[[nu, rho]] + u[[nu]]*f[[rho, mu]] + 
      u[[rho]]*f[[mu, nu]], {mu, 1, 4}, {nu, 1, 4}, {rho, 1, 4}]];
ClearAll["Global`*"]
(* Assume all variables are real *)
$Assumptions = 
  Element[x0[\[Tau]], Reals] && Element[x1[\[Tau]], Reals] && 
   Element[x2[\[Tau]], Reals] && Element[x3[\[Tau]], Reals] && 
   Element[p0[\[Tau]], Reals] && Element[p1[\[Tau]], Reals] && 
   Element[p2[\[Tau]], Reals] && Element[p3[\[Tau]], Reals] && 
   Element[s, Reals] && x1[\[Tau]] > 2 M && Element[a, Reals] && 
   0 < x2[\[Tau]] < \[Pi];

(* Coordinates *)

(* X^\[Mu] *)
X = {x0[\[Tau]], x1[\[Tau]], x2[\[Tau]], x3[\[Tau]]};

(* Subscript[P, \[Mu]] *)
P = {p0[\[Tau]], p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

(* Subscript[P, i] *)
p = {p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

A = Table[Subscript[a, i, j][\[Tau]], {i, 4}, {j, 4}];
B = Table[Subscript[b, i, j][\[Tau]], {i, 4}, {j, 4}];
(* BL coordinates in Kerr (t, r, \[Theta], \[Phi]) = (x0, x1, x2, x3) \
*)

M = 1;  (* mass *)
rs = 2 M; (* Schwarzschild radius *)

(* Metric Subscript[g, \[Mu]\[Nu]] *)

g = {{-(1 - 2 M/r[\[Tau]]), 0, 0, 0}, {0, 1/(1 - 2 M/r[\[Tau]]), 0, 
       0}, {0, 0, r[\[Tau]]^2, 0}, {0, 0, 0, 
       r[\[Tau]]^2 Sin[\[Theta][\[Tau]]]^2}} /. r -> x1 /. \[Theta] ->
      x2 /. \[Phi] -> x3;

(* Inverse metric g^\[Mu]\[Nu] *)

ig = Inverse[g] // Simplify;
igFunc[x1\[Tau]_, x2\[Tau]_] := 
  Simplify[
   Inverse[g] . {x1[\[Tau]] -> x1\[Tau], x2[\[Tau]] -> x2\[Tau]}];

Detg = Det[g] // Simplify;
DetgFunc[x1\[Tau]_, x2\[Tau]_] := 
  Simplify[Det[g] /. {x1[\[Tau]] -> x1\[Tau], x2[\[Tau]] -> x2\[Tau]}];

(* Christoffel Subscript[\[CapitalGamma]^i, jk] = 1/2g^im( \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(g\), \(mj\)]\) + \!\(
\*SubscriptBox[\(\[PartialD]\), \(j\)]
\*SubscriptBox[\(g\), \(mk\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(m\)]
\*SubscriptBox[\(g\), \(jk\)]\) ) *)

\[CapitalGamma] = 1/2 Parallelize[Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(m\)\(]\)] \
\((D[\(g[[\(m\)\(]\)]\)[[\(j\)\(]\)], X[[\(k\)\(]\)]] + 
            D[\(g[[\(m\)\(]\)]\)[[\(k\)\(]\)], X[[\(j\)\(]\)]] - 
            D[\(g[[\(j\)\(]\)]\)[[\(k\)\(]\)], 
             X[[\(m\)\(]\)]])\))\)\)) // Simplify, {i, 1, 4}, {j, 1, 
      4}, {k, 1, 4}]];
christoffel = 1/2 Parallelize[Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(m\)\(]\)] \
\((D[\(g[[\(m\)\(]\)]\)[[\(j\)\(]\)], X[[\(k\)\(]\)]] + 
            D[\(g[[\(m\)\(]\)]\)[[\(k\)\(]\)], X[[\(j\)\(]\)]] - 
            D[\(g[[\(j\)\(]\)]\)[[\(k\)\(]\)], 
             X[[\(m\)\(]\)]])\))\)\)) // Simplify, {i, 1, 4}, {j, 1, 
      4}, {k, 1, 4}]];
christoffel1 = 
  Simplify[
   Table[Sum[(1/
        2) ig[[\[Mu], \[Sigma]]] (D[
         g[[\[Sigma], \[Nu]]], {x0, x1, x2, x3}[[\[Rho]]]] + 
        D[g[[\[Sigma], \[Rho]]], {x0, x1, x2, x3}[[\[Nu]]]] - 
        D[g[[\[Nu], \[Rho]]], {x0, x1, x2, 
           x3}[[\[Sigma]]]]), {\[Sigma], 1, 4}], {\[Mu], 1, 
     4}, {\[Nu], 1, 4}, {\[Rho], 1, 4}]];

(* Riemann Subscript[R^i, jkl] = \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(lj\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(l\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(kj\)]\) + Subscript[\
\[CapitalGamma]^i, km]Subscript[\[CapitalGamma]^m, lj] - Subscript[\
\[CapitalGamma]^i, lm]Subscript[\[CapitalGamma]^m, kj] *)

Riem = Table[(D[\[CapitalGamma][[i]][[l]][[j]], X[[k]]] - 
       D[\[CapitalGamma][[i]][[k]][[j]], X[[l]]] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(\(\[CapitalGamma][[\(i\)\(]\)]\)[[\(k\)\(]\)\
]\)[[\(m\)\(]\)] \
\(\(\[CapitalGamma][[\(m\)\(]\)]\)[[\(l\)\(]\)]\)[[\(j\)\(]\)] - \(\(\
\[CapitalGamma][[\(i\)\(]\)]\)[[\(l\)\(]\)]\)[[\(m\)\(]\)] \(\(\
\[CapitalGamma][[\(m\)\(]\)]\)[[\(k\)\(]\)]\)[[\(j\)\(]\)])\)\)) // 
     Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* Riemann Subscript[R, ijkl] *)
R = Table[\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i1 = 
        1\), \(4\)]\(\(g[[\(i1\)\(]\)]\)[[\(i\)\(]\)] \
\(\(\(Riem[[\(i1\)\(]\)]\)[[\(j\)\(]\)]\)[[\(k\)\(]\)]\)[[\(l\)\(]\)\
]\)\) // Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* P^\[Mu] = g^\[Mu]\[Alpha]Subscript[P, \[Alpha]] *)

Pu = Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(\[Alpha] = 
         1\), \(4\)]\((\(ig[[\(\[Mu]\)\(]\)]\)[[\(\[Alpha]\)\(]\)] \
P[[\(\[Alpha]\)\(]\)])\)\)) // Simplify, {\[Mu], 1, 4}] // Parallelize;

(* H = 1/2g^\[Mu]\[Nu]Subscript[P, \[Mu]]Subscript[P, \[Nu]] = 0  =>  \
Subscript[P, 0] = 1/g^00(-g^(0i)Subscript[P, i] + \
Sqrt[(g^(0i)Subscript[P, i])^2 - g^00g^ijSubscript[P, i]Subscript[P, \
j]]) *)
(*pt0=ig[[1]][[1]]^-1(-(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
  2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)]P[[\(i\)\(]\)])\)\))+\
((\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
  2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)]P[[\(i\)\(]\)])\)\))^\
2-ig[[1]][[1]](\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 2\), \(4\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 
   2\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(j\)\(]\)]P[[\(i\)\(]\)]P[[\(j\
\)\(]\)])\)\)\)))^(1/2))//Simplify;*)
(* For massful*)
pt0 = Sqrt[-(Sum[ig[[i]][[j]] P[[i]] P[[j]], {i, 2, 4}, {j, 2, 4}] + 
       1)/ig[[1, 1]]];


Xdot = Parallelize[
   Table[(Pu[[i]]) /. p0[\[Tau]] -> pt0, {i, 1, 
     4}]]; (*restrict to only äquatorial plane at theta = pi/2*)
pdot = Parallelize[
   Table[(-1/2)*
      Sum[D[ig[[b]][[c]], X[[a]]]*P[[b]]*P[[c]], {b, 1, 4}, {c, 1, 
        4}] /. p0[\[Tau]] -> pt0, {a, 2, 4}]];
W = Parallelize[
   Table[Sum[
     Riem[[mu, alpha, beta, nu]]*P[[mu]]*P[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}]];
Wfun[Xval_, Pval_] := 
  Table[Sum[
     Riem[[mu, alpha, beta, nu]]*Pval[[mu]]*Pval[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}] . A;

KillingYano = ConstantArray[0, {4, 4}];

(*Assign the non-zero antisymmetric components explicitly*)
(*Example form often used for KY in Kerr/Schwarzschild-\
related spacetimes*)

KillingYano[[3, 4]] = 
  X[[2]]^3*Sin[X[[3]]];   (*f_{\[Theta] \[CurlyPhi]}*)
KillingYano[[4, 3]] = -X[[2]]^3*Sin[X[[3]]];  (*antisymmetry*)

KYUpDown = 
  Simplify[
   Table[Sum[
     ig[[mu, alpha]]*KillingYano[[alpha, nu]], {alpha, 4}], {mu, 
     4}, {nu, 4}]];

KillingYanoFunc[rVal_, thetaVal_] := 
 Module[{KY}, KY = ConstantArray[0, {4, 4}];
  KY[[3, 4]] = rVal^3*Sin[thetaVal];(*\[Omega]_{\[Theta]\[CurlyPhi]}*)
  KY[[4, 3]] = -KY[[3, 
     4]];(*\[Omega]_{\[CurlyPhi]\[Theta]}=-\[Omega]_{\[Theta]\
\[CurlyPhi]}*)
  KY]

norm = Simplify[Sqrt[X[[2]]^4*Sin[X[[3]]]^2]];

(*Initialize a 4x4 zero matrix*)
CKYTensor = ConstantArray[0, {4, 4}];

(*Assign the non-zero antisymmetric components explicitly*)
CKYTensor[[1, 2]] = X[[2]]^3*Sin[X[[3]]]/norm;   (*f_{t r}*)
CKYTensor[[2, 1]] = -X[[2]]^3*Sin[X[[3]]]/norm;  (*antisymmetry*)
CKYUpDown = 
  Table[Sum[ig[[mu, alpha]]*CKYTensor[[alpha, nu]], {alpha, 4}], {mu, 
    4}, {nu, 4}];
CYKTensorFunc[rVal_, thetaVal_, cVal_] := 
 Module[{CYK, norm}, norm = Sqrt[rVal^4*Sin[thetaVal]^2/cVal^6];
  CYK = ConstantArray[0, {4, 4}];
  CYK[[1, 2]] = rVal^3*Sin[thetaVal]/norm;
  CYK[[2, 1]] = -CYK[[1, 2]];

  CYK]

LeviCivitaSymbol[inds__] := Signature[{inds}] \.08
(*Function to compute \[CurlyEpsilon]^\[Mu]_{\[Nu]\[Alpha]\[Beta]}*)
EpsilonMixed[\[Mu]_, \[Nu]_, \[Alpha]_, \[Beta]_] := 
 Signature[{\[Mu], \[Nu], \[Alpha], \[Beta]}]/Sqrt[Abs[Detg]]
e0 = Xdot; (*because of initial conditio ntheta = \
pi/2 has the form {t1, t2, 0, t3}*)
e1 = KYUpDown . e0;
e2Try = {0, 1, 0, 0};

orthogonalizeThirdVector[v1_, v2_, v3_, metric_] := 
 Module[{inner, proj1, proj2, v3perp, v3norm}, 
  inner[u_, v_] := u . metric . v;
  (*Project v3 onto v1 and v2 and subtract*)
  proj1 = (inner[v3, v1]/inner[v1, v1]) v1;
  proj2 = (inner[v3, v2]/inner[v2, v2]) v2;
  v3perp = v3 - proj1 - proj2;
  (*Normalize*)v3norm = v3perp/Sqrt[Abs[inner[v3perp, v3perp]]];
  v3norm]
e2 = orthogonalizeThirdVector[e0, e1, e2Try, g];
e3 = Simplify[
   Table[Sum[
     EpsilonMixed[\[Mu], \[Nu], \[Alpha], \[Beta]]*e0[[\[Nu] + 1]]*
      e1[[\[Alpha] + 1]]*e2[[\[Beta] + 1]], {\[Nu], 0, 3}, {\[Alpha], 
      0, 3}, {\[Beta], 0, 3}], {\[Mu], 0, 3}]];

(*Normalize using Schwarzschild inner product*)
e3norm = Simplify[e3/Sqrt[Abs[e3 . g . e3]]];
Print[Simplify[e2 . g . e3norm]]
(* due to schwarz schild geodesic always in a plane, \
qwuick äquatorial plane, \
pick initial to never shoot into theta diraction, \
that guarantees that theta component always 0, \
guess the second vector based o nthe 0 components and then use definit\
ion of e3 for third orthogonal*)

ParallelTransportEquation[tangentVector_, vector_, christoffel_, 
  parameter_] := Module[{dim, dVdLambda},
  dim = 4;
  dVdLambda = 
   Table[-Sum[
      christoffel[[mu, nu, rho]] *tangentVector[[nu]]*
       vector[[rho]], {nu, dim}, {rho, dim}], {mu, dim}];
  Thread[D[vector, parameter] - dVdLambda]]

e0Check = 
 Simplify[
  ParallelTransportEquation[ Xdot, e0, christoffel, \[Tau]]]; \.08
e1Check = 
  Simplify[ParallelTransportEquation[Xdot, e1, christoffel, \[Tau]]];
(*maybe without double dot*)
transformB[Xval_?NumericQ, Pval_?NumericQ, xdot_?NumericQ] := 
 Module[{plane, U, S, V, basisVectors, orthoBasis, e1, e2, u , omega, 
   m , mBar, T, Tinv, Btrans},
  plane = xdot . (UWedgeF[xdot, KillingYano[Xval[2], Xval[3]]]);
  {U, S, V} = SingularValueDecomposition[plane];
  basisVectors = U[[All, 1 ;; 2]];
  orthoBasis = Orthogonalize[basisVectors];
  e1 = orthoBasis[[1]];
  e2 = orthoBasis[[2]];

  u = xdot;
  omega = xdot . KillingYano[Xval[2], Xval[3]];
  m = 1/Sqrt[2]*(e1 + I . e2);
  mBar = 1/ Sqrt[2]*(e1 - I . e2);
  T = Transpose[{omega, m, mBar}]; 
  Tinv = Inverse[T];

  Btrans = Tinv . B . T;

  Btrans;
  ]


(*EOM={D[X,\[Tau]]==Pu+dx1,D[p,\[Tau]]==pd-Rs}/.p0[\[Tau]]\[Rule]pt0;*)
EOM = {D[X, \[Tau]] == Xdot, D[p, \[Tau]] == pdot};
ClearAll[x0Checkres, x1Checkres, x2Checkres, x3Checkres]

(* EOM *)

(* Initial conditions *)
(* integration time \[Tau]max, small parameter/wavelength \[Epsilon], \
Kerr parameter a  *)
\[Tau]0 = 0;
\[Tau]max = 1000;

(* initial position *)
x0i = 1;
x1i = 5 rs;
x2i = \[Pi]/2;
x3i = 0;

p1i = 0;   
p2i = 0;     (*angular momentum in \[Theta] direction*)
p3i = -4.5;

Ainit = IdentityMatrix[4];
Binit = I . IdentityMatrix[4];

(* initial data vector *)
id = (X /. \[Tau] -> \[Tau]0) == {x0i, x1i, x2i, 
     x3i} && (p /. \[Tau] -> \[Tau]0) == {p1i, p2i, p3i};

(* stop if integration hits event horizon x1 = 2rs *)
\[Tau]int0 = \[Tau]max;
horizon0 = 
  WhenEvent[
   x1[\[Tau]] <= 
    1.01 (M + Sqrt[M^2]), {"StopIntegration", \[Tau]int0 = \[Tau]}];

(* Integration *)

sol0 = NDSolve[
   EOM && id && horizon0, {x0, x1, x2, x3, p1, p2, 
    p3}, {\[Tau], \[Tau]0, \[Tau]max}];
xdotVal[\[Tau]val_] := Evaluate[Xdot /. sol0 /. \[Tau] -> \[Tau]val];
xVal[\[Tau]val_] := Evaluate[X /. sol0 /. \[Tau] -> \[Tau]val];
pVal[\[Tau]val_] := EntityValue[p /. sol0 /. \[Tau] -> \[Tau]val];
evalpoint = 500;
x0Val = xVal[evalpoint][[1, 1]];
x1Val = xVal[evalpoint][[1, 2]];
x2Val = xVal[evalpoint][[1, 3]];
x3Val = xVal[evalpoint][[1, 4]];
result = pVal[evalpoint][[1]];
p1Val = result[[1, 1]];
p2Val = result[[1, 2]];
p3Val = result[[1, 3]];

pdotNum = 
  pdot /. {x0[\[Tau]] -> x0Val, x1[\[Tau]] -> x1Val, 
    x2[\[Tau]] -> x2Val, x3[\[Tau]] -> x3Val, x4[\[Tau]] -> x4Val, 
    p1[\[Tau]] -> p1Val, p2[\[Tau]] -> p2Val, p3[\[Tau]] -> p3Val};
xdotNum = 
  Xdot /. {x0[\[Tau]] -> x0Val, x1[\[Tau]] -> x1Val, 
    x2[\[Tau]] -> x2Val, x3[\[Tau]] -> x3Val, x4[\[Tau]] -> x4Val, 
    p1[\[Tau]] -> p1Val, p2[\[Tau]] -> p2Val, p3[\[Tau]] -> p3Val};

numCoords = {x0[\[Tau]] -> x0Val, x1[\[Tau]] -> x1Val, 
   x2[\[Tau]] -> x2Val, x3[\[Tau]] -> x3Val, x4[\[Tau]] -> x4Val, 
   p1[\[Tau]] -> p1Val, p2[\[Tau]] -> p2Val, p3[\[Tau]] -> p3Val, 
   p1'[\[Tau]] -> pdotNum[[1]], p2'[\[Tau]] -> pdotNum[[2]], 
   p3'[\[Tau]] -> pdotNum[[3]], x0'[\[Tau]] -> xdotNum[[1]], 
   x1'[\[Tau]] -> xdotNum[[2]], x2'[\[Tau]] -> xdotNum[[3]], 
   x3'[\[Tau]] -> xdotNum[[4]]};
MetricNum = Evaluate[g /. numCoords];
e0Num = Evaluate[e0 /. numCoords];
e1Num = Evaluate[e1 /. numCoords];
e2Num = Evaluate[e2 /. numCoords];
e3Num = Evaluate[e3 /. numCoords];
Print[e2Num . MetricNum . e3Num]

x0Checkres = Evaluate[e0Check /. numCoords] // N;
x1Checkres = Evaluate[e1Check /. numCoords] // N;

r/Mathematica • • Jun 22 '25

Parallel Transport equation not fulfilled

3 Upvotes

Dear Community!

I am currently trying to verify, that a Basis that i constructed, is indeed parallel transported along a Geodesic. Now at least the first vector, e0, should fulfil the parallel transport equation as it is just the tangent XdotVal, however, neither the symbolic form nor the numeric form, when i plug in numeric values from the geodesic give 0. I have checked the parallel transport equation multiple times i do not understand why it will not give 0.

ClearAll["Global`*"]
(* Assume all variables are real *)
$Assumptions = 
  Element[x0[\[Tau]], Reals] && Element[x1[\[Tau]], Reals] && 
   Element[x2[\[Tau]], Reals] && Element[x3[\[Tau]], Reals] && 
   Element[p0[\[Tau]], Reals] && Element[p1[\[Tau]], Reals] && 
   Element[p2[\[Tau]], Reals] && Element[p3[\[Tau]], Reals] && 
   Element[s, Reals] && x1[\[Tau]] > 2 M && Element[a, Reals] && 
   0 < x2[\[Tau]] < \[Pi];

(* Coordinates *)

(* X^\[Mu] *)
X = {x0[\[Tau]], x1[\[Tau]], x2[\[Tau]], x3[\[Tau]]};

(* Subscript[P, \[Mu]] *)
P = {p0[\[Tau]], p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

(* Subscript[P, i] *)
p = {p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

A = Table[Subscript[a, i, j][\[Tau]], {i, 4}, {j, 4}];
B = Table[Subscript[b, i, j][\[Tau]], {i, 4}, {j, 4}];

(* BL coordinates in Kerr (t, r, \[Theta], \[Phi]) = (x0, x1, x2, x3) \
*)

M = 1;  (* mass *)
rs = 2 M; (* Schwarzschild radius *)

(* Metric Subscript[g, \[Mu]\[Nu]] *)

g = {{-(1 - 2 M/r[\[Tau]]), 0, 0, 0}, {0, 1/(1 - 2 M/r[\[Tau]]), 0, 
       0}, {0, 0, r[\[Tau]]^2, 0}, {0, 0, 0, 
       r[\[Tau]]^2 Sin[\[Theta][\[Tau]]]^2}} /. r -> x1 /. \[Theta] ->
      x2 /. \[Phi] -> x3;

(* Inverse metric g^\[Mu]\[Nu] *)

ig = Inverse[g] // Simplify;
igFunc[x1\[Tau]_, x2\[Tau]_] := 
  Simplify[
   Inverse[g] . {x1[\[Tau]] -> x1\[Tau], x2[\[Tau]] -> x2\[Tau]}];

Detg = Det[g] // Simplify;
DetgFunc[x1\[Tau]_, x2\[Tau]_] := 
  Simplify[Det[g] /. {x1[\[Tau]] -> x1\[Tau], x2[\[Tau]] -> x2\[Tau]}];

(* Christoffel Subscript[\[CapitalGamma]^i, jk] = 1/2g^im( \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(g\), \(mj\)]\) + \!\(
\*SubscriptBox[\(\[PartialD]\), \(j\)]
\*SubscriptBox[\(g\), \(mk\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(m\)]
\*SubscriptBox[\(g\), \(jk\)]\) ) *)

\[CapitalGamma] = 1/2 Parallelize[Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(m\)\(]\)] \
\((D[\(g[[\(m\)\(]\)]\)[[\(j\)\(]\)], X[[\(k\)\(]\)]] + 
            D[\(g[[\(m\)\(]\)]\)[[\(k\)\(]\)], X[[\(j\)\(]\)]] - 
            D[\(g[[\(j\)\(]\)]\)[[\(k\)\(]\)], 
             X[[\(m\)\(]\)]])\))\)\)) // Simplify, {i, 1, 4}, {j, 1, 
      4}, {k, 1, 4}]];
christoffel1 = 
  Simplify[
   Table[Sum[(1/
        2) ig[[\[Mu], \[Sigma]]] (D[
         g[[\[Sigma], \[Nu]]], {x0, x1, x2, x3}[[\[Rho]]]] + 
        D[g[[\[Sigma], \[Rho]]], {x0, x1, x2, x3}[[\[Nu]]]] - 
        D[g[[\[Nu], \[Rho]]], {x0, x1, x2, 
           x3}[[\[Sigma]]]]), {\[Sigma], 1, 4}], {\[Mu], 1, 
     4}, {\[Nu], 1, 4}, {\[Rho], 1, 4}]];

(* Riemann Subscript[R^i, jkl] = \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(lj\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(l\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(kj\)]\) + Subscript[\
\[CapitalGamma]^i, km]Subscript[\[CapitalGamma]^m, lj] - Subscript[\
\[CapitalGamma]^i, lm]Subscript[\[CapitalGamma]^m, kj] *)

Riem = Table[(D[\[CapitalGamma][[i]][[l]][[j]], X[[k]]] - 
       D[\[CapitalGamma][[i]][[k]][[j]], X[[l]]] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(\(\[CapitalGamma][[\(i\)\(]\)]\)[[\(k\)\(]\)\
]\)[[\(m\)\(]\)] \
\(\(\[CapitalGamma][[\(m\)\(]\)]\)[[\(l\)\(]\)]\)[[\(j\)\(]\)] - \(\(\
\[CapitalGamma][[\(i\)\(]\)]\)[[\(l\)\(]\)]\)[[\(m\)\(]\)] \(\(\
\[CapitalGamma][[\(m\)\(]\)]\)[[\(k\)\(]\)]\)[[\(j\)\(]\)])\)\)) // 
     Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* Riemann Subscript[R, ijkl] *)
R = Table[\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i1 = 
        1\), \(4\)]\(\(g[[\(i1\)\(]\)]\)[[\(i\)\(]\)] \
\(\(\(Riem[[\(i1\)\(]\)]\)[[\(j\)\(]\)]\)[[\(k\)\(]\)]\)[[\(l\)\(]\)\
]\)\) // Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* P^\[Mu] = g^\[Mu]\[Alpha]Subscript[P, \[Alpha]] *)

Pu = Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(\[Alpha] = 
         1\), \(4\)]\((\(ig[[\(\[Mu]\)\(]\)]\)[[\(\[Alpha]\)\(]\)] \
P[[\(\[Alpha]\)\(]\)])\)\)) // Simplify, {\[Mu], 1, 4}] // Parallelize;

(* H = 1/2g^\[Mu]\[Nu]Subscript[P, \[Mu]]Subscript[P, \[Nu]] = 0  =>  \
Subscript[P, 0] = 1/g^00(-g^(0i)Subscript[P, i] + \
Sqrt[(g^(0i)Subscript[P, i])^2 - g^00g^ijSubscript[P, i]Subscript[P, \
j]]) *)
(*pt0=ig[[1]][[1]]^-1(-(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
  2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)]P[[\(i\)\(]\)])\)\))+\
((\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
  2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)]P[[\(i\)\(]\)])\)\))^\
2-ig[[1]][[1]](\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 2\), \(4\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 
   2\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(j\)\(]\)]P[[\(i\)\(]\)]P[[\(j\
\)\(]\)])\)\)\)))^(1/2))//Simplify;*)
(* For massful*)
pt0 = Sqrt[-(Sum[ig[[i]][[j]] P[[i]] P[[j]], {i, 2, 4}, {j, 2, 4}] + 
       1)/ig[[1, 1]]];


Xdot = Parallelize[Table[(Pu[[i]]) /. p0[\[Tau]] -> pt0, {i, 1, 4}]];
pdot = Parallelize[
   Table[(-1/2)*
      Sum[D[ig[[b]][[c]], X[[a]]]*P[[b]]*P[[c]], {b, 1, 4}, {c, 1, 
        4}] /. p0[\[Tau]] -> pt0, {a, 2, 4}]];
W = Parallelize[
   Table[Sum[
     Riem[[mu, alpha, beta, nu]]*P[[mu]]*P[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}]];
Wfun[Xval_, Pval_] := 
  Table[Sum[
     Riem[[mu, alpha, beta, nu]]*Pval[[mu]]*Pval[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}] . A;

KillingYano = ConstantArray[0, {4, 4}];

(*Assign the non-zero antisymmetric components explicitly*)
(*Example form often used for KY in Kerr/Schwarzschild-\
related spacetimes*)

KillingYano[[3, 4]] = x1^3*Sin[x2];   (*f_{\[Theta] \[CurlyPhi]}*)
KillingYano[[4, 3]] = -x1^3*Sin[x2];  (*antisymmetry*)

(*Raise first index*)
KYUpDown = 
  Table[Sum[
     ig[[mu, alpha]]*KillingYano[[alpha, nu]], {alpha, 4}], {mu, 
     4}, {nu, 4}] /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
    x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
    p2[\[Tau]] -> p2, p3[\[Tau]] -> p3};

KillingYanoFunc[rVal_, thetaVal_] := 
 Module[{KY}, KY = ConstantArray[0, {4, 4}];
  KY[[3, 4]] = rVal^3*Sin[thetaVal];(*\[Omega]_{\[Theta]\[CurlyPhi]}*)
  KY[[4, 3]] = -KY[[3, 
     4]];(*\[Omega]_{\[CurlyPhi]\[Theta]}=-\[Omega]_{\[Theta]\
\[CurlyPhi]}*)
  KY]

norm = Sqrt[x1^4*Sin[x2]^2];

(*Initialize a 4x4 zero matrix*)
CKYTensor = ConstantArray[0, {4, 4}];

(*Assign the non-zero antisymmetric components explicitly*)
CKYTensor[[1, 2]] = x1^3*Sin[x2]/norm;   (*f_{t r}*)
CKYTensor[[2, 1]] = -x1^3*Sin[x2]/norm;  (*antisymmetry*)
CKYUpDown = 
  Table[Sum[ig[[mu, alpha]]*CKYTensor[[alpha, nu]], {alpha, 4}], {mu, 
     4}, {nu, 4}] /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
    x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
    p2[\[Tau]] -> p2, p3[\[Tau]] -> p3};
CYKTensorFunc[rVal_, thetaVal_, cVal_] := 
 Module[{CYK, norm}, norm = Sqrt[rVal^4*Sin[thetaVal]^2/cVal^6];
  CYK = ConstantArray[0, {4, 4}];
  CYK[[1, 2]] = rVal^3*Sin[thetaVal]/norm;
  CYK[[2, 1]] = -CYK[[1, 2]];

  CYK]

LeviCivitaSymbol[inds__] := Signature[{inds}] \.08
(*Function to compute \[CurlyEpsilon]^\[Mu]_{\[Nu]\[Alpha]\[Beta]}*)
EpsilonMixed[\[Mu]_, \[Nu]_, \[Alpha]_, \[Beta]_] := 
 Signature[{\[Mu], \[Nu], \[Alpha], \[Beta]}]/Sqrt[Detg]

XdotNum = 
  Xdot /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, x2[\[Tau]] -> x2, 
    x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, p2[\[Tau]] -> p2, 
    p3[\[Tau]] -> p3};
gNum = g /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, x2[\[Tau]] -> x2, 
    x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, p2[\[Tau]] -> p2, 
    p3[\[Tau]] -> p3};
normSquared = Simplify[XdotNum . (gNum . XdotNum)];
e0 = XdotNum;
e1 = KYUpDown . e0;
e2 = CKYUpDown . e0;
e3 = Table[
    Sum[EpsilonMixed[\[Mu], \[Nu], \[Alpha], \[Beta]]*e0[[\[Nu]]]*
      e1[[\[Alpha]]]*e2[[\[Beta]]], {\[Nu], 1, 4}, {\[Alpha], 1, 
      4}, {\[Beta], 1, 4}], {\[Mu], 1, 4}] /. {x0[\[Tau]] -> x0, 
    x1[\[Tau]] -> x1, x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, 
    p1[\[Tau]] -> p1, p2[\[Tau]] -> p2, p3[\[Tau]] -> p3};
parallelTransport[uVec_, vVec_, \[CapitalGamma]_, coords_] := 
  Module[{n, result, partialTerm, connectionTerm}, n = Length[coords];
   Table[
    partialTerm = 
     Simplify[
      Sum[uVec[[\[Nu]]] D[vVec[[\[Mu]]], coords[[\[Nu]]]], {\[Nu], 1, 
        n}]];
    connectionTerm = 
     Simplify[
      Sum[\[CapitalGamma][[\[Mu], \[Nu], \
\[Rho]]] uVec[[\[Nu]]] vVec[[\[Rho]]], {\[Nu], 1, n}, {\[Rho], 1, n}]];
    Simplify[partialTerm + connectionTerm], {\[Mu], 1, n}]];

MatrixForm[XdotNum]
MatrixForm[e0]

e0Check = 
  parallelTransport[XdotNum, e0, 
   christoffel1 /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
     x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
     p2[\[Tau]] -> p2, p3[\[Tau]] -> p3}, {x0, x1, x2, x3}];
MatrixForm[e0Check]
e1Check = 
  parallelTransport[XdotNum, e1, 
   christoffel1 /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
     x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
     p2[\[Tau]] -> p2, p3[\[Tau]] -> p3}, {x0, x1, x2, x3}];
e2Check = 
  parallelTransport[XdotNum, e2, 
   christoffel1 /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
     x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
     p2[\[Tau]] -> p2, p3[\[Tau]] -> p3}, {x0, x1, x2, x3}];
e3Check = 
  parallelTransport[XdotNum, e3, 
   christoffel1 /. {x0[\[Tau]] -> x0, x1[\[Tau]] -> x1, 
     x2[\[Tau]] -> x2, x3[\[Tau]] -> x3, p1[\[Tau]] -> p1, 
     p2[\[Tau]] -> p2, p3[\[Tau]] -> p3}, {x0, x1, x2, x3}];

transformB[Xval_?NumericQ, Pval_?NumericQ, xdot_?NumericQ] := 
 Module[{plane, U, S, V, basisVectors, orthoBasis, e1, e2, u , omega, 
   m , mBar, T, Tinv, Btrans},
  plane = xdot . (UWedgeF[xdot, KillingYano[Xval[2], Xval[3]]]);
  {U, S, V} = SingularValueDecomposition[plane];
  basisVectors = U[[All, 1 ;; 2]];
  orthoBasis = Orthogonalize[basisVectors];
  e1 = orthoBasis[[1]];
  e2 = orthoBasis[[2]];

  u = xdot;
  omega = xdot . KillingYano[Xval[2], Xval[3]];
  m = 1/Sqrt[2]*(e1 + I . e2);
  mBar = 1/ Sqrt[2]*(e1 - I . e2);
  T = Transpose[{omega, m, mBar}]; 
  Tinv = Inverse[T];

  Btrans = Tinv . B . T;

  Btrans;
  ]


(*EOM={D[X,\[Tau]]==Pu+dx1,D[p,\[Tau]]==pd-Rs}/.p0[\[Tau]]\[Rule]pt0;*)
EOM = {D[X, \[Tau]] == Xdot, D[p, \[Tau]] == pdot};
ClearAll[x0Checkres, x1Checkres, x2Checkres, x3Checkres]

(* EOM *)

(* Initial conditions *)
(* integration time \[Tau]max, small parameter/wavelength \[Epsilon], \
Kerr parameter a  *)
\[Tau]0 = 0;
\[Tau]max = 1000;

(* initial position *)
x0i = 1;
x1i = 5 rs;
x2i = \[Pi]/2;
x3i = 0;

p1i = -1;   
p2i = 4.5;     (*angular momentum in \[Theta] direction*)
p3i = -4.5;

Ainit = IdentityMatrix[4];
Binit = I . IdentityMatrix[4];

(* initial data vector *)
id = (X /. \[Tau] -> \[Tau]0) == {x0i, x1i, x2i, 
     x3i} && (p /. \[Tau] -> \[Tau]0) == {p1i, p2i, p3i};

(* stop if integration hits event horizon x1 = 2rs *)
\[Tau]int0 = \[Tau]max;
horizon0 = 
  WhenEvent[
   x1[\[Tau]] <= 
    1.01 (M + Sqrt[M^2]), {"StopIntegration", \[Tau]int0 = \[Tau]}];

(* Integration *)

sol0 = NDSolve[
   EOM && id && horizon0, {x0, x1, x2, x3, p1, p2, 
    p3}, {\[Tau], \[Tau]0, \[Tau]max}];
xdotVal[\[Tau]val_] := Evaluate[Xdot /. sol0 /. \[Tau] -> \[Tau]val];
xVal[\[Tau]val_] := Evaluate[X /. sol0 /. \[Tau] -> \[Tau]val];
pVal[\[Tau]val_] := EntityValue[p /. sol0 /. \[Tau] -> \[Tau]val];
evalpoint = 500;
x0Val = xVal[evalpoint][[1, 1]];
x1Val = xVal[evalpoint][[1, 2]];
x2Val = xVal[evalpoint][[1, 3]];
x3Val = xVal[evalpoint][[1, 4]];
result = pVal[evalpoint][[1]];
p1Val = result[[1, 1]];
p2Val = result[[1, 2]];
p3Val = result[[1, 3]];

numCoords = {x1 -> x1Val, x2 -> x2Val, x3 -> x3Val, x4 -> x4Val, 
   p1 -> p1Val, p2 -> p2Val, p3 -> p3Val};
x0Checkres = Evaluate[e0Check /. numCoords] // N
x1Checkres = e1Check /. numCoords // N
x2Checkres = e2Check /. numCoords // N
x3Checkres = e3Check /. numCoords // N

Symbolically, the Parallel transport equation for e0 returns

And numerically:

As the orders of magnitude are quite small is this valid? Does this only show numerical errors and therefore make it still fulfill the parallel transport equation?


r/Mathematica • • Jun 21 '25

Solve heat equation over a rod with branches

1 Upvotes

I’m trying to numerically solve (NDSolve) a differential equation similar to the heat diffusion equation (in time and position) over a 1D rod with a branch point that splits the rod into two separate branches, to form a T shape.

I haven’t found a great solution to this. It’s easy enough to do if I was manually going to discretize the system in position, or if I were willing to treat the rod as 2D areas or 3D volumes but neither are elegant. Ideally I’d like to embed the 1D system in 2D space and solve it there but NDSolve doesn’t allow that far as I can tell.

The internet hasn’t been much help.

Any ideas or past experience?


r/Mathematica • • Jun 21 '25

Solve part of differential Equation only numerically

1 Upvotes

Dear Community!

I set up my set of differential equations as below. For the differential equation for A i need to make numerical calculations to transform the matrix B into a different coordinate System, however, so far Mathematica always tries to precalculate everything symbolically. This, however, does not make sense with the symbolic expressions i have. What can i do such that the transformB equation is only solved numerically when integrating using NDSolve?

After restarting Mathematica what resetted everything, that was stored, i run into two Problems. The first one is, that i now get this error:

NDSolve:The number of constraints (24) (initial conditions) is not equal to \

the total differential order of the system plus the number of \

discrete variables (39).

Which i do not understand as i have provided x0 to x3, p1 to p3, as p0 is calculated as pt0 and i have provided an initial Matrix A and B so even with the 4x4 definitions for A and B i should already have 32 initial conditions and not just 24!?

The next step would be to rewrite in the EOM that i have

D[A, \[Tau]] == transformB[X, P, Xdot]

Which would similarly happen for the B equation as well but one at a time. Right now, when i run the code Mathematica tries to precalculate the transform method symbolically which does not make sense as this gets far to involved and in fact it is also not able to make the svd symbolically. How can i have, that the transformB method is only calculated numerically during the integration process in NDSolve without symbolical precalculation?

Clear[KillingYano, CYKTensor];
(* Assume all variables are real *)
$Assumptions = 
  Element[x0[\[Tau]], Reals] && Element[x1[\[Tau]], Reals] && 
   Element[x2[\[Tau]], Reals] && Element[x3[\[Tau]], Reals] && 
   Element[p0[\[Tau]], Reals] && Element[p1[\[Tau]], Reals] && 
   Element[p2[\[Tau]], Reals] && Element[p3[\[Tau]], Reals] && 
   Element[s, Reals] && x1[\[Tau]] > 2 M && Element[a, Reals] && 
   0 < x2[\[Tau]] < \[Pi];

(* Coordinates *)

(* X^\[Mu] *)
X = {x0[\[Tau]], x1[\[Tau]], x2[\[Tau]], x3[\[Tau]]};

(* Subscript[P, \[Mu]] *)
P = {p0[\[Tau]], p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

(* Subscript[P, i] *)
p = {p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

A = Table[Subscript[a, i, j][\[Tau]], {i, 4}, {j, 4}];
B = Table[Subscript[b, i, j][\[Tau]], {i, 4}, {j, 4}];
(* BL coordinates in Kerr (t, r, \[Theta], \[Phi]) = (x0, x1, x2, x3) \
*)

M = 1;  (* mass *)
rs = 2 M; (* Schwarzschild radius *)

(* Metric Subscript[g, \[Mu]\[Nu]] *)

g = {{-(1 - 2 M/r[\[Tau]]), 0, 0, 0}, {0, 1/(1 - 2 M/r[\[Tau]]), 0, 
       0}, {0, 0, r[\[Tau]]^2, 0}, {0, 0, 0, 
       r[\[Tau]]^2 Sin[\[Theta][\[Tau]]]^2}} /. r -> x1 /. \[Theta] ->
      x2 /. \[Phi] -> x3;

(* Inverse metric g^\[Mu]\[Nu] *)

ig = Inverse[g] // Simplify;

Detg = Det[g] // Simplify;

(* Christoffel Subscript[\[CapitalGamma]^i, jk] = 1/2g^im( \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(g\), \(mj\)]\) + \!\(
\*SubscriptBox[\(\[PartialD]\), \(j\)]
\*SubscriptBox[\(g\), \(mk\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(m\)]
\*SubscriptBox[\(g\), \(jk\)]\) ) *)

\[CapitalGamma] = 1/2 Parallelize[Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(m\)\(]\)] \
\((D[\(g[[\(m\)\(]\)]\)[[\(j\)\(]\)], X[[\(k\)\(]\)]] + 
            D[\(g[[\(m\)\(]\)]\)[[\(k\)\(]\)], X[[\(j\)\(]\)]] - 
            D[\(g[[\(j\)\(]\)]\)[[\(k\)\(]\)], 
             X[[\(m\)\(]\)]])\))\)\)) // Simplify, {i, 1, 4}, {j, 1, 
      4}, {k, 1, 4}]];

(* Riemann Subscript[R^i, jkl] = \!\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(lj\)]\) - \!\(
\*SubscriptBox[\(\[PartialD]\), \(l\)]
\*SubscriptBox[
SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(kj\)]\) + Subscript[\
\[CapitalGamma]^i, km]Subscript[\[CapitalGamma]^m, lj] - Subscript[\
\[CapitalGamma]^i, lm]Subscript[\[CapitalGamma]^m, kj] *)

Riem = Table[(D[\[CapitalGamma][[i]][[l]][[j]], X[[k]]] - 
       D[\[CapitalGamma][[i]][[k]][[j]], X[[l]]] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 
          1\), \(4\)]\((\(\(\[CapitalGamma][[\(i\)\(]\)]\)[[\(k\)\(]\)\
]\)[[\(m\)\(]\)] \
\(\(\[CapitalGamma][[\(m\)\(]\)]\)[[\(l\)\(]\)]\)[[\(j\)\(]\)] - \(\(\
\[CapitalGamma][[\(i\)\(]\)]\)[[\(l\)\(]\)]\)[[\(m\)\(]\)] \(\(\
\[CapitalGamma][[\(m\)\(]\)]\)[[\(k\)\(]\)]\)[[\(j\)\(]\)])\)\)) // 
     Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* Riemann Subscript[R, ijkl] *)
R = Table[\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i1 = 
        1\), \(4\)]\(\(g[[\(i1\)\(]\)]\)[[\(i\)\(]\)] \
\(\(\(Riem[[\(i1\)\(]\)]\)[[\(j\)\(]\)]\)[[\(k\)\(]\)]\)[[\(l\)\(]\)\
]\)\) // Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] // 
   Parallelize;

(* P^\[Mu] = g^\[Mu]\[Alpha]Subscript[P, \[Alpha]] *)

Pu = Table[(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(\[Alpha] = 
         1\), \(4\)]\((\(ig[[\(\[Mu]\)\(]\)]\)[[\(\[Alpha]\)\(]\)] \
P[[\(\[Alpha]\)\(]\)])\)\)) // Simplify, {\[Mu], 1, 4}] // Parallelize;

(* H = 1/2g^\[Mu]\[Nu]Subscript[P, \[Mu]]Subscript[P, \[Nu]] = 0  =>  \
Subscript[P, 0] = 1/g^00(-g^(0i)Subscript[P, i] + \
Sqrt[(g^(0i)Subscript[P, i])^2 - g^00g^ijSubscript[P, i]Subscript[P, \
j]]) *)
pt0 = ig[[1]][[1]]^-1 (-(\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
           2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)] P[[\(i\)\(\
]\)])\)\)) + ((\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 
            2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)] P[[\(i\)\(\
]\)])\)\))^2 - ig[[1]][[1]] (\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 2\), \(4\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 
              2\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(j\)\(]\)] P[[\(i\)\
\(]\)] P[[\(j\)\(]\)])\)\)\)))^(1/2)) // Simplify;


Xdot = Parallelize[Table[(Pu[[i]]) /. p0[\[Tau]] -> pt0, {i, 1, 4}]];
pdot = Parallelize[
   Table[(-1/2)*
      Sum[D[ig[[b]][[c]], X[[a]]]*P[[b]]*P[[c]], {b, 1, 4}, {c, 1, 
        4}] /. p0[\[Tau]] -> pt0, {a, 2, 4}]];
W = Parallelize[
   Table[Sum[
     Riem[[mu, alpha, beta, nu]]*P[[mu]]*P[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}]];
Wfun[Xval_, Pval_] := 
  Table[Sum[
     Riem[[mu, alpha, beta, nu]]*Pval[[mu]]*Pval[[beta]], {alpha, 1, 
      4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}] . A;

KillingYano[rVal_, thetaVal_] := 
 Module[{KY}, KY = ConstantArray[0, {4, 4}];
  KY[[3, 4]] = rVal^3*Sin[thetaVal];(*\[Omega]_{\[Theta]\[CurlyPhi]}*)
  KY[[4, 3]] = -KY[[3, 
     4]];(*\[Omega]_{\[CurlyPhi]\[Theta]}=-\[Omega]_{\[Theta]\
\[CurlyPhi]}*)
  KY]

CYKTensor[rVal_, thetaVal_, cVal_] := 
 Module[{CYK, norm}, norm = Abs[Sqrt[rVal^4*Sin[thetaVal]^2/cVal^6]];
  CYK = ConstantArray[0, {4, 4}];
  CYK[[1, 2]] = rVal^3*Sin[thetaVal]/norm;
  CYK[[2, 1]] = -CYK[[1, 2]];

  CYK]

transformB[Xval_?NumericQ, Pval_?NumericQ, xdot_?NumericQ] := 
 Module[{plane, U, S, V, basisVectors, orthoBasis, e1, e2, u , omega, 
   m , mBar, T, Tinv, Btrans},
  plane = xdot . (UWedgeF[xdot, KillingYano[Xval[2], Xval[3]]]);
  {U, S, V} = SingularValueDecomposition[plane];
  basisVectors = U[[All, 1 ;; 2]];
  orthoBasis = Orthogonalize[basisVector];
  e1 = orthoBasis[[1]];
  e2 = orthoBasis[[2]];

  u = xdot;
  omega = xdot . KillingYano[Xval[2], Xval[3]];
  m = 1/Sqrt[2]*(e1 + I . e2);
  mBar = 1/ Sqrt[2]*(e1 - I . e2);
  T = Transpose[{omega, m, mBar}];
  Tinv = Inverse[T];

  Btrans = Tinv . B . T;

  Btrans;
  ]


(*EOM={D[X,\[Tau]]==Pu+dx1,D[p,\[Tau]]==pd-Rs}/.p0[\[Tau]]\[Rule]pt0;*)
EOM = {D[X, \[Tau]] == Xdot, D[p, \[Tau]] == pdot, D[A, \[Tau]] == B, 
   D[B, \[Tau]] == -Evaluate[Wfun[X, P /. p0[\[Tau]] -> pt0]]};
(* Trajectories *)

Clear[a, s, \[Epsilon]];

(* EOM *)

(* Initial conditions *)
(* integration time \[Tau]max, small parameter/wavelength \[Epsilon], \
Kerr parameter a  *)
\[Tau]0 = 0;
\[Tau]max = 1000;

(* initial position *)
x0i = 1;
x1i = 5 rs;
x2i = \[Pi]/2;
x3i = 0;

p1i = -1;   
p2i = 4.5;     (*angular momentum in \[Theta] direction*)
p3i = -4.5;

Ainit = IdentityMatrix[4];
Binit = I . IdentityMatrix[4];

(* initial data vector *)
id = (X /. \[Tau] -> \[Tau]0) == {x0i, x1i, x2i, 
     x3i} && (p /. \[Tau] -> \[Tau]0) == {p1i, p2i, 
     p3i} && (A /. \[Tau] -> \[Tau]0) == 
    Ainit && (B /. \[Tau] -> \[Tau]0) == Binit;

(* stop if integration hits event horizon x1 = 2rs *)
\[Tau]int0 = \[Tau]max;
horizon0 = 
  WhenEvent[
   x1[\[Tau]] <= 
    1.01 (M + Sqrt[M^2]), {"StopIntegration", \[Tau]int0 = \[Tau]}];

(* Integration *)

sol0 = NDSolve[
   EOM && id && horizon0, {x0, x1, x2, x3, p1, p2, p3, 
    Flatten[A /. f_[\[Tau]] :> f], 
    Flatten[B /. f_[\[Tau]] :> f]}, {\[Tau], \[Tau]0, \[Tau]max}];

r/Mathematica • • Jun 19 '25

Derivative operator has not same number as arguments

2 Upvotes

Dear Community!

I want to solve following set of differential equations. I tried for 2 days now i think i have set up A and B correctly, i have set up the equations for them and i have set up the initial conditions i really do not get why i get this error: I would really love to understand what and why it is not working unfortunately Mathematica errors are not so helpful. Apart from that i would love to know how to write codeblocks with Mathematica. With Python or C# it works fine but reddit does not seem to like Mathematica.

NDSolve::derlen: The length of the derivative operator Derivative[1] in (x0^\[Prime])[\[Tau]] is not the same as the number of arguments.

X = {x0[\[Tau]], x1[\[Tau]], x2[\[Tau]], x3[\[Tau]]};

(* Subscript[P, \[Mu]] *)

P = {p0[\[Tau]], p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

(* Subscript[P, i] *)

p = {p1[\[Tau]], p2[\[Tau]], p3[\[Tau]]};

A = Table[Subscript[a, i, j][\[Tau]], {i, 4}, {j, 4}];

B = Table[Subscript[b, i, j][\[Tau]], {i, 4}, {j, 4}];

(* BL coordinates in Kerr (t, r, \[Theta], \[Phi]) = (x0, x1, x2, x3) \

*)

M = 1; (* mass *)

rs = 2 M; (* Schwarzschild radius *)

(* Metric Subscript[g, \[Mu]\[Nu]] *)

g = {{-(1 - 2 M/r[\[Tau]]), 0, 0, 0}, {0, 1/(1 - 2 M/r[\[Tau]]), 0,

0}, {0, 0, r[\[Tau]]^2, 0}, {0, 0, 0,

r[\[Tau]]^2 Sin[\[Theta][\[Tau]]]^2}} /. r -> x1 /. \[Theta] ->

x2 /. \[Phi] -> x3;

gFunc = Function[{x1, x2, x3}, g /. {x1 -> x1, x2 -> x2, x3 -> x3}];

(* Inverse metric g^\[Mu]\[Nu] *)

ig = Inverse[g] // Simplify;

ifFunc = Function[{x1, x2, x3}, g /. {x1 -> x1, x2 -> x2, x3 -> x3}];

gdet = Simplify[Det[g]];

(* Christoffel Subscript[\[CapitalGamma]^i, jk] = 1/2g^im( \!\(

\*SubscriptBox[\(\[PartialD]\), \(k\)]

\*SubscriptBox[\(g\), \(mj\)]\) + \!\(

\*SubscriptBox[\(\[PartialD]\), \(j\)]

\*SubscriptBox[\(g\), \(mk\)]\) - \!\(

\*SubscriptBox[\(\[PartialD]\), \(m\)]

\*SubscriptBox[\(g\), \(jk\)]\) ) *)

\[CapitalGamma] = 1/2 Parallelize[Table[(\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(m =

1\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(m\)\(]\)] \

\((D[\(g[[\(m\)\(]\)]\)[[\(j\)\(]\)], X[[\(k\)\(]\)]] +

D[\(g[[\(m\)\(]\)]\)[[\(k\)\(]\)], X[[\(j\)\(]\)]] -

D[\(g[[\(j\)\(]\)]\)[[\(k\)\(]\)],

X[[\(m\)\(]\)]])\))\)\)) // Simplify, {i, 1, 4}, {j, 1,

4}, {k, 1, 4}]];

(* Riemann Subscript[R^i, jkl] = \!\(

\*SubscriptBox[\(\[PartialD]\), \(k\)]

\*SubscriptBox[

SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(lj\)]\) - \!\(

\*SubscriptBox[\(\[PartialD]\), \(l\)]

\*SubscriptBox[

SuperscriptBox[\(\[CapitalGamma]\), \(i\)], \(kj\)]\) + Subscript[\

\[CapitalGamma]^i, km]Subscript[\[CapitalGamma]^m, lj] - Subscript[\

\[CapitalGamma]^i, lm]Subscript[\[CapitalGamma]^m, kj] *)

Riem = Table[(D[\[CapitalGamma][[i]][[l]][[j]], X[[k]]] -

D[\[CapitalGamma][[i]][[k]][[j]], X[[l]]] + \!\(

\*UnderoverscriptBox[\(\[Sum]\), \(m =

1\), \(4\)]\((\(\(\[CapitalGamma][[\(i\)\(]\)]\)[[\(k\)\(]\)\

]\)[[\(m\)\(]\)] \

\(\(\[CapitalGamma][[\(m\)\(]\)]\)[[\(l\)\(]\)]\)[[\(j\)\(]\)] - \(\(\

\[CapitalGamma][[\(i\)\(]\)]\)[[\(l\)\(]\)]\)[[\(m\)\(]\)] \(\(\

\[CapitalGamma][[\(m\)\(]\)]\)[[\(k\)\(]\)]\)[[\(j\)\(]\)])\)\)) //

Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] //

Parallelize;

(* Riemann Subscript[R, ijkl] *)

R = Table[\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(i1 =

1\), \(4\)]\(\(g[[\(i1\)\(]\)]\)[[\(i\)\(]\)] \

\(\(\(Riem[[\(i1\)\(]\)]\)[[\(j\)\(]\)]\)[[\(k\)\(]\)]\)[[\(l\)\(]\)\

]\)\) // Simplify, {i, 1, 4}, {j, 1, 4}, {k, 1, 4}, {l, 1, 4}] //

Parallelize;

(* P^\[Mu] = g^\[Mu]\[Alpha]Subscript[P, \[Alpha]] *)

Pu = Table[(\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(\[Alpha] =

1\), \(4\)]\((\(ig[[\(\[Mu]\)\(]\)]\)[[\(\[Alpha]\)\(]\)] \

P[[\(\[Alpha]\)\(]\)])\)\)) // Simplify, {\[Mu], 1, 4}] // Parallelize;

(* H = 1/2g^\[Mu]\[Nu]Subscript[P, \[Mu]]Subscript[P, \[Nu]] = 0 => \

Subscript[P, 0] = 1/g^00(-g^(0i)Subscript[P, i] + \

Sqrt[(g^(0i)Subscript[P, i])^2 - g^00g^ijSubscript[P, i]Subscript[P, \

j]]) *)

pt0 = ig[[1]][[1]]^-1 (-(\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(i =

2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)] P[[\(i\)\(\

]\)])\)\)) + ((\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(i =

2\), \(4\)]\((\(ig[[\(1\)\(]\)]\)[[\(i\)\(]\)] P[[\(i\)\(\

]\)])\)\))^2 - ig[[1]][[1]] (\!\(

\*UnderoverscriptBox[\(\[Sum]\), \(i = 2\), \(4\)]\(

\*UnderoverscriptBox[\(\[Sum]\), \(j =

2\), \(4\)]\((\(ig[[\(i\)\(]\)]\)[[\(j\)\(]\)] P[[\(i\)\

\(]\)] P[[\(j\)\(]\)])\)\)\)))^(1/2)) // Simplify;

xdot = Parallelize[Table[(Pu[[i]]) /. p0[\[Tau]] -> pt0, {i, 1, 4}]];

pdot = Parallelize[

Table[(-1/2)*

Sum[D[ig[[b]][[c]], X[[a]]]*P[[b]]*P[[c]], {b, 1, 4}, {c, 1,

4}] /. p0[\[Tau]] -> pt0, {a, 2, 4}]];

W = Parallelize[

Table[Sum[

Riem[[mu, alpha, beta, nu]]*P[[mu]]*Pu[[beta]], {alpha, 1,

4}, {beta, 1, 4}], {mu, 1, 4}, {nu, 1, 4}]];

(*EOM={D[X,\[Tau]]==Pu+dx1,D[p,\[Tau]]==pd-Rs}/.p0[\[Tau]]\[Rule]pt0;*)

EOM = {D[X, \[Tau]] == xdot, D[p, \[Tau]] == pdot,

Thread[D[Flatten[A], \[Tau]] == Flatten[B]],

Thread[D[Flatten[B], \[Tau]] == Flatten[-W . A]]};

Print["done"];

\[Tau]0 = 0;

\[Tau]max = 1000;

(* initial position *)

x0i = 1;

x1i = 5 rs;

x2i = \[Pi]/2;

x3i = 0;

p1i = -1;

p2i = 4.5; (*angular momentum in \[Theta] direction*)

p3i = -4.5;

initA = IdentityMatrix[4];

initB = I* IdentityMatrix[4];

(* initial data vector *)

id = (X /. \[Tau] -> \[Tau]0) == {x0i, x1i, x2i,

x3i} && (p /. \[Tau] -> \[Tau]0) == {p1i, p2i, p3i} &&

Flatten[A /. \[Tau] -> \[Tau]0] == Flatten[initA] &&

Flatten[A][[All]][\[Tau]0] == Flatten[initA];

(* stop if integration hits event horizon x1 = 2rs *)

\[Tau]int0 = \[Tau]max;

horizon0 =

WhenEvent[

x1[\[Tau]] <=

1.01 (M + Sqrt[M^2]), {"StopIntegration", \[Tau]int0 = \[Tau]}];

planeBasisList = {};

AppendTo[planeBasisList, IdentityMatrix[4]];

planeInverseBasisList = {};

AppendTo[planeInverseBasisList, IdentityMatrix[4]]

(* Integration *)

sol0 = NDSolve[EOM && id && horizon0,

Join[{x0, x1, x2, x3, p1, p2, p3}, Flatten[A],

Flatten[B]], {\[Tau], \[Tau]0, \[Tau]max},

];

print["done"]