# NSolve for Piecewise function

I have a piecewise function. I want to find the root of this function with the NSolve command. But, it does not give me any result and it just prints the equation. I can find the root with FindRoot, but the problem is that my initial point is not a constant number, and I have to change the initial point each time. So, for the purpose I have, the FindRoot command is not a suitable case. Can anyone help me to find the root with the NSolve? Thank you so much. Here is the code:

a=7.64606*10^-10;
b=0.00160977;
G=4.30091*10^-6;
g[x_]=856595/x^(7/4);
f[x_]=1.066*10^8/((1 + x/26)^2 x);
h[x_]=Piecewise[{{0,x<a},{g[x],a<=x<=b},{f[x],x>b}}]
j[x_]=Integrate[G/
u^2 (Integrate[4 \[Pi] w^2 h[w], {w, 0, u},
Assumptions -> {u > 0}]), {u, x, \[Infinity]},
Assumptions -> {x > 0}];
NSolve[j[x]==139284, x]
FindRoot[j[x]==139284, {x,4,10}]


Clear["Global*"]

a = 7.64606*10^-10 // Rationalize[#, 0] &;
b = 0.00160977 // Rationalize[#, 0] &;
G = 4.30091*10^-6 // Rationalize[#, 0] &;
g[x_] = 856595/x^(7/4);
f[x_] = 1.066*10^8/((1 + x/26)^2 x) // Rationalize[#, 0] &;
h[x_] = Piecewise[{{0, x < a}, {g[x], a <= x <= b}, {f[x], x > b}}] //
Simplify;

j[x_] = Integrate[
G/u^2 (Integrate[4 \[Pi] w^2 h[w], {w, 0, u},
Assumptions -> {u > 0}]), {u, x, \[Infinity]},
Assumptions -> {x > 0}] // Simplify;

sol = NSolve[j[x] == 139284, x, WorkingPrecision -> 12]

(* {{x -> 4.02093432553}} *)


Verifying,

j[x /. sol[[1]]]

(* 139284.0000 *)
`
• Thank you. It worked. Commented Feb 3, 2022 at 19:52