# Why does NDSolve and NIntegrate not give the same result? [closed] I have plotted solution of two equivalent equations one in Integral form (right chart) the other in Differential form (left chart) using NDSolve and NIntegrate but they give me completely different graphs. Can somebody explain why this is happening?

My NIntegrate code for the right hand chart:

Subscript[Ω, rad] = 10^-4;
Subscript[Ω, mat] = 0.3;
Subscript[Ω, Λ] = 0.7;
Subscript[H, 0] = 2*10^-18;
c = 3*10^8;
Subscript[a, 0] = 10^-10;
H[z_] := Subscript[H,
0]*(Subscript[Ω, rad] (1 + z)^4 +
Subscript[Ω, mat] (1 + z)^3 +
Subscript[Ω, Λ])^0.5;
Plot[6 (1 + x)^3*
NIntegrate[(H[z] - (1 + z) H'[z])/(1 + z)^4, {z, x, 100000}], {x, 0,100000}]


The NDSolve code for the left hand chart:

Subscript[Ω, rad] = 10^-4;
Subscript[Ω, mat] = 0.3;
Subscript[Ω, Λ] = 0.7;
Subscript[H, 0] = 2*10^-18;
c = 3*10^8;
Subscript[a, 0] = 10^-10;
Subscript[z, i] = 10^5;

H[z_] := Subscript[H,0]*(Subscript[Ω, rad] (1 + z)^4 + Subscript[Ω, mat] (1 + z)^3 +Subscript[Ω,Λ])^0.5;
ϵ[z_] := H'[z]/H[z] (1 + z);

s = NDSolve[{(1 + z)^2 ϕ''[z] - (2 - ϵ[z]) (1 + z) ϕ'[z]== 6 (1 - ϵ[z]), ϕ == 0, ϕ' == 0}, ϕ, {z, 0, Subscript[z, i]}];
Z[z_] := -((c*ϕ'[z] H[z] (1 + z))/Subscript[a, 0])^2

Plot[Evaluate[-((c*ϕ'[z] H[z] (1 + z))/Subscript[a, 0])^2 /.s], {z, 0, 10^5}]


The relevant equations are $$Z=-(\frac{c \dot{\phi}}{a_0})^2$$ dot is derivative with respect to time and ' is derivative with respect to $z$ (Note: capital Z and small z are different)$$\frac{dz}{dt}=-H(1+z)$$ and $$\phi(t)=6\int_{t_i}^{t}\frac{dt'}{a^3(t')}\int_{t_i}^{t'}dt''a^3(t'')[\dot{H(t'')}+H^2(t'')]$$

## closed as off-topic by march, m_goldberg, user9660, MarcoB, Yves KlettMay 26 '16 at 6:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, m_goldberg, Community, MarcoB, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

• We can't explain without seeing your specific code, preferably a simplified version that shows the same behavior. – march May 22 '16 at 0:25
• sure I am gonna copy the code and paste it here – MSB May 22 '16 at 0:26
• I ahve written the codes now – MSB May 22 '16 at 1:10
• Would you mind also mentioning a bit of background on where you got these equations from? The most obvious recommendation I can give at the moment is for you to use exact constants (e.g. 1/2 instead of 0.5). – J. M. will be back soon May 22 '16 at 1:34
• Not sure about how well Subscript is handled. Personally I have come to avoid it as the devil will holy water. As I don't want to worry about Downvalues or not I often end up simply using variable names like \[CapitalOmega]rad in one symbol. – gwr May 22 '16 at 10:00

I have found my mistake. It was on the initial condition if we take $$\phi(zi)=0$$ and $$\phi'(zi)=0$$ the both methods will give the exact same solution.