Gravitational Potential Energy

In this problem we calculate the potential energy u[r] of a point-mass particle m with repsect to a massive shell of uniform density ρ and inner radius b and outer radius a.  Using the boundary condition u[∞] = 0, we find the following solutions for all three regions where the factor ((4/3)πρGm)  is set equal to 1.  We combine the piecewise continuous solutions in all three regions to form a single continuous function u[r] as shown below.

u[r_]:=(Piecewise[{{-(3/2) ((a^2)- (b^2)), r<b}, {-(1/(2 a r)) (3 (a^3) r - a (r^3) - 2 a (b^3)), b≤r≤a}, {-((((a^3)-(b^3)))/r), r>a}}])

Pick an inner radius of b=1 and an outer radius of a=2.

a=2;
b=1;

Plot[u[r],{r,0,10},AxesOrigin->{0,0}]