I have following code:
Two differential equations,each one of them with varying initial conditions
Clear["Global`*"]
sol1[l0_] := NDSolve[{D[r[x]/(1 + x)^4, x] == 0, r[l0] == 2}, r, {x, 0,1000}, AccuracyGoal -> 15];
sol2[l0_] := NDSolve[{D[n[x]/(1 + x)^4, x] == (r[x] /. First@sol1[l0]), n[l0] == 2}, n, {x, 0, 1000}, AccuracyGoal -> 15];
Next I try to plot the solution of the sum of solutions of differential equations as function of $l0$, but this doesn't work:
len = 3; sum := 0;
sump[l0_, i_] := n[i] /. sol2[l0];
Do[sum += sump[l0, i] , {i, len}];
Plot[sum, {l0, 1, 2}, PlotRange -> All, PlotStyle -> Red]
Some alternative solution: If I choose "l0" in the first differential equation it works
Clear["Global`*"]
sol1 := NDSolve[{D[r[x]/(1 + x)^4, x] == 0, r[2] == 2}, r, {x, 0, 1000}, AccuracyGoal -> 15];
sol3[l0_] := NDSolve[{D[n[x]/(1 + x)^4, x] == (r[x] /. First@sol1), n[l0] == 2},n, {x, 0, 1000}, AccuracyGoal -> 15];
len = 3;
sump[l0_, i_] := n[i] /. sol3[l0];
sum := 0;
Do[sum += sump[l0, i] , {i, len}];
Plot[sum, {l0, 1, 2}, PlotRange -> All, PlotStyle -> Red]
sump[l0, 1]
, for instance? Do you notice the problem? If you do not provide a numerical value forl0
, NDSolve cannot proceed symbolically and throws (many, many) errors. $\endgroup$