Runtime too long for NDSolveValue, FindRoot breaks down at sharp turnsFinding and plotting roots with parameterStuck in solving two variables from two expressionsSolution of Coupled second-order ODEs and plot the diagramAvoiding divide by zero to simplify an expression enough to solveexact solution to this differential equation in mathematicaHow to use DEigensystem with periodic boundary conditions on the derivative?why Mathematica gives zero as eigenvalue for $y''+lambda y=0$ for these boundary conditions?how to obtain solution for $u_t+u=u_xx$Numerically evaluating and plotting functions involving complete Elliptic integralsSolving for three parameters from a matrix equation and storing them in separate variables

"Best practices" for formulating MIPs

Disk usage confusion: 10G missing on Linux home partition on SSD

What do you call the fear of forgetting (specifically something one cherishes a lot)?

My players like to search everything. What do they find?

Is it OK to say "The situation is pregnant with a crisis"?

How to extract coefficients of a generating function like this one, using a computer?

Are the Gray and Death Slaad's Bite and Claw attacks magical?

Could citing a database like libgen get one into trouble?

Can you help me, to widen the page. Thank you

How to model a Coral or Sponge Structure?

Old story where computer expert digitally animates The Lord of the Rings

2019 2-letters 33-length list

Does the Grothendieck group of finitely generated modules form a commutative ring where the multiplication structure is induced from tensor product?

Can you run PoE Cat6 alongside standard Cat6 cables?

What happened to the Apollo 1 rocket?

Why is quantum gravity non-renormalizable?

Existence of infinite set of positive integers s.t sum of reciprocals is rational and set of primes dividing an element is infinite

Is my background sufficient to start Quantum Computing

Square wave to sawtooth wave using two BJT

What's the idiomatic (or best) way to trim surrounding whitespace from a string?

Finding an optimal set without forbidden subsets

Is it normal for professors to hold their graduate students "hostage?"

How can solar sailed ships be protected from space debris?

What is the meaning of "it" in "as luck would have it"?



Runtime too long for NDSolveValue, FindRoot breaks down at sharp turns


Finding and plotting roots with parameterStuck in solving two variables from two expressionsSolution of Coupled second-order ODEs and plot the diagramAvoiding divide by zero to simplify an expression enough to solveexact solution to this differential equation in mathematicaHow to use DEigensystem with periodic boundary conditions on the derivative?why Mathematica gives zero as eigenvalue for $y''+lambda y=0$ for these boundary conditions?how to obtain solution for $u_t+u=u_xx$Numerically evaluating and plotting functions involving complete Elliptic integralsSolving for three parameters from a matrix equation and storing them in separate variables













2












$begingroup$


I have two equations:



$$
frac23thinspaceleft(fracvarepsilonDeltaright)^frac32=sum_i=1,2 sigma_ilambda_ileft(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+sum_i=1,2 sigma_i frac(1+lambda_i^2)^1/4 2 ( lambda_i+sqrt1+lambda_i^2 ) F(fracpi2, k_i )
$$



and



$$
sqrtDeltasum_i=1,2biggl[-left(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+fracFleft(fracpi2,k_iright)2left(1+lambda_i^2right)^frac14left( lambda_i +
frac1sqrt1+lambda_i^2+lambda_i right)biggr]=sum_i=1,2biggl[-left(1+widetildelambda_i^2right)^frac14Eleft(fracpi2,widetildek_iright)+fracFleft(fracpi2,widetildek_iright)2left(1+widetildelambda_i^2right)^frac14left(widetildelambda_i+frac1sqrt1+widetildelambda_i^2+widetildelambda_i right)biggr]
$$



where $sigma_1=1$, $sigma_2=-1$,
$k_i^2=fracsqrt1+lambda_i^2+lambda_i2sqrtleft(1+lambda_i^2right)$ for $i=1,2$ with $lambda_1equiv fracmu-Delta_0Delta$, $lambda_2equiv frac-Delta_0-muDelta $, $widetildek_i^2=fracsqrt1+widetildelambda_i^2+widetildelambda_i2sqrtleft(1+widetildelambda_i^2right)$ for $i=1,2$ with $widetildelambda_1equiv mu$, $widetildelambda_2equiv -mu $. $F(fracpi2,k)$ and $E(fracpi2,k)$ are the complete elliptic integral of the first and the second kind respectively which in Mathematica are EllipticK[] and EllipticE[]. In the code below $mu$, $Delta_0$, $Delta$, $varepsilon$ are represented by u, o, d, e.



By first converting those two equations in the form of differential equations and then using NDSolveValue to obtain plots of $Delta$ and $mu$ as a function of $Delta_0$ at $varepsilon=0.001$, I encounter the error:



lambda1[u_, o_, d_] := (u - o)/d;
lambda2[u_, o_, d_] := (-u - o)/d;
k1sq[u_, o_, d_] := (Sqrt[1 + ((lambda1[u, o, d])^2)] + lambda1[u, o, d])/(2*(Sqrt[1 + ((lambda1[u, o, d])^2)]));
k2sq[u_, o_, d_] := (Sqrt[1 + ((lambda2[u, o, d])^2)] + lambda2[u, o, d])/(2*(Sqrt[1 + ((lambda2[u, o, d])^2)]));
a1[u_, o_, d_] := (1 + (lambda1[u, o, d])^2)^(1/4);
a2[u_, o_, d_] := (1 + (lambda2[u, o, d])^2)^(1/4);
b1[u_, o_, d_] := Sqrt[1 + (lambda1[u, o, d])^2] + lambda1[u, o, d];
b2[u_, o_, d_] := Sqrt[1 + (lambda2[u, o, d])^2] + lambda2[u, o, d];

equat1[u_, o_, d_, e_] =
(2/3)*(((e)/d)^(3/2)) == ((lambda1[u, o, d]*a1[u, o, d]*EllipticE[k1sq[u, o, d]])
-((lambda1[u, o, d]*EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*b1[u, o, d]))+
((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d])) -
(lambda2[u, o, d]*a2[u, o, d]* EllipticE[k2sq[u, o, d]])
+ ((lambda2[u, o, d]*EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*b2[u, o, d]))-
((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d])));

equat2[u_, o_, d_] =
Sqrt[d]*(((lambda1[u, o, d])*
EllipticK[k1sq[u, o, d]]/(2*a1[u, o, d])) - (a1[u, o, d]*
EllipticE[
k1sq[u, o, d]]) + ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*
b1[u, o, d])) + ((lambda2[u, o, d])*
EllipticK[k2sq[u, o, d]]/(2*a2[u, o, d])) - (a2[u, o, d]*
EllipticE[
k2sq[u, o, d]]) + ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*
b2[u, o, d]))) == ((lambda1[u, 0, 1])*
EllipticK[k1sq[u, 0, 1]]/(2*a1[u, 0, 1])) - (a1[u, 0, 1]*
EllipticE[
k1sq[u, 0, 1]]) + ((EllipticK[k1sq[u, 0, 1]])/(2*a1[u, 0, 1]*
b1[u, 0, 1])) + ((lambda2[u, 0, 1])*
EllipticK[k2sq[u, 0, 1]]/(2*a2[u, 0, 1])) - (a2[u, 0, 1]*
EllipticE[
k2sq[u, 0, 1]]) + ((EllipticK[k2sq[u, 0, 1]])/(2*a2[u, 0, 1]*
b2[u, 0, 1]));

dk, uk = d, u /. FindRoot[equat2[u, o, d], equat1[u, o, d, .001] /. o -> 0, d, .5, u, .1];

dsolk, usolk =
NDSolveValue[D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
D[equat1[u, o, d, .001] /. d -> d[o], u -> u[o], o],
u[0] == uk, d[0] == dk, d, u, o, 0, 1,
Method -> "EquationSimplification" -> "Residual"];

Plot[dsolk[t], usolk[t], t, 0, 1, PlotRange -> -.1, 1.1, Frame -> True]




NDSolveValue::mxst: Maximum number of 100000 steps reached at the point o == 0.6097033678408679`.




enter image description here



I expect the blue curve ($Delta$) to continue levelling off and the yellow curve ($mu$) to continue increasing. Increasing MaxSteps->Infinity probably helps but the run-time took too long to evaluate and I gave up. Eventually, I will be obtaining these plots for different values of $varepsilon$ and so increasing the run-time by increasing MaxSteps does not seem to be the way to go.



Using FindRoot directly gives somwhat the plot I want and the run-time is relatively shorter, but fails around the sharp turn at $Delta_0=0.29$ and throws the error:



Table[Values@
FindRoot[equat2[u, o, d],
equat1[u, o, d, .001], d, .5, u, .1], o, 0, 1, .001];
ListPlot[Transpose@%, DataRange -> 0, 1, Joined -> True,
AxesLabel -> o, "d, u",
LabelStyle -> Directive[Bold, Black, Medium], ImageSize -> Large]



FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.




enter image description here










share|improve this question











$endgroup$
















    2












    $begingroup$


    I have two equations:



    $$
    frac23thinspaceleft(fracvarepsilonDeltaright)^frac32=sum_i=1,2 sigma_ilambda_ileft(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+sum_i=1,2 sigma_i frac(1+lambda_i^2)^1/4 2 ( lambda_i+sqrt1+lambda_i^2 ) F(fracpi2, k_i )
    $$



    and



    $$
    sqrtDeltasum_i=1,2biggl[-left(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+fracFleft(fracpi2,k_iright)2left(1+lambda_i^2right)^frac14left( lambda_i +
    frac1sqrt1+lambda_i^2+lambda_i right)biggr]=sum_i=1,2biggl[-left(1+widetildelambda_i^2right)^frac14Eleft(fracpi2,widetildek_iright)+fracFleft(fracpi2,widetildek_iright)2left(1+widetildelambda_i^2right)^frac14left(widetildelambda_i+frac1sqrt1+widetildelambda_i^2+widetildelambda_i right)biggr]
    $$



    where $sigma_1=1$, $sigma_2=-1$,
    $k_i^2=fracsqrt1+lambda_i^2+lambda_i2sqrtleft(1+lambda_i^2right)$ for $i=1,2$ with $lambda_1equiv fracmu-Delta_0Delta$, $lambda_2equiv frac-Delta_0-muDelta $, $widetildek_i^2=fracsqrt1+widetildelambda_i^2+widetildelambda_i2sqrtleft(1+widetildelambda_i^2right)$ for $i=1,2$ with $widetildelambda_1equiv mu$, $widetildelambda_2equiv -mu $. $F(fracpi2,k)$ and $E(fracpi2,k)$ are the complete elliptic integral of the first and the second kind respectively which in Mathematica are EllipticK[] and EllipticE[]. In the code below $mu$, $Delta_0$, $Delta$, $varepsilon$ are represented by u, o, d, e.



    By first converting those two equations in the form of differential equations and then using NDSolveValue to obtain plots of $Delta$ and $mu$ as a function of $Delta_0$ at $varepsilon=0.001$, I encounter the error:



    lambda1[u_, o_, d_] := (u - o)/d;
    lambda2[u_, o_, d_] := (-u - o)/d;
    k1sq[u_, o_, d_] := (Sqrt[1 + ((lambda1[u, o, d])^2)] + lambda1[u, o, d])/(2*(Sqrt[1 + ((lambda1[u, o, d])^2)]));
    k2sq[u_, o_, d_] := (Sqrt[1 + ((lambda2[u, o, d])^2)] + lambda2[u, o, d])/(2*(Sqrt[1 + ((lambda2[u, o, d])^2)]));
    a1[u_, o_, d_] := (1 + (lambda1[u, o, d])^2)^(1/4);
    a2[u_, o_, d_] := (1 + (lambda2[u, o, d])^2)^(1/4);
    b1[u_, o_, d_] := Sqrt[1 + (lambda1[u, o, d])^2] + lambda1[u, o, d];
    b2[u_, o_, d_] := Sqrt[1 + (lambda2[u, o, d])^2] + lambda2[u, o, d];

    equat1[u_, o_, d_, e_] =
    (2/3)*(((e)/d)^(3/2)) == ((lambda1[u, o, d]*a1[u, o, d]*EllipticE[k1sq[u, o, d]])
    -((lambda1[u, o, d]*EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*b1[u, o, d]))+
    ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d])) -
    (lambda2[u, o, d]*a2[u, o, d]* EllipticE[k2sq[u, o, d]])
    + ((lambda2[u, o, d]*EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*b2[u, o, d]))-
    ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d])));

    equat2[u_, o_, d_] =
    Sqrt[d]*(((lambda1[u, o, d])*
    EllipticK[k1sq[u, o, d]]/(2*a1[u, o, d])) - (a1[u, o, d]*
    EllipticE[
    k1sq[u, o, d]]) + ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*
    b1[u, o, d])) + ((lambda2[u, o, d])*
    EllipticK[k2sq[u, o, d]]/(2*a2[u, o, d])) - (a2[u, o, d]*
    EllipticE[
    k2sq[u, o, d]]) + ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*
    b2[u, o, d]))) == ((lambda1[u, 0, 1])*
    EllipticK[k1sq[u, 0, 1]]/(2*a1[u, 0, 1])) - (a1[u, 0, 1]*
    EllipticE[
    k1sq[u, 0, 1]]) + ((EllipticK[k1sq[u, 0, 1]])/(2*a1[u, 0, 1]*
    b1[u, 0, 1])) + ((lambda2[u, 0, 1])*
    EllipticK[k2sq[u, 0, 1]]/(2*a2[u, 0, 1])) - (a2[u, 0, 1]*
    EllipticE[
    k2sq[u, 0, 1]]) + ((EllipticK[k2sq[u, 0, 1]])/(2*a2[u, 0, 1]*
    b2[u, 0, 1]));

    dk, uk = d, u /. FindRoot[equat2[u, o, d], equat1[u, o, d, .001] /. o -> 0, d, .5, u, .1];

    dsolk, usolk =
    NDSolveValue[D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
    D[equat1[u, o, d, .001] /. d -> d[o], u -> u[o], o],
    u[0] == uk, d[0] == dk, d, u, o, 0, 1,
    Method -> "EquationSimplification" -> "Residual"];

    Plot[dsolk[t], usolk[t], t, 0, 1, PlotRange -> -.1, 1.1, Frame -> True]




    NDSolveValue::mxst: Maximum number of 100000 steps reached at the point o == 0.6097033678408679`.




    enter image description here



    I expect the blue curve ($Delta$) to continue levelling off and the yellow curve ($mu$) to continue increasing. Increasing MaxSteps->Infinity probably helps but the run-time took too long to evaluate and I gave up. Eventually, I will be obtaining these plots for different values of $varepsilon$ and so increasing the run-time by increasing MaxSteps does not seem to be the way to go.



    Using FindRoot directly gives somwhat the plot I want and the run-time is relatively shorter, but fails around the sharp turn at $Delta_0=0.29$ and throws the error:



    Table[Values@
    FindRoot[equat2[u, o, d],
    equat1[u, o, d, .001], d, .5, u, .1], o, 0, 1, .001];
    ListPlot[Transpose@%, DataRange -> 0, 1, Joined -> True,
    AxesLabel -> o, "d, u",
    LabelStyle -> Directive[Bold, Black, Medium], ImageSize -> Large]



    FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.




    enter image description here










    share|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      I have two equations:



      $$
      frac23thinspaceleft(fracvarepsilonDeltaright)^frac32=sum_i=1,2 sigma_ilambda_ileft(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+sum_i=1,2 sigma_i frac(1+lambda_i^2)^1/4 2 ( lambda_i+sqrt1+lambda_i^2 ) F(fracpi2, k_i )
      $$



      and



      $$
      sqrtDeltasum_i=1,2biggl[-left(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+fracFleft(fracpi2,k_iright)2left(1+lambda_i^2right)^frac14left( lambda_i +
      frac1sqrt1+lambda_i^2+lambda_i right)biggr]=sum_i=1,2biggl[-left(1+widetildelambda_i^2right)^frac14Eleft(fracpi2,widetildek_iright)+fracFleft(fracpi2,widetildek_iright)2left(1+widetildelambda_i^2right)^frac14left(widetildelambda_i+frac1sqrt1+widetildelambda_i^2+widetildelambda_i right)biggr]
      $$



      where $sigma_1=1$, $sigma_2=-1$,
      $k_i^2=fracsqrt1+lambda_i^2+lambda_i2sqrtleft(1+lambda_i^2right)$ for $i=1,2$ with $lambda_1equiv fracmu-Delta_0Delta$, $lambda_2equiv frac-Delta_0-muDelta $, $widetildek_i^2=fracsqrt1+widetildelambda_i^2+widetildelambda_i2sqrtleft(1+widetildelambda_i^2right)$ for $i=1,2$ with $widetildelambda_1equiv mu$, $widetildelambda_2equiv -mu $. $F(fracpi2,k)$ and $E(fracpi2,k)$ are the complete elliptic integral of the first and the second kind respectively which in Mathematica are EllipticK[] and EllipticE[]. In the code below $mu$, $Delta_0$, $Delta$, $varepsilon$ are represented by u, o, d, e.



      By first converting those two equations in the form of differential equations and then using NDSolveValue to obtain plots of $Delta$ and $mu$ as a function of $Delta_0$ at $varepsilon=0.001$, I encounter the error:



      lambda1[u_, o_, d_] := (u - o)/d;
      lambda2[u_, o_, d_] := (-u - o)/d;
      k1sq[u_, o_, d_] := (Sqrt[1 + ((lambda1[u, o, d])^2)] + lambda1[u, o, d])/(2*(Sqrt[1 + ((lambda1[u, o, d])^2)]));
      k2sq[u_, o_, d_] := (Sqrt[1 + ((lambda2[u, o, d])^2)] + lambda2[u, o, d])/(2*(Sqrt[1 + ((lambda2[u, o, d])^2)]));
      a1[u_, o_, d_] := (1 + (lambda1[u, o, d])^2)^(1/4);
      a2[u_, o_, d_] := (1 + (lambda2[u, o, d])^2)^(1/4);
      b1[u_, o_, d_] := Sqrt[1 + (lambda1[u, o, d])^2] + lambda1[u, o, d];
      b2[u_, o_, d_] := Sqrt[1 + (lambda2[u, o, d])^2] + lambda2[u, o, d];

      equat1[u_, o_, d_, e_] =
      (2/3)*(((e)/d)^(3/2)) == ((lambda1[u, o, d]*a1[u, o, d]*EllipticE[k1sq[u, o, d]])
      -((lambda1[u, o, d]*EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*b1[u, o, d]))+
      ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d])) -
      (lambda2[u, o, d]*a2[u, o, d]* EllipticE[k2sq[u, o, d]])
      + ((lambda2[u, o, d]*EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*b2[u, o, d]))-
      ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d])));

      equat2[u_, o_, d_] =
      Sqrt[d]*(((lambda1[u, o, d])*
      EllipticK[k1sq[u, o, d]]/(2*a1[u, o, d])) - (a1[u, o, d]*
      EllipticE[
      k1sq[u, o, d]]) + ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*
      b1[u, o, d])) + ((lambda2[u, o, d])*
      EllipticK[k2sq[u, o, d]]/(2*a2[u, o, d])) - (a2[u, o, d]*
      EllipticE[
      k2sq[u, o, d]]) + ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*
      b2[u, o, d]))) == ((lambda1[u, 0, 1])*
      EllipticK[k1sq[u, 0, 1]]/(2*a1[u, 0, 1])) - (a1[u, 0, 1]*
      EllipticE[
      k1sq[u, 0, 1]]) + ((EllipticK[k1sq[u, 0, 1]])/(2*a1[u, 0, 1]*
      b1[u, 0, 1])) + ((lambda2[u, 0, 1])*
      EllipticK[k2sq[u, 0, 1]]/(2*a2[u, 0, 1])) - (a2[u, 0, 1]*
      EllipticE[
      k2sq[u, 0, 1]]) + ((EllipticK[k2sq[u, 0, 1]])/(2*a2[u, 0, 1]*
      b2[u, 0, 1]));

      dk, uk = d, u /. FindRoot[equat2[u, o, d], equat1[u, o, d, .001] /. o -> 0, d, .5, u, .1];

      dsolk, usolk =
      NDSolveValue[D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
      D[equat1[u, o, d, .001] /. d -> d[o], u -> u[o], o],
      u[0] == uk, d[0] == dk, d, u, o, 0, 1,
      Method -> "EquationSimplification" -> "Residual"];

      Plot[dsolk[t], usolk[t], t, 0, 1, PlotRange -> -.1, 1.1, Frame -> True]




      NDSolveValue::mxst: Maximum number of 100000 steps reached at the point o == 0.6097033678408679`.




      enter image description here



      I expect the blue curve ($Delta$) to continue levelling off and the yellow curve ($mu$) to continue increasing. Increasing MaxSteps->Infinity probably helps but the run-time took too long to evaluate and I gave up. Eventually, I will be obtaining these plots for different values of $varepsilon$ and so increasing the run-time by increasing MaxSteps does not seem to be the way to go.



      Using FindRoot directly gives somwhat the plot I want and the run-time is relatively shorter, but fails around the sharp turn at $Delta_0=0.29$ and throws the error:



      Table[Values@
      FindRoot[equat2[u, o, d],
      equat1[u, o, d, .001], d, .5, u, .1], o, 0, 1, .001];
      ListPlot[Transpose@%, DataRange -> 0, 1, Joined -> True,
      AxesLabel -> o, "d, u",
      LabelStyle -> Directive[Bold, Black, Medium], ImageSize -> Large]



      FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.




      enter image description here










      share|improve this question











      $endgroup$




      I have two equations:



      $$
      frac23thinspaceleft(fracvarepsilonDeltaright)^frac32=sum_i=1,2 sigma_ilambda_ileft(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+sum_i=1,2 sigma_i frac(1+lambda_i^2)^1/4 2 ( lambda_i+sqrt1+lambda_i^2 ) F(fracpi2, k_i )
      $$



      and



      $$
      sqrtDeltasum_i=1,2biggl[-left(1+lambda_i^2right)^frac14Eleft(fracpi2,k_iright)+fracFleft(fracpi2,k_iright)2left(1+lambda_i^2right)^frac14left( lambda_i +
      frac1sqrt1+lambda_i^2+lambda_i right)biggr]=sum_i=1,2biggl[-left(1+widetildelambda_i^2right)^frac14Eleft(fracpi2,widetildek_iright)+fracFleft(fracpi2,widetildek_iright)2left(1+widetildelambda_i^2right)^frac14left(widetildelambda_i+frac1sqrt1+widetildelambda_i^2+widetildelambda_i right)biggr]
      $$



      where $sigma_1=1$, $sigma_2=-1$,
      $k_i^2=fracsqrt1+lambda_i^2+lambda_i2sqrtleft(1+lambda_i^2right)$ for $i=1,2$ with $lambda_1equiv fracmu-Delta_0Delta$, $lambda_2equiv frac-Delta_0-muDelta $, $widetildek_i^2=fracsqrt1+widetildelambda_i^2+widetildelambda_i2sqrtleft(1+widetildelambda_i^2right)$ for $i=1,2$ with $widetildelambda_1equiv mu$, $widetildelambda_2equiv -mu $. $F(fracpi2,k)$ and $E(fracpi2,k)$ are the complete elliptic integral of the first and the second kind respectively which in Mathematica are EllipticK[] and EllipticE[]. In the code below $mu$, $Delta_0$, $Delta$, $varepsilon$ are represented by u, o, d, e.



      By first converting those two equations in the form of differential equations and then using NDSolveValue to obtain plots of $Delta$ and $mu$ as a function of $Delta_0$ at $varepsilon=0.001$, I encounter the error:



      lambda1[u_, o_, d_] := (u - o)/d;
      lambda2[u_, o_, d_] := (-u - o)/d;
      k1sq[u_, o_, d_] := (Sqrt[1 + ((lambda1[u, o, d])^2)] + lambda1[u, o, d])/(2*(Sqrt[1 + ((lambda1[u, o, d])^2)]));
      k2sq[u_, o_, d_] := (Sqrt[1 + ((lambda2[u, o, d])^2)] + lambda2[u, o, d])/(2*(Sqrt[1 + ((lambda2[u, o, d])^2)]));
      a1[u_, o_, d_] := (1 + (lambda1[u, o, d])^2)^(1/4);
      a2[u_, o_, d_] := (1 + (lambda2[u, o, d])^2)^(1/4);
      b1[u_, o_, d_] := Sqrt[1 + (lambda1[u, o, d])^2] + lambda1[u, o, d];
      b2[u_, o_, d_] := Sqrt[1 + (lambda2[u, o, d])^2] + lambda2[u, o, d];

      equat1[u_, o_, d_, e_] =
      (2/3)*(((e)/d)^(3/2)) == ((lambda1[u, o, d]*a1[u, o, d]*EllipticE[k1sq[u, o, d]])
      -((lambda1[u, o, d]*EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*b1[u, o, d]))+
      ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d])) -
      (lambda2[u, o, d]*a2[u, o, d]* EllipticE[k2sq[u, o, d]])
      + ((lambda2[u, o, d]*EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*b2[u, o, d]))-
      ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d])));

      equat2[u_, o_, d_] =
      Sqrt[d]*(((lambda1[u, o, d])*
      EllipticK[k1sq[u, o, d]]/(2*a1[u, o, d])) - (a1[u, o, d]*
      EllipticE[
      k1sq[u, o, d]]) + ((EllipticK[k1sq[u, o, d]])/(2*a1[u, o, d]*
      b1[u, o, d])) + ((lambda2[u, o, d])*
      EllipticK[k2sq[u, o, d]]/(2*a2[u, o, d])) - (a2[u, o, d]*
      EllipticE[
      k2sq[u, o, d]]) + ((EllipticK[k2sq[u, o, d]])/(2*a2[u, o, d]*
      b2[u, o, d]))) == ((lambda1[u, 0, 1])*
      EllipticK[k1sq[u, 0, 1]]/(2*a1[u, 0, 1])) - (a1[u, 0, 1]*
      EllipticE[
      k1sq[u, 0, 1]]) + ((EllipticK[k1sq[u, 0, 1]])/(2*a1[u, 0, 1]*
      b1[u, 0, 1])) + ((lambda2[u, 0, 1])*
      EllipticK[k2sq[u, 0, 1]]/(2*a2[u, 0, 1])) - (a2[u, 0, 1]*
      EllipticE[
      k2sq[u, 0, 1]]) + ((EllipticK[k2sq[u, 0, 1]])/(2*a2[u, 0, 1]*
      b2[u, 0, 1]));

      dk, uk = d, u /. FindRoot[equat2[u, o, d], equat1[u, o, d, .001] /. o -> 0, d, .5, u, .1];

      dsolk, usolk =
      NDSolveValue[D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
      D[equat1[u, o, d, .001] /. d -> d[o], u -> u[o], o],
      u[0] == uk, d[0] == dk, d, u, o, 0, 1,
      Method -> "EquationSimplification" -> "Residual"];

      Plot[dsolk[t], usolk[t], t, 0, 1, PlotRange -> -.1, 1.1, Frame -> True]




      NDSolveValue::mxst: Maximum number of 100000 steps reached at the point o == 0.6097033678408679`.




      enter image description here



      I expect the blue curve ($Delta$) to continue levelling off and the yellow curve ($mu$) to continue increasing. Increasing MaxSteps->Infinity probably helps but the run-time took too long to evaluate and I gave up. Eventually, I will be obtaining these plots for different values of $varepsilon$ and so increasing the run-time by increasing MaxSteps does not seem to be the way to go.



      Using FindRoot directly gives somwhat the plot I want and the run-time is relatively shorter, but fails around the sharp turn at $Delta_0=0.29$ and throws the error:



      Table[Values@
      FindRoot[equat2[u, o, d],
      equat1[u, o, d, .001], d, .5, u, .1], o, 0, 1, .001];
      ListPlot[Transpose@%, DataRange -> 0, 1, Joined -> True,
      AxesLabel -> o, "d, u",
      LabelStyle -> Directive[Bold, Black, Medium], ImageSize -> Large]



      FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.




      enter image description here







      plotting differential-equations equation-solving






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 8 hours ago







      user0000

















      asked 8 hours ago









      user0000user0000

      285 bronze badges




      285 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          I think the problem is a 0/0 term somewhere in the expression for equat2[] that arises at the time the integration begins to fail, from around 0.60 to 0.62. This causes numeric noise in computing u'[o], which leads to NDSolve[] thinking there's an error. A common factor can be eliminated for o -> 0 via Simplify. I let Simplify run for a several minutes on general o to no avail. So I resorted to Limit, which is slow. To resolve the issue, I needed higher WorkingPrecision, so I had to avoid Method -> "EquationSimplification" -> "Residual", which can only be used with the machine-precision IDA method. I also replaced the parameter e value 0.001 with 1/1000 to avoid machine precision. I timed all the time-consuming computations.



          dk, uk = d, u /. 
          FindRoot[equat2[u, o, d], equat1[u, o, d, 1/1000] /.
          o -> 0, d, .5, u, .1, WorkingPrecision -> 100];

          newODE = First@Solve[
          D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
          D[equat1[u, o, d, 1/1000] /. d -> d[o], u -> u[o], o],
          d'[o], u'[o]
          ] /. Rule -> Equal; // AbsoluteTiming
          (* 7.57532, Null *)

          ClearAll[uprime];
          uprime[o1_?NumericQ, d1_, u1_] := Block[o,
          Quiet[Check[
          newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1,
          nlim++;
          Limit[newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1],
          Power::infy, Infinity::indet],
          Power::infy, Infinity::indet]
          ];

          newODE2 = First@newODE, u'[o] == uprime[o, d[o], u[o]];

          nlim = 0;
          dsolk, usolk =
          NDSolveValue[newODE2, u[0] == uk, d[0] == dk, d, u, o, 0, 1,
          PrecisionGoal -> 8, AccuracyGoal -> 8,
          WorkingPrecision -> 50]; // AbsoluteTiming
          nlim
          (*
          99.1584, Null
          3 <-- number of times Limit[] was called
          *)

          ListLinePlot@dsolk, usolk


          enter image description here



          In sum, equat2[] is numerically ill-conditioned in places. Perhaps simplification can help, or manual analysis, although the equations are too unwieldy for a quick look-see. However, I don't have any more time to look into it or the FindRoot problem, which is likely to be related, at this point.






          share|improve this answer









          $endgroup$












          • $begingroup$
            Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
            $endgroup$
            – Michael E2
            4 hours ago













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "387"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201281%2fruntime-too-long-for-ndsolvevalue-findroot-breaks-down-at-sharp-turns%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2












          $begingroup$

          I think the problem is a 0/0 term somewhere in the expression for equat2[] that arises at the time the integration begins to fail, from around 0.60 to 0.62. This causes numeric noise in computing u'[o], which leads to NDSolve[] thinking there's an error. A common factor can be eliminated for o -> 0 via Simplify. I let Simplify run for a several minutes on general o to no avail. So I resorted to Limit, which is slow. To resolve the issue, I needed higher WorkingPrecision, so I had to avoid Method -> "EquationSimplification" -> "Residual", which can only be used with the machine-precision IDA method. I also replaced the parameter e value 0.001 with 1/1000 to avoid machine precision. I timed all the time-consuming computations.



          dk, uk = d, u /. 
          FindRoot[equat2[u, o, d], equat1[u, o, d, 1/1000] /.
          o -> 0, d, .5, u, .1, WorkingPrecision -> 100];

          newODE = First@Solve[
          D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
          D[equat1[u, o, d, 1/1000] /. d -> d[o], u -> u[o], o],
          d'[o], u'[o]
          ] /. Rule -> Equal; // AbsoluteTiming
          (* 7.57532, Null *)

          ClearAll[uprime];
          uprime[o1_?NumericQ, d1_, u1_] := Block[o,
          Quiet[Check[
          newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1,
          nlim++;
          Limit[newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1],
          Power::infy, Infinity::indet],
          Power::infy, Infinity::indet]
          ];

          newODE2 = First@newODE, u'[o] == uprime[o, d[o], u[o]];

          nlim = 0;
          dsolk, usolk =
          NDSolveValue[newODE2, u[0] == uk, d[0] == dk, d, u, o, 0, 1,
          PrecisionGoal -> 8, AccuracyGoal -> 8,
          WorkingPrecision -> 50]; // AbsoluteTiming
          nlim
          (*
          99.1584, Null
          3 <-- number of times Limit[] was called
          *)

          ListLinePlot@dsolk, usolk


          enter image description here



          In sum, equat2[] is numerically ill-conditioned in places. Perhaps simplification can help, or manual analysis, although the equations are too unwieldy for a quick look-see. However, I don't have any more time to look into it or the FindRoot problem, which is likely to be related, at this point.






          share|improve this answer









          $endgroup$












          • $begingroup$
            Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
            $endgroup$
            – Michael E2
            4 hours ago















          2












          $begingroup$

          I think the problem is a 0/0 term somewhere in the expression for equat2[] that arises at the time the integration begins to fail, from around 0.60 to 0.62. This causes numeric noise in computing u'[o], which leads to NDSolve[] thinking there's an error. A common factor can be eliminated for o -> 0 via Simplify. I let Simplify run for a several minutes on general o to no avail. So I resorted to Limit, which is slow. To resolve the issue, I needed higher WorkingPrecision, so I had to avoid Method -> "EquationSimplification" -> "Residual", which can only be used with the machine-precision IDA method. I also replaced the parameter e value 0.001 with 1/1000 to avoid machine precision. I timed all the time-consuming computations.



          dk, uk = d, u /. 
          FindRoot[equat2[u, o, d], equat1[u, o, d, 1/1000] /.
          o -> 0, d, .5, u, .1, WorkingPrecision -> 100];

          newODE = First@Solve[
          D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
          D[equat1[u, o, d, 1/1000] /. d -> d[o], u -> u[o], o],
          d'[o], u'[o]
          ] /. Rule -> Equal; // AbsoluteTiming
          (* 7.57532, Null *)

          ClearAll[uprime];
          uprime[o1_?NumericQ, d1_, u1_] := Block[o,
          Quiet[Check[
          newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1,
          nlim++;
          Limit[newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1],
          Power::infy, Infinity::indet],
          Power::infy, Infinity::indet]
          ];

          newODE2 = First@newODE, u'[o] == uprime[o, d[o], u[o]];

          nlim = 0;
          dsolk, usolk =
          NDSolveValue[newODE2, u[0] == uk, d[0] == dk, d, u, o, 0, 1,
          PrecisionGoal -> 8, AccuracyGoal -> 8,
          WorkingPrecision -> 50]; // AbsoluteTiming
          nlim
          (*
          99.1584, Null
          3 <-- number of times Limit[] was called
          *)

          ListLinePlot@dsolk, usolk


          enter image description here



          In sum, equat2[] is numerically ill-conditioned in places. Perhaps simplification can help, or manual analysis, although the equations are too unwieldy for a quick look-see. However, I don't have any more time to look into it or the FindRoot problem, which is likely to be related, at this point.






          share|improve this answer









          $endgroup$












          • $begingroup$
            Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
            $endgroup$
            – Michael E2
            4 hours ago













          2












          2








          2





          $begingroup$

          I think the problem is a 0/0 term somewhere in the expression for equat2[] that arises at the time the integration begins to fail, from around 0.60 to 0.62. This causes numeric noise in computing u'[o], which leads to NDSolve[] thinking there's an error. A common factor can be eliminated for o -> 0 via Simplify. I let Simplify run for a several minutes on general o to no avail. So I resorted to Limit, which is slow. To resolve the issue, I needed higher WorkingPrecision, so I had to avoid Method -> "EquationSimplification" -> "Residual", which can only be used with the machine-precision IDA method. I also replaced the parameter e value 0.001 with 1/1000 to avoid machine precision. I timed all the time-consuming computations.



          dk, uk = d, u /. 
          FindRoot[equat2[u, o, d], equat1[u, o, d, 1/1000] /.
          o -> 0, d, .5, u, .1, WorkingPrecision -> 100];

          newODE = First@Solve[
          D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
          D[equat1[u, o, d, 1/1000] /. d -> d[o], u -> u[o], o],
          d'[o], u'[o]
          ] /. Rule -> Equal; // AbsoluteTiming
          (* 7.57532, Null *)

          ClearAll[uprime];
          uprime[o1_?NumericQ, d1_, u1_] := Block[o,
          Quiet[Check[
          newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1,
          nlim++;
          Limit[newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1],
          Power::infy, Infinity::indet],
          Power::infy, Infinity::indet]
          ];

          newODE2 = First@newODE, u'[o] == uprime[o, d[o], u[o]];

          nlim = 0;
          dsolk, usolk =
          NDSolveValue[newODE2, u[0] == uk, d[0] == dk, d, u, o, 0, 1,
          PrecisionGoal -> 8, AccuracyGoal -> 8,
          WorkingPrecision -> 50]; // AbsoluteTiming
          nlim
          (*
          99.1584, Null
          3 <-- number of times Limit[] was called
          *)

          ListLinePlot@dsolk, usolk


          enter image description here



          In sum, equat2[] is numerically ill-conditioned in places. Perhaps simplification can help, or manual analysis, although the equations are too unwieldy for a quick look-see. However, I don't have any more time to look into it or the FindRoot problem, which is likely to be related, at this point.






          share|improve this answer









          $endgroup$



          I think the problem is a 0/0 term somewhere in the expression for equat2[] that arises at the time the integration begins to fail, from around 0.60 to 0.62. This causes numeric noise in computing u'[o], which leads to NDSolve[] thinking there's an error. A common factor can be eliminated for o -> 0 via Simplify. I let Simplify run for a several minutes on general o to no avail. So I resorted to Limit, which is slow. To resolve the issue, I needed higher WorkingPrecision, so I had to avoid Method -> "EquationSimplification" -> "Residual", which can only be used with the machine-precision IDA method. I also replaced the parameter e value 0.001 with 1/1000 to avoid machine precision. I timed all the time-consuming computations.



          dk, uk = d, u /. 
          FindRoot[equat2[u, o, d], equat1[u, o, d, 1/1000] /.
          o -> 0, d, .5, u, .1, WorkingPrecision -> 100];

          newODE = First@Solve[
          D[equat2[u, o, d] /. d -> d[o], u -> u[o], o],
          D[equat1[u, o, d, 1/1000] /. d -> d[o], u -> u[o], o],
          d'[o], u'[o]
          ] /. Rule -> Equal; // AbsoluteTiming
          (* 7.57532, Null *)

          ClearAll[uprime];
          uprime[o1_?NumericQ, d1_, u1_] := Block[o,
          Quiet[Check[
          newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1,
          nlim++;
          Limit[newODE[[2, 2]] /. d[o] -> d1, u[o] -> u1, o -> o1],
          Power::infy, Infinity::indet],
          Power::infy, Infinity::indet]
          ];

          newODE2 = First@newODE, u'[o] == uprime[o, d[o], u[o]];

          nlim = 0;
          dsolk, usolk =
          NDSolveValue[newODE2, u[0] == uk, d[0] == dk, d, u, o, 0, 1,
          PrecisionGoal -> 8, AccuracyGoal -> 8,
          WorkingPrecision -> 50]; // AbsoluteTiming
          nlim
          (*
          99.1584, Null
          3 <-- number of times Limit[] was called
          *)

          ListLinePlot@dsolk, usolk


          enter image description here



          In sum, equat2[] is numerically ill-conditioned in places. Perhaps simplification can help, or manual analysis, although the equations are too unwieldy for a quick look-see. However, I don't have any more time to look into it or the FindRoot problem, which is likely to be related, at this point.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          Michael E2Michael E2

          154k12 gold badges211 silver badges500 bronze badges




          154k12 gold badges211 silver badges500 bronze badges











          • $begingroup$
            Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
            $endgroup$
            – Michael E2
            4 hours ago
















          • $begingroup$
            Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
            $endgroup$
            – Michael E2
            4 hours ago















          $begingroup$
          Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
          $endgroup$
          – Michael E2
          4 hours ago




          $begingroup$
          Note also that the total number of steps according to dsolk@"Grid" // Length is only 264.
          $endgroup$
          – Michael E2
          4 hours ago

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Mathematica Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201281%2fruntime-too-long-for-ndsolvevalue-findroot-breaks-down-at-sharp-turns%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

          Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її