0
$\begingroup$

How can I remove the error in the code below? I don't know the reason for getting this error.

r0 = L;
Nu = 50;
l = 4;
phi = Pi L^2/(l r0 Nu Sin[t]);
X1 = r0 Sin[phi/2];
X0 = -r0 Sin[phi/2];
Y0 = r0 Cos[phi/2];
Y1 = Y0;
X = (Tan[phi/2 + t] X1 + Tan[phi/2] X0 + Y1 - Y0) (Tan[phi/2 + t] + Tan[phi/2])^(-1);
NDSolve[X0 + l Cos[phi/2 - t]/2 - X == 0, t[L], {L, 30, 70}]

The function t appears with no arguments. NDSolve

Edit

After the helpful comment:

r0 = L;
Nu = 50;
l = 4;
phi = Pi L^2/(l r0 Nu Sin[t[L]]);
X1 = r0 Sin[phi/2];
X0 = -r0 Sin[phi/2];
Y0 = r0 Cos[phi/2];
Y1 = Y0;
X = 
  (Tan[phi/2 + t[L]] X1 + Tan[phi/2] X0 + Y1 - Y0) 
    (Tan[phi/2 + t[L]] + Tan[phi/2])^(-1);
NDSolve[X0 + l Cos[phi/2 - t[L]]/2 - X == 0, t[L], {L, 30, 70}]

But now, the error is:

No derivatives of dependent variables were found in the equations. NDSolve is designed to solve differential or differential algebraic equations. Use NSolve or FindRoot to numerically solve algebraic equations.

I want to find solutions of $t$ as a function of $L$. But I don't know what Mathematica function to use.

$\endgroup$

closed as unclear what you're asking by Daniel Lichtblau, Sektor, bbgodfrey, MarcoB, corey979 Jan 14 '18 at 6:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Replace both instances of Tan[phi/2 + t] with Tan[phi/2 + t[L]] and Cos[phi/2 - t] with Cos[phi/2 - t[L]] and Sin[t] with Sin[t[L]]. However, you will still have errors. $\endgroup$ – Bob Hanlon Jan 13 '18 at 20:48
  • $\begingroup$ What is it that you really want to do? NDSolve is for solving differential equations, but yours is an algebraic one. Maybe you could describe with words and math what's the actual problem you're trying to solve. $\endgroup$ – corey979 Jan 13 '18 at 20:51
  • $\begingroup$ I don't see what is unclear about "I want to find solutions of $t$ as a function of $L$." (I can see that this was added after the initial post, but it was also added ten hours before being closed.) $\endgroup$ – Michael E2 Jan 14 '18 at 13:18
  • $\begingroup$ To @corey979. Like Michael E2, I don't see, that this question should be unclear. The answer of Michael E2 and my alternative answer as comment show, it is solveable. Please release the hold. $\endgroup$ – Akku14 Jan 17 '18 at 15:43
  • $\begingroup$ To @Daniel Lichtblau. Like Michael E2, I don't see, that this question should be unclear. The answer of Michael E2 and my alternative answer as comment show, it is solveable. Please release the hold. $\endgroup$ – Akku14 Jan 17 '18 at 15:44
2
$\begingroup$

I think there are 22 different solutions, because there are lots of solutions for t[30] at L = 30 modulo 2 Pi (there may be more near ±Pi, which the discretization missed, though; decrease MaxStepSize in the code for rts and you'll see):

eqn = X0 + l Cos[phi/2 - t[L]]/2 - X == 0;

Block[{L = 30},
  rts = Sort@
    Flatten@Last@Reap@NDSolve[{t'[s] == 1, t[1/100] == 1/100,
         WhenEvent[
          eqn && Abs[eqn /. Equal -> Subtract] < 10^16 /. 
            t[L] -> t[s] // Evaluate, Sow[t[s]]]},
        {}, {s, -Pi + 2^-25, Pi - 2^-25}, MaxStepSize -> 0.01, 
        WorkingPrecision -> 3 $MachinePrecision]
  ];

sol[n_Integer] /; 1 <= n <= Length@rts := (* pretty good solution *)
  NDSolve[{Equal @@@ First@Solve[D[eqn, L], t'[L]], t[30] == rts[[n]]},
   t, {L, 30, 70}];

sol[n_Integer] /; 1 <= n <= Length@rts := (* a more accurate solution *)
  NDSolve[{Equal @@@ First@Solve[D[eqn, L], t'[L]], t[30] == rts[[n]]},
   t, {L, 30, 70}, 
   Method -> {"Projection", "Invariants" -> {eqn /. Equal -> Subtract}}, 
   InterpolationOrder -> All];

Plot[t[L] /. Join @@ Table[sol[n], {n, 1, Length@rts}] // 
  Evaluate, {L, 30, 70}]

Mathematica graphics

Yep, lots of potential initial conditions (infinitely many, I believe):

Block[{L = 30, neqn},
   neqn = 
    Cos[1/400 L \[Pi] Csc[t[L]] + t[L]] Cos[
          1/400 L \[Pi] Csc[t[L]]] (eqn /. Equal -> Subtract) /. 
        t[L] -> t // Expand // Together // Numerator;
   rts = t /. Join[
      NSolve[{neqn, 1/1000 < t < Pi - 1/1000}, t, 
       WorkingPrecision -> $MachinePrecision],
      NSolve[{neqn, -Pi + 1/1000 < t < -1/1000}, t, 
       WorkingPrecision -> $MachinePrecision]
      ]]; // AbsoluteTiming
(*  {2.76056, Null}  *)

Length@rts
(*  898  *)
$\endgroup$
  • $\begingroup$ Appendix to the fine answer of @Michael E2. The same with less code: equ[L_] = X0 + l Cos[phi/2 - t[L]]/2 - X // Simplify; Solve for starting values. Exclude areas with infinit many solutions. sol1 = t[30] /. Solve[equ[30] == 0 && (1/100 < t[30] < 310/100 || -310/100 < t[30] < -1/100), t[30]]; Differentate equation. dequ[L] = D[equ[L], L] // Simplify; NDSolve with found starting values. ndsol = NDSolve[{dequ[L] == 0, t[30] == #}, t, {L, 30, 70}] & /@ sol1; Plot gives the same result Plot[Evaluate[t[L] /. ndsol], {L, 30, 70}, PlotRange -> All] $\endgroup$ – Akku14 Jan 14 '18 at 8:15

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