0
$\begingroup$

Below a sample of some first-order differential equations I try to solve. Although there are no non-numerical values involved in the equations, Mathematica systematically spits out "Encountered non-numerical value at $\tau$ == 0".

And I also get the error: "Cannot solve to find an explicit formula for the derivatives. NDSolve
will try solving the system as differential-algebraic equations"... What does that mean exactly and how can I remedy this?

Might the problem lie somewhere else?

Thanks in advance for your help !

eqs = {0 == (1.38 D[r[5/6, 0][\[Tau]], \[Tau]] == -10.18 + 
   9.61 r[5/6, 0][\[Tau]] - 3.1 r[5/6, \[Pi]/4][\[Tau]]), 
  0 == (2.95 (D[r[5/6, \[Pi]/4][\[Tau]], \[Tau]]) == -21.7 + 
   13.8 r[5/6, \[Pi]/4][\[Tau]] + 
   1.66 (r[5/6, 0][\[Tau]] - 1. r[5/6, \[Pi]/2][\[Tau]])^2 - 
   1.67 (4.64 .3 r[5/6, \[Pi]/4][\[Tau]]) (r[5/6, 0][\[Tau]] - 
       1. r[5/6, \[Pi]/2][\[Tau]])^2 - 
   3.33 (r[5/6, 0][\[Tau]] - 2 r[5/6, \[Pi]/4][\[Tau]] + 
      r[5/6, \[Pi]/2][\[Tau]])), 
  0 == (4.53 (D[r[5/6, \[Pi]/2][\[Tau]], \[Tau]]) == -33.2 - 
   5.10 (2 r[5/6, \[Pi]/4][\[Tau]] - 2 r[5/6, \[Pi]/2][\[Tau]]) + 
   21.14 r[5/6, \[Pi]/2][\[Tau]])};

Unknowns = {r[5/6, 0], r[5/6, \[Pi]/4], r[5/6, \[Pi]/2]};
Unknowns\[Tau] = Unknowns /. r[a_, b_] :> r[a, b][\[Tau]];

Init = Join[Map[(0 == #) &, Unknowns\[Tau] /. \[Tau] -> 0], 
Map[(0 == #) &, D[Unknowns\[Tau], \[Tau]] /. \[Tau] -> 0]];

sols = NDSolve[Flatten[{eqs, Init}], Unknowns, {\[Tau], 1, 3}][[1]];

---------- Edit--------

So the context is that I am trying to solve some differential equation for a function $r(x,y,t)$ that I have discretised on a grid along the x-y direction leaving the time dependence continuous. So I end up with a set of differential equations for t with unknowns the point in my grid. The code above is for a sample of points $r(a,b)$ in this grid (and the corresponding equations.)

$\left\{0=\left(1.38 r\left(\frac{5}{6},0\right)'\tau =9.61 r\left(\frac{5}{6},0\right)\tau -3.1 r\left(\frac{5}{6},\frac{\pi }{4}\right)\tau -10.18\right),0=\left(2.95r\left(\frac{5}{6},\frac{\pi }{4}\right)'\tau =-2.32464r\left(\frac{5}{6},\frac{\pi }{4}\right)\tau \left(r\left(\frac{5}{6},0\right)\tau -1.r\left(\frac{5}{6},\frac{\pi }{2}\right)\tau \right)^2+1.66\left(r\left(\frac{5}{6},0\right)\tau -1.r\left(\frac{5}{6},\frac{\pi }{2}\right)\tau \right)^2+13.8r\left(\frac{5}{6},\frac{\pi }{4}\right)\tau -3.33\left(r\left(\frac{5}{6},0\right)\tau -2r\left(\frac{5}{6},\frac{\pi }{4}\right)\tau +r\left(\frac{5}{6},\frac{\pi }{2}\right)\tau \right)-21.7\right),0=\left(4.53r\left(\frac{5}{6},\frac{\pi }{2}\right)'\tau =-5.1\left(2r\left(\frac{5}{6},\frac{\pi }{4}\right)\tau -2r\left(\frac{5}{6},\frac{\pi }{2}\right)\tau \right)+21.14r\left(\frac{5}{6},\frac{\pi }{2}\right)\tau -33.2\right)\right\}$

$\endgroup$
5
  • $\begingroup$ Can you write out the equations you're trying to solve, with their initial conditions? It's not clear from the code what you're actually trying to do, which we'll need to know in order to figure out how to fix things. This Stack accepts MathJaX, so if you know LaTeX, just edit your question to include LaTeX code. $\endgroup$ Jun 23 at 19:10
  • $\begingroup$ @MichaelSeifert Thanks for taking already a look at my question! I added some context and the equations in tex form $\endgroup$ Jun 23 at 19:39
  • $\begingroup$ Setting all the differential equations equal to zero makes them into algebraic equations for an equilibrium. Is that what you intend? If so, then use Solve or NSolve or FindRoot. $\endgroup$
    – Chris K
    Jun 23 at 19:51
  • $\begingroup$ @ChrisK I don't think I can do that, since I still have a set of genuine differential equations with respect to $\tau$? $\endgroup$ Jun 23 at 19:59
  • $\begingroup$ @Nomdeplume Not after you set time derivatives (rate of change) equal to zero! $\endgroup$
    – Chris K
    Jun 23 at 20:34
0
$\begingroup$

Your code is a bit hard to parse and the math seems wrong. You have a system of 3 first order diff-eqs but 6 initial conditions (all variables and their derivatives are 0 at $t=0$). That's overconstrained, and if the variables and their derivatives are all 0, then the solution is trivial. They all stay 0 forever.

What's up with the 0==(a==b) formatting of the equations? If that's really what you mean, then you again just get the trivial solution $r(5/6,0)=r(5/6,\pi/4)=r(5/6,\pi/2)=0$ for all $\tau$.

Let's remove the initial condition on the derivatives and the 0== terms in the equations. Let's also rename $\tau$ to $t$ since it's ugly to have \[Tau]'s floating around here. And for conciseness let's also call $r(5/6,0)=r1, \ r(5/6,\pi/4)=r2, \ r(5/6,\pi/2)=r3$. Then we get

eqs = {1.38 r1'[t] == -10.18 + 9.61 r1[t] - 3.1 r2[t], 
  2.95 r2'[t] == -21.7 + 13.8 r2[t] + 1.66 (r1[t] - 1. r3[t])^2 - 2.32464 r2[t] (r1[t] - 1. r3[t])^2 - 3.33 (r1[t] - 2 r2[t] + r3[t]), 
  4.53 r3'[t] == -33.2 - 5.1 (2 r2[t] - 2 r3[t]) + 21.14 r3[t]} 
vars[t_] = {r1[t], r2[t], r3[t]};
init = Thread[vars[0] == 0];
sols = NDSolve[Flatten[{eqs, init}], vars[t], {t, 1, 3}][[1]]

This only goes to about $t=2.35$ where the solution appears to run into divergence issues. You can see this from a plot of the solution

Plot[Evaluate[{r1[t], r2[t], r3[t]} /. sols], {t, 1, 2.35}, PlotRange -> All]

enter image description here

Hope that helps!

$\endgroup$
0
$\begingroup$

Try this:

eqs = {(1.38 D[r[5/6, 0][\[Tau]], \[Tau]] == -10.18 + 
  9.61 r[5/6, 0][\[Tau]] - 
  3.1 r[5/6, \[Pi]/4][\[Tau]]), (2.95 (D[
    r[5/6, \[Pi]/4][\[Tau]], \[Tau]]) == -21.7 + 
  13.8 r[5/6, \[Pi]/4][\[Tau]] + 
  1.66 (r[5/6, 0][\[Tau]] - 1. r[5/6, \[Pi]/2][\[Tau]])^2 - 
  1.67 (4.64 .3 r[5/6, \[Pi]/4][\[Tau]]) (r[5/6, 0][\[Tau]] - 
      1. r[5/6, \[Pi]/2][\[Tau]])^2 - 
  3.33 (r[5/6, 0][\[Tau]] - 2 r[5/6, \[Pi]/4][\[Tau]] + 
     r[5/6, \[Pi]/2][\[Tau]])), (4.53 (D[
    r[5/6, \[Pi]/2][\[Tau]], \[Tau]]) == -33.2 - 
  5.10 (2 r[5/6, \[Pi]/4][\[Tau]] - 2 r[5/6, \[Pi]/2][\[Tau]]) + 
  21.14 r[5/6, \[Pi]/2][\[Tau]])};

Unknowns = {r[5/6, 0], r[5/6, \[Pi]/4], r[5/6, \[Pi]/2]};
Unknowns\[Tau] = Unknowns /. r[a_, b_] :> r[a, b][\[Tau]];
Init = Map[(0 == #) &, Unknowns\[Tau] /. \[Tau] -> 0]

sols = NDSolve[Flatten[{eqs, Init}], Unknowns, {\[Tau], 1, 3}][[1]];

Now the integration proceeds until $\tau\approx 2.28$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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