# Multiple function definition inside a whenevent [closed]

I am trying to implement a whenevent inside a NdSolve such that when a particle reaches within earths radius its position becomes a constant <0,0,0>. When I set one function x[t]-> 0 it works. However multiple functions do not work.

sol[x0_, y0_, z0_, v0x_, v0y_, v0z_] :=
Flatten[NDSolve[{x''[t] == -G*
M ((x[t])/(x[t]^2 + y[t]^2 + z[t]^2)^(3/2)),
y''[t] == -(G*M (y[t])/(x[t]^2 + y[t]^2 + z[t]^2)^(3/2)),
z''[t] == -G*M ((z[t])/(x[t]^2 + y[t]^2 + z[t]^2)^(3/2)),
x[0] == x0, y[0] == y0, z[0] == z0, x'[0] == v0x,
y'[0] == v0y, z'[0] == v0z,
WhenEvent[(x[t]^2 + y[t]^2 + z[t]^2)^(1/2) ==
6871000, {x[t] -> 0, y[t] -> 0, z[t] -> 0}]}, {x[t], y[t],
z[t]}, {t, 0, 10000}]];

• Please post the full code. What is the G and M? Commented Jul 9, 2023 at 13:20
• G is the gravitational constant and M is the mass of the earth. They are constants defined earlier Commented Jul 9, 2023 at 13:37
• it also helps to show the call you made, and also explain why/how However multiple functions do not work mean. i.e. how will one running your code know that it did not work? Commented Jul 9, 2023 at 13:37
• They are constants defined earlier The comment meant that you should include these in your question. Do not let others do the work that you are supposed to do. Your code should be self contained and complete. Commented Jul 9, 2023 at 13:38
• It's harder to help if you don't include an MWE. -- BTW, the ODE is undefined at $(0,0,0)$, so the event action would cause NDSolve to throw an error. Maybe you want "StopIntegration" instead? (Also QuantityMagnitude@ UnitConvert[Entity["Planet", "Earth"][EntityProperty["Planet", "Radius"]], "Meters"] has a 3 where you have an 8, but since the Earth is not a sphere, I don't know if that matters to you.) Commented Jul 9, 2023 at 16:26