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[0] == 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[0] == phi0,        VinitR'[t] == 1/tauS*(1 - VinitR[t]/Vinitphi),        VinitR[0] == 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 ?

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[0] == 1, I1[0] == 1.22};  Select[Flatten[   Trace[     NDSolve[{S, c}, {N1, I1}, {t, 0, 30}],      TraceInternal -> True]],    !FreeQ[#, Method | NDSolve`MethodData] &] 

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[0] == 2, ω2[0] == 3, ω3[0] == 4, ψ[0] == 0, φ[0] == 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][[1]][0] == \[Theta]1IC, \[Theta][[2]][0] == \[Theta]2IC};  EqsICs = Join[Eqs, ICs];  {Solution =  NDSolve[EqsICs, {\[Theta][[1]], \[Theta][[2]]}, {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:

enter image description here

Solve nonlinear ODE system (2nd order) with dependent variables using NDSolve

I’m trying to solve 2nd Order related ODE system with five dependent variables. The equations are:

eqn1 = D[z]*C''[Z]-u*C'[z]==a*r1[z] eqn2 = k[z]*T''[z]-q*T'[z]==a*(r1[z]*b+r2[z]*c+r3[z]*d) 

Where a,b,c,d are constants; k[z],D[z], ri[z] (where i=1,2,3) are dependent variables of T[z] and C[z], and C[z] and T[z] depends of one to each other . ( I have the equations of k[z], D[z] and ri[z] but I think they are not quite important right now.)

I have the following boundary conditions:

initConds={T[0]==893.15, T'[L]==0,C[0]==0.992,C'[L]==0}; 

where L’s value is 9.

I’m using NDSolve as the following one but the program cannot solve this and give as output to me the next error.

s = NDSolve[{eqns, initConds}, {T[z], C[z]}, {z, 0, 9,  

0.01}]

NDSolve::ntdv: Cannot solve to find an explicit formula for the derivatives. Consider using the option Method->{"EquationSimplification"->"Residual"}. 

Assuming that Mathematica can solve it, how could I write a code using, if possible, the NDSolve?

THANKS!

Force NDSolve to include three BC constraints to a second order ODE because generic NDSolve choses wrong intial slope

The following is an ODE that represents a numerical solution for the radial part of the heat equation corrected to first order for a spatially varying thermal conductivity in spherical coordinates. This computes the temperature distribution near the tip of a self-cooled electrode / ablation catheter. Since the heat equation is second order, NDSolve requires two BCs, but faults when three are specified. The problem requires the specification of temperatures at an initial and final spatial point {r0,large} respectively. In order to specify a power input, the temperature slope must be specified at the initial position (tt'[r0]). There is an extreme temperature point (max/min) at an intermediate point between initial and final temperature locations.(See graphic below.) The generic NDSolve chooses the wrong sign for the initial temperature slope because the curve length between initial temperature, (tt[r0]) and final temperature, (tt[large]) is shorter when (tt'[r0]<0) versus curve length when (tt'[r0]>0). The question is how do I specify the value of (tt'[r0] = pwr/(thermalConductivity * r0)) ? NOTE: As I have stated before, I am only a dumb engineer who only infrequently uses Mathematica when I need a solution that could have been solved by a Mathematician and is free of the errors and inconsistencies of Matlab. I would appreciate it if one of the “monitors” would transfer the code and graphic to traditional “people readable” format here. Thanks!!

<< VectorAnalysis` SetCoordinates[Spherical[r, theta , phi]] de = \!\(TraditionalForm\`Div[\((1 + \((dkc/kc0)\)*tt[r])\)*   Grad[tt[r]]] - \((pwr/\((\((kc0 - dkc*tt[r])\)*r)\)\ *\ \((r0^3/     r^5)\)\ )\)\);   ss = Simplify[de]; kc0z = 1.0; dkcz = 0.01; r0z = 0.1; largez = 20.0; pwrz = 40.0; tbodz = 37.0; tzeroz = 25.0;  ppp = NDSolve[{{ss == 0, tt[r0] == tzero, tt[large] == tbod}},  tt[r], {r, r0, large}] /. {kc0 -> kc0z, dkc -> dkcz, r0 -> r0z,  large -> largez, pwr -> pwrz, tbod -> tbodz, tzero -> tzeroz } rmax = 0.5; Plot[Evaluate[tt[r] /. ppp], {r, r0z, rmax}, Frame -> True,  GridLines -> Automatic, PlotRange -> {{r0z, rmax}, {0, 50}}] 

Temprature plot from r0 to "large"

NDSolve error: Cannot solve to find an explicit formula for the derivatives. Consider using the option Method->{“EquationSimplification”->”Residual”}

I get the above error message when running the following code:

\[Alpha]h = 0.2; \[Alpha]z = 0.2; \[Gamma] = 0.5; ph = 0.01; pf = \ 0.1; pE = 0.05; FC = 0.1; FE = 0.15; tC = 0.01; tE = 0; TC = 0.05; TE \ = -0.05; w = 1; \[Rho] = 0.2; \[Sigma] =   1/(1 - \[Rho]); L = 1; RA = 0.25; \[Mu] = 1;  G = 1; R0 = 0.1; S = 1;  v[s_] := \[Mu] Log[     Exp[(\[Alpha]h ((RC[s] +                ph)^(-(\[Rho]/\[Sigma]))  + (\[Alpha]h/\[Alpha]z)^(-(\ \[Rho]/\[Sigma])))^((           1 - \[Rho])/\[Rho]) (w + G + R0/L - (pf + tC) s - FC -              TC) - \[Gamma]  Integrate[            LogisticSigmoid[              x] ((\[Alpha]h/\[Alpha]z)^(-(\[Rho]/\[Sigma])) + (RC[x] +                   ph)^(-(\[Rho]/\[Sigma])) )/((RC[x] +                   ph)^-\[Sigma]   (w + G + R0/L - (pf + tC) x - FC -                   TC)), {x, s, S}])/\[Mu]] +       Exp[(\[Alpha]h ((RC[s] +                ph)^(-(\[Rho]/\[Sigma]))  + (\[Alpha]h/\[Alpha]z)^(-(\ \[Rho]/\[Sigma])))^((           1 - \[Rho])/\[Rho]) (w + G + R0/L - (pE + tE) s - FE -              TE) - \[Gamma]  Integrate[(1 -                LogisticSigmoid[                x]) ((\[Alpha]h/\[Alpha]z)^(-(\[Rho]/\[Sigma])) + (RC[                   x] + ph)^(-(\[Rho]/\[Sigma])) )/((RC[x] +                   ph)^-\[Sigma]   (w + G + R0/L - (pf + tC) x - FC -                   TC)), {x, s, S}])/\[Mu]]];  sol = FullSimplify[Solve[{D[v[s], s] == 0}, RC'[s]]] solprime = Equal @@@ Flatten[sol]; solND = NDSolve[{solprime[[1]], RC[S] == RA}, RC, {s, 0, S}] 

I have tried to add the proposed method and also Method->{“EquationSimplification”->”Solve”} but got other error messages then after quite some time of computation. Either “NDSolve::idelay: Initial history needs to be specified for all variables for delay-differential equations.” or “StringForm::sfr: Item 2 requested in “Delayed time 1 = 2 computed at 3 = 4 did not evaluate to a real number.” out of range; 1 items available.”

Any advice would be highly appreciated. Thanks!

ndsolve with multiple initial conditions

I am trying to solve a PDE using the NDsolve with initial and boundary conditions,

NDSolve[{D[u[t, x], t] - D[ D[u[t, x], x]] + D[u[t, x], x] == 10,     u[0, x] == 2,     u[t, 0] == 1,     u[t, 2] == 1     },     u,     {t, 0, 5}, {x, 0, 2}, MaxStepSize -> 0.01] 

it worked. But when I trying to assign a initial condition: u[0,x]=2 when 0.5<=x<=1, u[0,x]=1 elsewhere in [0,2] by means of If

NDSolve[{D[u[t, x], t] - D[ D[u[t, x], x]] + D[u[t, x], x] == 10,     If[0.5 <= x <= 1, u[0, x] == 2, u[0, x] == 1],     u[t, 0] == 1,     u[t, 2] == 1     },     u,     {t, 0, 5}, {x, 0, 2}, MaxStepSize -> 0.01] 

the system returned me

NDSolve::deqn: Equation or list of equations expected instead of If[0.5<=x<=1,u[0,x]==2,u[0,x]==1] in the first argument {(u^(1,0))[t,x]==10,If[0.5<=x<=1,u[0,x]==2,u[0,x]==1],u[t,0]==1,u[t,2]==1}. 

I know something is wrong with my initial conditions expression, But how I assign the initial conditions with an if condition. Or a better way to deal with it?

Thank you for your time!

UPDATE:

I followed the advice of @bbgodfrey by using DirichletCondition. it worked.

NDSolve[{D[u[t, x], t] - D[ D[u[t, x], x]] + D[u[t, x], x] == 0,         DirichletCondition[u[t, x] == 2, 0.5 <= x <= 1],         DirichletCondition[u[t, x] == 1, {2 >= x > 1, 0 <= x < 0.5}],     u[t, 0] == 1,     u[t, 2] == 1     },     u,     {t, 0, 5}, {x, 0, 2}, MaxStepSize -> 0.01] 

But comparing with the results of @kglr, the results are different. this is the results using DirichletCondition, which also with an alert

NDSolve::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help.

enter image description here

this is the result using Boole

enter image description here

Thank you!