I just solved a differential equation with NDSolve, and the behavior of the solution was not what I was expecting. In trying to track down where things went wrong, I plotted the solution function evaluated at the time that the initial condition is given, and it doesn't match what I had specified as the initial condition. I tried the solution proposed here with no luck.
Code:
a[t_] := Piecewise[{{e 0.000204499/Sqrt[47000] Sqrt[t], t < 46995}, {f t^3 + g t^2 + h t + i, 46995 <= t < 47005}, {c ((t)^0.667)/(6.39143*10^6) + d, 47005 <= t < 9800000000}, {q E^(Sqrt[1.989*10^(-20)/3] (t)) + b, t >= 9800000000}}] //. {q -> 0.292367892161671, b -> 0.10064726726594109, c -> 1.0386606919493655, d -> 0.00006529554347973175, e -> 1.3579559739239264, f -> -4.3633807877894195*10^(-13), g -> 6.152604549062771*10^(-8), h -> -0.002891832817142504, i -> 45.30731397090777, j -> 1.1404135497820182*10^-23, k -> 1.1236120846288418*10^-13, u -> -0.0054880391504018525, v -> 3.225813286569839*10^7}; zed[t_] := 1/a[t] - 1; zTable = {}; zTable = Table[{10^T, zed[10^T]}, {T, 3, 10, 0.0001}]; zedInt = Interpolation[zTable]; lamavg[t_] := Min[1, 0.01 + 0.07 zedInt[t]] eps = .1; l = (126/100)*10^(31); sol = 3*^8; moDot = 1.989*10^30 DifEq = D[P[M, t], t] == -31536000* M l/(moDot*sol^2) (1 - eps)/eps lamavg[t] D[P[M, t], M]; fixedM[x_] := 2.396946971556801*^-7*(32.59434080693661 - 2.0297457454952188*^-7 x + 1.2887918124478197*^-15 x^2 - 2.5861699533219344*^-25 x^3 + 1.941139394441828*^-35 x^4 - 5.134757798851362*^-46 x^5); fixedT[M_] := 26 (M^(-1)) E^(-4.7 M*10^(-10)); soln = NDSolve[{DifEq, P[M, 8.15240949872944*^8] == fixedT[M], P[10^5.263, t] == fixedM[t]}, P[M, t], {M, 10^5.263, 10000000000}, {t, 1000, 8.15240949872944*^8}, Method -> {"IndexReduction" -> {Automatic, "ConstraintMethod" -> "Projection"}}] Plot of initial condition and problematic solution:
ϕ[m_, T_] := P[M, t] /. soln //. {M -> m, t -> T} Plot[{ϕ[M, 8.15240949872944*^8] /. soln, fixedT[M]}, {M, 10^6, 10^10}, PlotRange -> {0, 10^-7}] Thanks!
P.S. Also note that the interpolation for a and zedInt should be pretty good, a is continuous but not differentiable.
Edits: e-> eps, added a factor to the previously enormous coefficient




NDSolvecode in version 10.4, it returns with a message and unevaluated. $\endgroup$lamavg[t], sorry about that $\endgroup$