I am asking Mathematica to solve a differential equation using DSolve
, with two different parameters, q and m, and then evaluate at a point.
So I write the following lines of code:
x[y_] = w[y] /.
First[DSolve[{w'[y] == (1 - (2 m y^2)/(y^2 + q^2)^(3/2))^-1},
w[y], y]] /. C[1] -> 0;
m = 1.; q = 1/2;
x[2]
Where the output is (I just chose a random point to evaluate this function, it does not really matter where):
-4.60489 - 1.14725*10^-19i .
However, If I first set the parameters (using the same values as before) and then let Mathematica solve it:
m = 1.; q = 1/2;
x[y_] = w[y] /.
First[DSolve[{w'[y] == (1 - (2 m y^2)/(y^2 + q^2)^(3/2))^-1}, w[y],
y]] /. C[1] -> 0
x[2]
It yields:
Inactive[Integrate][(
0.25 Sqrt[1. + 4. K[1]^2] +
1. K[1]^2 Sqrt[1. + 4. K[1]^2])/(-4. K[1]^2 +
0.25 Sqrt[1. + 4. K[1]^2] +
1. K[1]^2 Sqrt[1. + 4. K[1]^2]), {K[1], 1, 2}]
which is an integral that cannot be analytically solved.
How come this happens? Why would the order that I define my constants change the outcome of how Mathematica handles this differential equation? What I find even weirder, is that (at least to me) it seems like it would be simpler to set the parameters first and then solve it.
NIntegrate
seems to suggest the last integral doesn't converge. $\endgroup$y
. Also, C[1] is not necessarily the same quantity in the two solutions. $\endgroup$