0
$\begingroup$

ADDED LATER: READ THE POST SCRIPT TEXT AT THE END

Before saying anything else I would like to say please don't edit my codes in this question. I know that they are not formatted properly but they'll work (or you can say not work) and show the same error message that I get. Just copy and paste. After you paste them in mathematica they'll automatically be formatted as they should be in a nice way. While answering the question you may want to post properly formatted code if you wish.

Okay this is going to be be a complicated question. I have four differential equations with variables $r[s], \theta[s],\phi[s],t[s]$ where $s$ is used to parameterize all equations. The differential equations are humongous but still I am posting it as I cannot figure out where the problem is. Mathematica is considering $\theta$ to be an independent variable but since I have parameterized the equation with $s$ the only independent parameter/variable which should remain is $s$. The error which I am receiving from mathematica while trying to use NDSolve function is

NDSolve::ivhead: The independent variable θ appears in the head of the expression θ[s]. The independent variables should always be arguments.

I am posting the differential equations for if someone can find for me where the error is that'll be great. I am trying to make it work since more than 8 hours and I have lost all patience. All the coordinates are labelled as a function of $s$. The differential equations are correct and the only place the problem is should be labeling in labeling coordinates as $\theta[s]$

$$\text{Radial Equation}$$

radial = ((r[s] (2 a^2 + r[s] (-3 M + r[s])) + 
  a^2 (M - r[s]) Cos[θ[s]]^2) r'[
 s]^2)/((a^2 + r[s] (-2 M + r[s])) (r[s]^2 + 
  a^2 Cos[θ[s]]^2)) - (
M (a^2 + r[s] (-2 M + r[s])) (-3 r[s]^2 + 
  a^2 Cos[θ[s]]^2) t'[s]^2)/(r[s]^2 + 
 a^2 Cos[θ[s]]^2)^5 - (
4 a^2 Cos[θ[s]] Sin[θ[s]] r'[s] θ'[s])/(
r[s]^2 + a^2 Cos[θ[s]]^2) - (
2 r[s] (a^2 + r[s] (-2 M + r[s])) θ'[s]^2)/(
r[s]^2 + a^2 Cos[θ[s]]^2) - (
2 a M (a^2 + r[s] (-2 M + r[s])) (-3 r[s]^2 + 
  a^2 Cos[θ[s]]^2) Sin[θ[s]]^2 t'[s] ϕ'[
 s])/(r[s]^2 + 
 a^2 Cos[θ[s]]^2)^5 + ((a^2 + 
  r[s] (-2 M + r[s])) (-2 r[s] Sin[θ[s]]^2 - (
  2 a^2 M (-3 r[s]^2 + a^2 Cos[θ[s]]^2) Sin[θ[
     s]]^4)/(r[s]^2 + a^2 Cos[θ[s]]^2)^3) ϕ'[s]^2)/(
2 (r[s]^2 + a^2 Cos[θ[s]]^2)^2) + r''[s];

$$\text{Theta Equation}$$

theta = (Sin[2 θ[s]] r'[
 s]^2)/((1 + r[s] (-2 M + r[s])) (r[s]^2 + 
  Cos[θ[s]]^2)) - (
 64 M r[s] Cos[θ[s]] Sin[θ[s]] t'[s]^2)/(r[s]^2 + 
 16 Cos[θ[s]]^2)^5 + (2 r[s] r'[s] θ'[s])/(
 r[s]^2 + Cos[θ[s]]^2) + (2 r[s] r'[s] θ'[s])/(
r[s]^2 + 4 Cos[θ[s]]^2) - (
8 Cos[θ[s]] Sin[θ[s]] θ'[s]^2)/(
r[s]^2 + 4 Cos[θ[s]]^2) + (
3 M r[s] Cos[θ[s]] (-27 - 2 r[s]^2 + 
  9 Cos[2 θ[s]]) Sin[θ[s]] t'[s] ϕ'[
 s])/(r[s]^2 + 9 Cos[θ[s]]^2)^5 + (
4 M r[s] Cos[θ[s]] (-48 - 2 r[s]^2 + 
  16 Cos[2 θ[s]]) Sin[θ[s]] t'[s] ϕ'[
 s])/(r[s]^2 + 16 Cos[θ[s]]^2)^5 + 
1/(r[s]^2 + 9 Cos[θ[s]]^2)^5 Cos[θ[s]] Sin[θ[
  s]] ((9 - r[s]^2) (r[s]^2 + 9 Cos[θ[s]]^2)^3 - 
  36 M r[s] (r[s]^2 + 9 Cos[θ[s]]^2) Sin[θ[s]]^2 - 
  324 M r[s] Sin[θ[s]]^4) ϕ'[s]^2 + θ''[s];

$$\text{Phi Equation}$$

phi = (M (-3 r[s]^2 + Cos[θ[s]]^2) r'[s] t'[
   s])/((r[s]^2 + 
    Cos[θ[s]]^2) (r[s] (-1 + r[s]^2) (-2 M + r[s]^3) - 
    2 r[s]^2 (1 - r[s]^2) Cos[θ[s]]^2 + (-1 + 
       r[s]^2) Cos[θ[s]]^4 + 
    2 M r[s] Sin[θ[s]]^2)) + (4 M (-3 r[s]^2 + 
    16 Cos[θ[s]]^2) r'[s] t'[
   s])/((r[s]^2 + 
    16 Cos[θ[s]]^2) (r[s] (-16 + r[s]^2) (-2 M + r[s]^3) - 
    32 r[s]^2 (16 - r[s]^2) Cos[θ[s]]^2 + (-4096 + 
       256 r[s]^2) Cos[θ[s]]^4 + 
    32 M r[s] Sin[θ[s]]^2)) + (M r[
   s] (80 - 16 M r[s] + 64 r[s]^2 + 8 r[s]^4 + 
    64 Cos[2 θ[s]] - 16 Cos[4 θ[s]]) Cot[θ[
    s]] t'[s] θ'[
   s])/(2 (r[s]^2 + 
    4 Cos[θ[s]]^2)^2 (r[s] (-4 + r[s]^2) (-2 M + r[s]^3) - 
    8 r[s]^2 (4 - r[s]^2) Cos[θ[s]]^2 + (-64 + 
       16 r[s]^2) Cos[θ[s]]^4 + 
    8 M r[s] Sin[θ[s]]^2)) + (M r[
   s] (1280 - 16 M r[s] + 256 r[s]^2 + 8 r[s]^4 + 
    1024 Cos[2 θ[s]] - 
    256 Cos[4 θ[s]]) Cot[θ[s]] t'[s] θ'[
   s])/((r[s]^2 + 
    16 Cos[θ[s]]^2)^2 (r[
      s] (-16 + r[s]^2) (-2 M + r[s]^3) - 
    32 r[s]^2 (16 - r[s]^2) Cos[θ[s]]^2 + (-4096 + 
       256 r[s]^2) Cos[θ[s]]^4 + 
    32 M r[s] Sin[θ[s]]^2)) + ((-2 M r[s]^4 + r[s]^7 + 
    3 r[s]^3 Cos[θ[s]]^4 + r[s] Cos[θ[s]]^6 - 
    3 M r[s]^2 Sin[θ[s]]^2 + 
    Cos[θ[s]]^2 (-2 M r[s]^2 + 3 r[s]^5 + 
       M Sin[θ[s]]^2)) r'[s] ϕ'[
   s])/((r[s]^2 + 
    Cos[θ[s]]^2) (r[s] (-1 + r[s]^2) (-2 M + r[s]^3) - 
    2 r[s]^2 (1 - r[s]^2) Cos[θ[s]]^2 + (-1 + 
       r[s]^2) Cos[θ[s]]^4 + 
    2 M r[s] Sin[θ[s]]^2)) + ((-2 M r[s]^4 + r[s]^7 + 
    243 r[s]^3 Cos[θ[s]]^4 + 729 r[s] Cos[θ[s]]^6 - 
    27 M r[s]^2 Sin[θ[s]]^2 + 
    9 Cos[θ[s]]^2 (-2 M r[s]^2 + 3 r[s]^5 + 
       9 M Sin[θ[s]]^2)) r'[s] ϕ'[
   s])/((r[s]^2 + 
    9 Cos[θ[s]]^2) (r[s] (-9 + r[s]^2) (-2 M + r[s]^3) - 
    18 r[s]^2 (9 - r[s]^2) Cos[θ[s]]^2 + (-729 + 
       81 r[s]^2) Cos[θ[s]]^4 + 
    18 M r[s] Sin[θ[s]]^2)) - (Csc[θ[
    s]] (256 r[s]^2 (4 - r[s]^2) Cos[θ[s]]^7 + 
    256 (4 - r[s]^2) Cos[θ[s]]^9 + 
    32 r[s] Cos[θ[s]]^5 (r[s]^2 (M - 3 r[s]^3) + 
       4 (-2 M + 3 r[s]^3) + 4 M Cos[2 θ[s]]) - 
    4 Cos[θ[s]]^3 (4 r[s]^3 (4 - r[s]^2) (M - r[s]^3) + 
       64 M r[s] Sin[θ[s]]^4) - 
    r[s]^2 Cos[θ[
       s]] (r[s]^3 (-4 + r[s]^2) (-2 M + r[s]^3) - 
       16 M (M - r[s]^3) Sin[θ[s]]^2 + 
       64 M r[s] Sin[θ[s]]^4 + 
       32 M r[s] Sin[2 θ[s]]^2)) θ'[s] ϕ'[
   s])/((r[s]^2 + 
    4 Cos[θ[s]]^2)^2 (r[s] (-4 + r[s]^2) (-2 M + r[s]^3) - 
    8 r[s]^2 (4 - r[s]^2) Cos[θ[s]]^2 + (-64 + 
       16 r[s]^2) Cos[θ[s]]^4 + 
    8 M r[s] Sin[θ[s]]^2)) - (Csc[θ[
    s]] (2916 r[s]^2 (9 - r[s]^2) Cos[θ[s]]^7 + 
    6561 (9 - r[s]^2) Cos[θ[s]]^9 + 
    162 r[s] Cos[θ[s]]^5 (r[s]^2 (M - 3 r[s]^3) + 
       9 (-2 M + 3 r[s]^3) + 9 M Cos[2 θ[s]]) - 
    4 Cos[θ[s]]^3 (9 r[s]^3 (9 - r[s]^2) (M - r[s]^3) + 
       729 M r[s] Sin[θ[s]]^4) - 
    r[s]^2 Cos[θ[
       s]] (r[s]^3 (-9 + r[s]^2) (-2 M + r[s]^3) - 
       36 M (M - r[s]^3) Sin[θ[s]]^2 + 
       324 M r[s] Sin[θ[s]]^4 + 
       162 M r[s] Sin[2 θ[s]]^2)) θ'[s] ϕ'[
   s])/((r[s]^2 + 
    9 Cos[θ[s]]^2)^2 (r[s] (-9 + r[s]^2) (-2 M + r[s]^3) - 
    18 r[s]^2 (9 - r[s]^2) Cos[θ[s]]^2 + (-729 + 
       81 r[s]^2) Cos[θ[s]]^4 + 
    18 M r[s] Sin[θ[s]]^2)) + ϕ''[s];

$$\text{Time Equation}$$

time = (M (1 - r[s]^2) (-3 r[s]^2 + Cos[θ[s]]^2) r'[s] t'[
   s])/((r[s]^2 + 
    Cos[θ[s]]^2) (r[s] (-1 + r[s]^2) (-2 M + r[s]^3) - 
    2 r[s]^2 (1 - r[s]^2) Cos[θ[s]]^2 + (-1 + 
       r[s]^2) Cos[θ[s]]^4 + 
    2 M r[s] Sin[θ[s]]^2)) + (M (16 - r[s]^2) (-3 r[s]^2 + 
    16 Cos[θ[s]]^2) r'[s] t'[
   s])/((r[s]^2 + 
    16 Cos[θ[s]]^2) (r[s] (-16 + r[s]^2) (-2 M + r[s]^3) - 
    32 r[s]^2 (16 - r[s]^2) Cos[θ[s]]^2 + (-4096 + 
       256 r[s]^2) Cos[θ[s]]^4 + 
    32 M r[s] Sin[θ[s]]^2)) + (4 M r[
   s] (16 + 2 M r[s] + 4 r[s]^2 - 2 r[s]^4 + 
    4 (4 - r[s]^2) Cos[2 θ[s]]) Sin[2 θ[s]] t'[
   s] θ'[
   s])/((r[s]^2 + 
    4 Cos[θ[s]]^2)^2 (r[s] (-4 + r[s]^2) (-2 M + r[s]^3) - 
    8 r[s]^2 (4 - r[s]^2) Cos[θ[s]]^2 + (-64 + 
       16 r[s]^2) Cos[θ[s]]^4 + 
    8 M r[s] Sin[θ[s]]^2)) + (16 M r[
   s] (256 + 2 M r[s] + 16 r[s]^2 - 2 r[s]^4 + 
    16 (16 - r[s]^2) Cos[2 θ[s]]) Sin[2 θ[s]] t'[
   s] θ'[
   s])/((r[s]^2 + 
    16 Cos[θ[s]]^2)^2 (r[
      s] (-16 + r[s]^2) (-2 M + r[s]^3) - 
    32 r[s]^2 (16 - r[s]^2) Cos[θ[s]]^2 + (-4096 + 
       256 r[s]^2) Cos[θ[s]]^4 + 
    32 M r[s] Sin[θ[s]]^2)) + (M (1 - 5 r[s]^2 + 
    10 r[s]^4 + (1 + r[s]^2) Cos[2 θ[s]]) Sin[θ[
    s]]^2 r'[s] ϕ'[
   s])/(2 (r[s]^2 + 
    Cos[θ[s]]^2) (r[s] (-1 + r[s]^2) (-2 M + r[s]^3) - 
    2 r[s]^2 (1 - r[s]^2) Cos[θ[s]]^2 + (-1 + 
       r[s]^2) Cos[θ[s]]^4 + 
    2 M r[s] Sin[θ[s]]^2)) + (3 M (81 - 45 r[s]^2 + 
    10 r[s]^4 + 9 (9 + r[s]^2) Cos[2 θ[s]]) Sin[θ[
    s]]^2 r'[s] ϕ'[
   s])/(2 (r[s]^2 + 
    9 Cos[θ[s]]^2) (r[s] (-9 + r[s]^2) (-2 M + r[s]^3) - 
    18 r[s]^2 (9 - r[s]^2) Cos[θ[s]]^2 + (-729 + 
       81 r[s]^2) Cos[θ[s]]^4 + 
    18 M r[s] Sin[θ[s]]^2)) + (16 M r[
   s] Cos[θ[s]] (16 + 2 M r[s] + 4 r[s]^2 - 2 r[s]^4 + 
    4 (4 - r[s]^2) Cos[2 θ[s]]) Sin[θ[
    s]]^3 θ'[s] ϕ'[
   s])/((r[s]^2 + 
    4 Cos[θ[s]]^2)^2 (r[s] (-4 + r[s]^2) (-2 M + r[s]^3) - 
    8 r[s]^2 (4 - r[s]^2) Cos[θ[s]]^2 + (-64 + 
       16 r[s]^2) Cos[θ[s]]^4 + 
    8 M r[s] Sin[θ[s]]^2)) + (54 M r[
   s] Cos[θ[s]] (81 + 2 M r[s] + 9 r[s]^2 - 2 r[s]^4 + 
    9 (9 - r[s]^2) Cos[2 θ[s]]) Sin[θ[
    s]]^3 θ'[s] ϕ'[
   s])/((r[s]^2 + 
    9 Cos[θ[s]]^2)^2 (r[s] (-9 + r[s]^2) (-2 M + r[s]^3) - 
    18 r[s]^2 (9 - r[s]^2) Cos[θ[s]]^2 + (-729 + 
       81 r[s]^2) Cos[θ[s]]^4 + 
    18 M r[s] Sin[θ[s]]^2)) + t''[s];

These are the $4$ 2nd order ordinary differential equations which I am trying to solve simultaneously using NDSolve. The code for that is

NDSolve[{time == 0, radial == 0, phi == 0, theta == 0, 
r[0] == 8, ϕ[0] == 0, t[0] == 0, ϕ'[0] == 0.1, t'[0] == 0,
r'[0] == 0.1}, r, t, ϕ, θ, {s, 0, 1}]

Post Script: I tried to do the same with equations of similar form and order and got the same error. Since I am getting the same error which means equations does not matter I am doing something fundamentally wrong. I am posting those equation so that you don't have to deal with complicated equations above

aa = x[s] Cos[y'[s] z[s]] + t''[s];
bb = Sin[x'[s]] Cos[y[s]] + t[s] + z''[s];
cc = x[s]^2 + Sin[z'[s]] Exp[t[s]] + y''[s];
dd = z'[s] + x'[s] y[s] + x''[s];


NDSolve[{aa == 0, bb == 0, cc == 0, dd == 0, x[0] == 1, y[0] == 1, 
z[0] == 0, t[0] == 0, x'[0] == 1, y'[0] == 1, z'[0] == 0, 
t'[0] == 0}, x, y, z, t, {s, 0, 1}]
$\endgroup$
2
  • $\begingroup$ try NDSolve[{aa == 0, bb == 0, cc == 0, dd == 0, x[0] == 1, y[0] == 1, z[0] == 0, t[0] == 0, x'[0] == 1, y'[0] == 1, z'[0] == 0, t'[0] == 0}, {x, y, z, t}, {s, 0, 1}]? $\endgroup$
    – kglr
    Commented Jun 25, 2018 at 0:55
  • $\begingroup$ Yeah thanks. Noticed it just 2 minutes ago. (>.<) $\endgroup$ Commented Jun 25, 2018 at 1:00

1 Answer 1

1
$\begingroup$

For those equations which were already there and for also ones added in the post script, the mistake is in the syntax.

posted code

aa = x[s] Cos[y'[s] z[s]] + t''[s];
bb = Sin[x'[s]] Cos[y[s]] + t[s] + z''[s];
cc = x[s]^2 + Sin[z'[s]] Exp[t[s]] + y''[s];
dd = z'[s] + x'[s] y[s] + x''[s];


NDSolve[{aa == 0, bb == 0, cc == 0, dd == 0, x[0] == 1, y[0] == 1, 
z[0] == 0, t[0] == 0, x'[0] == 1, y'[0] == 1, z'[0] == 0, 
t'[0] == 0}, x, y, z, t, {s, 0, 1}]

corrected code ( only posting the NDSolve part)

NDSolve[{aa == 0, bb == 0, cc == 0, dd == 0, x[0] == 1, y[0] == 1, 
z[0] == 0, t[0] == 0, x'[0] == 1, y'[0] == 1, z'[0] == 0, 
t'[0] == 0}, {x, y, z, t}, {s, 0, 1}]

correction is $$x,y,z,t \rightarrow \{x,y,z,t \}$$

Wasted my 8 effing hours thinking about what's wrong and it turned out to be such syntax problem. (>.<)

$\endgroup$
2
  • $\begingroup$ Was the original question resolved with the fixing of the syntax error? $\endgroup$
    – JimB
    Commented Jun 25, 2018 at 1:34
  • $\begingroup$ Yes it did. Only you need to add initial conditions for the $\theta[s]$ coordinate in the NDSolve command. It's missing from there. $\endgroup$ Commented Jun 25, 2018 at 1:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.