## How to NDSolve this equation?

I am trying to find the answer to f[r] in the following differential equation. Is there anything wrong? Why the output is printed with error?

eq=-2 + r - r*f[r] +    (0.01*(-2*Derivative[f][r]*(6*f[r] - 6*f[r]^2 +         r*Derivative[f][r]*(3 + r*Derivative[f][            r])) + 6*r*f[r]*(2 - 2*f[r] +         r*Derivative[f][r])*Derivative[f][r]))/    r^2;  NDSolve[{eq==0},f,{r,0,5}] 

All the additional informations are $$f(0)=\infty$$, and $$f(\infty)=1$$.

## Export NDSolve output to .txt

I tried to store the output of the following piece of code

s = NDSolve[{u'[x] ==  v[x] , v'[x] == u[x], u == 1,      v == 1}, {u, v}, {x, 0, 1}, WorkingPrecision -> 70,     PrecisionGoal -> 20] ; 

in a .txt file with the commands

SetDirectory[NotebookDirectory[]]; data = Table[{x, u[x] /. s, v[x] /. s}, {x, 0, 1, 0.1}] // TableForm Export["data.txt", data, "List"]; 

Unfortunately the resulting .txt had the following ugly arrangement

0.{1.}{1.} 0.1{1.1051709180440972}{1.1051709180440972} 0.2{1.2214027580171631}{1.2214027580171631} 0.30000000000000004{1.349858807431976}{1.349858807431976} 0.4{1.4918246976372467}{1.4918246976372467} 0.5{1.648721270402639}{1.648721270402639} 0.6000000000000001{1.8221187976152273}{1.8221187976152273} 0.7000000000000001{2.013752707127757}{2.013752707127757} 0.8{2.2255409261449164}{2.2255409261449164} 0.9{2.4596031083207683}{2.4596031083207683} 1.{2.718281828459045}{2.718281828459045} 

I want to get something like this

0.0    1.00000  1.00000 0.1    1.10517  1.10517 0.2    1.22140  1.22140  0.3    1.34985  1.34985  ... 

Can anyone help?

## How to find the distances between two adjacent maxima in a solution from NDSolve

I try to find a general approach to plot the time evolution of horizontal distances from maximum to maximum in a solution of PDE. The solution u[x,t] normally have multiple maximum and minimum in space x, which move in space x and evolve in time t.

Here is a simple example, in which the maxima and minima are periodic. But in my real problem they are not periodic and the distances between different pairs of adjacent max are different at a given t, also the distances between two adjacent max can change with t.

sol = NDSolve[{D[u[x, t], t] + u[x, t] D[u[x, t], x] + D[u[x, t], x, x] +  0.4*D[u[x, t], {x, 3}] + D[u[x, t], {x, 4}] == 0, u[-4 \[Pi], t] == u[4 \[Pi], t], u[x, 0] == 0.1*Sin[x]}, u, {t, 0, 20}, {x, -4 \[Pi], 4 \[Pi]}]  Plot3D[Evaluate[u[x, t] /. First[sol]], {t, 0, 10}, {x, -4 Pi, 4 Pi}, PlotRange -> All, PlotPoints -> 100] I have tried to use Table[FindMaximum[Evaluate[u[x, t] /. First[sol]], {x, x0}][[2, 1, 2]], {t,0,tend,0.01}] with an initial position x0 to find a local maximum. But I don’t know how to find two adjacent maxima simultaneously in order to plot the time evolution of their distance.

## Singularity or stiff system in NDSolve

I have the following piece of code

(*UV cuttoff*) rmax = 10; (*Fixed input values*) nc = 4; nf = 4; (*Value of \[Alpha]1*) \[Alpha]1 = 0.95;  b0 = 1/(6 \[Pi]) (11 nc - 2 (nc + 2) nf) ;  b1 =  1/(24 \[Pi]^2) (34 nc^2 - 10 nc (nc - 2) nf  -        6 (nc + 1) (nc - 2) (nc - 2) nf) ;  eqalp1 = alp1'[mu1] + (b0 alp1[mu1]^2 + b1 alp1[mu1]^3) == 0;   sol1 = NDSolve [{ eqalp1, alp1 == \[Alpha]1},     alp1, {mu1, 0, 10^24}];  alph1[mu1_] := First[Evaluate[alp1[mu1] /. sol1]]  alph1[mu1]; \[Alpha][mu_] := alph1[mu] 

It works fine if I choose nf=1,2,3 but when I set nf=4 and higher I get the following error message I tried to solve the differential equation not from zero but from other points. Every time I get a similar error. I also tried changing the tuned input for \[Alpha]1 in the beginning of the code, but the same message persists.

Can someone suggest something to bypass this?

Posted on Categories cheapest proxies

## How to use NDSolve with limited RAM?

How can I use NDSolve when running out of RAM?

The code I am implementing:

sol = NDSolve[ pdes, {A, B, C},     {x, -L, L}, {t, Tf, Tf} ] 

in order to obtain the end solution of NDSolve to be exported to the next run (due to limited RAM).

In previous attempts the solution of NDSolve was exported as an interpolating function, such as:

Export["sol_Tf.wdx",sol] 

sol_Tf.wdx is the export file of the NDSolve run.

Also see my previous question.

I then imported it as:

Import["sol_Tf.wdx"] 

and used the boundary conditions:

A[x, Ti] == A[x, Tf] B[x, Ti] == B[x, Tf]  C[x, Ti] == C[x, Tf] 

But the results were different from running it all in one go. What went wrong here? Is there a better way of doing this?

## Why does domain size change results of NDSolve? / How to overcome this?

this is a follow-up on a previous question which was answered, but it turned out that I was running in circles…

I have the following code:

(*Parameters*)eps = 1.4434; m = 0.3; c11 = 0.1732; (*PDEs*) pde1 :=    D[pp[t, x, y], t] ==     0.05*Laplacian[pp[t, x, y], {x, y}] +      pp[t, x, y]*(1 - c11*pp[t, x, y] - z[t, x, y]/(1 + pp[t, x, y]^2)); pde2 := D[z[t, x, y], t] ==     0.05*Laplacian[z[t, x, y], {x, y}] +      z[t, x, y]*(eps*pp[t, x, y]/(1 + pp[t, x, y]^2) - m); (*Initial conditions*) lo = 22 hi = 25 domlen = 50 ic1[x_, y_] := Which[x > lo && x < hi && y > lo && y < hi, 6, True, 0]; ic2[x_, y_] := Which[x < hi, 1, True, 1/c11]; (*Numerical approximation using NDSolve with zero-flux boundary \ conditions*) {solp, solz} =   Monitor[NDSolveValue[{pde1, pde2, z[0, x, y] == ic1[x, y],      pp[0, x, y] == ic2[x, y]}, {pp, z}, {t, 0,      100}, {x, y} \[Element] Rectangle[{0, 0}, {domlen, domlen}],     EvaluationMonitor :> (monitor = Row[{"t = ", CForm[t]}])], monitor] 

which produces certain spatiotemporal patterns.

However, I am not sure wether these patterns result from boundary forcing. Hence, I want to consider a larger domain and check wether these patterns still emerge.

Here is the same code for a larger domain (even the extent of initial conditions is the same).

(*Parameters*)eps = 1.4434; m = 0.3; c11 = 0.1732; (*PDEs*) pde1 :=    D[pp[t, x, y], t] ==     0.05*Laplacian[pp[t, x, y], {x, y}] +      pp[t, x, y]*(1 - c11*pp[t, x, y] - z[t, x, y]/(1 + pp[t, x, y]^2)); pde2 := D[z[t, x, y], t] ==     0.05*Laplacian[z[t, x, y], {x, y}] +      z[t, x, y]*(eps*pp[t, x, y]/(1 + pp[t, x, y]^2) - m); (*Initial conditions*) lo = 2 hi = 5 domlen = 10 ic1[x_, y_] := Which[x > lo && x < hi && y > lo && y < hi, 6, True, 0]; ic2[x_, y_] := Which[x < hi, 1, True, 1/c11]; (*Numerical approximation using NDSolve with zero-flux boundary \ conditions*) {solp, solz} =   Monitor[NDSolveValue[{pde1, pde2, z[0, x, y] == ic1[x, y],      pp[0, x, y] == ic2[x, y]}, {pp, z}, {t, 0,      100}, {x, y} \[Element] Rectangle[{0, 0}, {domlen, domlen}],     EvaluationMonitor :> (monitor = Row[{"t = ", CForm[t]}])], monitor] 

Why do I get this error now:

NDSolveValue: At t == 56.08186878658157, step size is effectively zero; singularity or stiff system suspected 

To me it does only make sense that Mathematica adjusts the step size to the domain and a larger step size results in this error. Am I right with that? What can I do?

Thank you!

## Problem with manipulate solution NDSolve and initial condition

I’m getting crazy with this Manipulate :

 Clear[l, L, nc, phic, tauC, tauG, tauS, phi0, Vinitphi, Vphi0, nL0, \ V, Vphi, VinitR, VinitR0, dV, V0, Vphi0]  VinitR0 = 0 L = 6000 nL0 = 1 phi0 = 0.4  model[Vinitphi_?NumberQ, l_?NumberQ, nc_?NumberQ, phic_?NumberQ,    tauC_?NumberQ, tauG_?NumberQ, tauS_?NumberQ] =   Module[{V, t, Vphi, VinitR},    First[V[t] /.      NDSolve[{V'[         t] == (-((            4 l L nL0 \[Pi] Csch[((3/\[Pi])^(1/3) V[t]^(1/3))/(              2^(2/3) l)] (-l^2 Sinh[((3/\[Pi])^(1/3) V[t]^(1/3))/(                 2^(2/3) l)] + (               l (3/\[Pi])^(1/3)                 Cosh[((3/\[Pi])^(1/3) V[t]^(1/3))/(2^(2/3) l)] V[t]^(                1/3))/2^(2/3)))/(-l -              L Coth[((3/\[Pi])^(1/3) V[t]^(1/3))/(               2^(2/3) l)] + ((3/\[Pi])^(1/3)               Coth[((3/\[Pi])^(1/3) V[t]^(1/3))/(2^(2/3) l)] V[t]^(              1/3))/2^(2/3))) - nc V[t]) /tauG  +          1/tauS*(1 - VinitR[t]/Vinitphi)/phi0 -          1/tauC*(1 - (1 - (Vphi[t]/V[t]))^2)*          V[t]^(2/3)*(-((            2 (Vphi[t]/V[t]) (-2 + 2 (1 - (Vphi[t]/V[t])) +                phic) (-(Vphi[t]/V[t]) + phic))/(1 - phic)^2)),        V == 1,        Vphi'[         t] == ((-((             4 l L nL0 \[Pi] Csch[((3/\[Pi])^(1/3) V[t]^(1/3))/(               2^(2/3) l)] (-l^2 Sinh[((3/\[Pi])^(1/3) V[t]^(1/3))/(                  2^(2/3) l)] + (                l (3/\[Pi])^(1/3)                  Cosh[((3/\[Pi])^(1/3) V[t]^(1/3))/(2^(2/3) l)] V[t]^(                 1/3))/2^(2/3)))/(-l -               L Coth[((3/\[Pi])^(1/3) V[t]^(1/3))/(                2^(2/3) l)] + ((3/\[Pi])^(1/3)                Coth[((3/\[Pi])^(1/3) V[t]^(1/3))/(2^(2/3) l)] V[t]^(               1/3))/2^(2/3))) - nc V[t]) (Vphi[t]/V[t]))/tauG  +          1/tauS*(1 - VinitR[t]/Vinitphi), Vphi == phi0,        VinitR'[t] == 1/tauS*(1 - VinitR[t]/Vinitphi),        VinitR == VinitR0}, {V}, {t, 0, 170}]]]  Manipulate[  Plot[Evaluate@({model[Vinitphi, l, nc, phic, tauC, tauG, tauS][t]}), {t, 0,     170}], {{Vinitphi, 10^5}, 10^5, 2*10^6,    Appearance -> "Labeled"}, {{l, 5}, 5, 40,    Appearance -> "Labeled"}, {{nc, 0.3}, 0.3, 0.6,    Appearance -> "Labeled"}, {{phic, 0.6}, 0.6, 75,    Appearance -> "Labeled"}, {{tauC, 0.1}, 0.1, 1.5,    Appearance -> "Labeled"}, {{tauG, 1}, 1, 20,    Appearance -> "Labeled"}, {{tauS, 10^(-5)}, 10^(-5), 10^(-4),    Appearance -> "Labeled"}]  

I’m getting the error :

NDSolve::ndnum: Encountered non-numerical value for a derivative at t\$ 174887 == 0..

Could you help me please ?

Posted on Categories cheapest proxies

## Finding NDSolve method details

I have eqs about the NDSolve, I know this code given the solving automatically.

How can I find out what method is used behind the scenes? How can I gauge the reliability level, find how many iterations have been used, the order of method. How can I estimate the error?

I found hints on this site, but I still do not fully understand.

It is impossible to say NDSolve has automatically solution for publishing paper?

I used this code related to my system:

r = 0.431201; β = 2.99 *10^-6; σ = 0.7; δ = 0.57; {m = 0.3, η = 0.1, μ = 0.1, ρ = 0.3};   S = {N1'[t] == r N1[t] (1 - β N1[t]) - η  N1[t] I1[t],      I1'[t] == σ + (ρ  N1[t]  I1[t])/( m + N1[t]) - δ I1[t] - μ  N1[t] I1[t]};  c = {N1 == 1, I1 == 1.22};  Select[Flatten[   Trace[     NDSolve[{S, c}, {N1, I1}, {t, 0, 30}],      TraceInternal -> True]],    !FreeQ[#, Method | NDSolveMethodData] &] 

but I don’t understand the output.

## How to solve these ODEs using NDSolve?

I have six odes and I cannot use DSolve. So I tried NDSolve. But it says there may be some errors.The code is such like this:

I1 = 2; I2 = 3; I3 = 4; NDSolve[{I1*ω1'[t] + (I3 - I2)*ω2[t]*ω3[t] == 0,  I2*ω2'[t] + (I1 - I3)*ω1[t]*ω3[t] == 0,  I3*ω3'[t] + (I2 - I1)*ω2[t]*ω1[t] == 0,  ω1[t] == φ'[t]*Sin[θ[t]]*Sin[ψ[t]] + θ'[t]*Cos[ψ[t]],  ω2[t] == φ'[t]*Sin[θ[t]]*Cos[ψ[t]] - θ'[t]*Sin[ψ[t]],  ω3[t] == φ'[t]*Cos[θ[t]] + ψ'[t],  ω1 == 2, ω2 == 3, ω3 == 4, ψ == 0, φ == 0, θ == Pi/6},  {ω1, ω2, ω3, ψ, φ, θ}, {t, 0, 120}] 

I want to know how to avoid this error.

## Eliminating Discontinuities When Using Mod with NDSolve and Plot for Oscillators

I have found similar questions to mine, but dealing with piecewise and parametric plots instead and unfortunately the answers don’t seem to extend to my case.

I have a solution from NDSolve for two oscillators, however I would like to plot that solution between 0 and 2pi instead of the whole set of reals. I have used Mod to keep the values between the desired range, but I am left with the discontinuities you see below. Is there anyway to eliminate these discontinuities for the general case?

Thanks 🙂

Code to generate solutions:

Example[\[Theta]1IC0_, \[Theta]2IC0_] :=  Module[{\[Theta]1IC = \[Theta]1IC0, \[Theta]2IC = \[Theta]2IC0},  n = 2;  \[Omega] = {0.95 \[CapitalOmega]0,  1.05 \[CapitalOmega]0}; \[Theta] = {\[Theta]1, \[Theta]2}; \[CapitalOmega]0 = (2 \[Pi])/24;  Eqs = Table[\[Theta][[i]]'[t] == \[Omega][[i]] + 1/n Sum[Sin[\[Theta][[j]][t] - \[Theta][[i]][t]], {j, 1, 2}], {i, 1, 2}];  ICs = {\[Theta][] == \[Theta]1IC, \[Theta][] == \[Theta]2IC};  EqsICs = Join[Eqs, ICs];  {Solution =  NDSolve[EqsICs, {\[Theta][], \[Theta][]}, {t, 0, 100}]} ] 

Here is the code to plot the solutions:

Show[Table[Plot[Mod[\[Theta][[i]][\[Tau]] /. Example[0, \[Pi]/2],  2 \[Pi]], {\[Tau], 0, 40}, PlotRange -> All, AxesOrigin -> {0, 0}, AxesLabel -> {"t", "\!$$\*SubscriptBox[\(\[Theta]$$, $$i$$]\)"},  PlotStyle -> TwoColours[[i]], PlotLegends -> Placed[{ToString[\[Theta][[i]]]}, Below]], {i, 1, 2}]] `

And here is the output: Posted on Categories cheapest proxies