```
ClearAll("Global`*")
time = Solve(x - (1/2)*g*(t^2) == 0, t)
position = Solve(x - (1/2)*g*(t^2) == 0, x)
v = D((g t^2)/2, t)
T = Sqrt(2*h/g)
dt = D((Sqrt(2) Sqrt(x))/Sqrt(g), x)
Ptdt1 = dt1/T // PowerExpand
Ptdt =
Replace(Ptdt1, {t -> (Sqrt(2) Sqrt(x))/Sqrt(g),
dt1 -> (1/(Sqrt(2) Sqrt(g) Sqrt(x)))*dx}, All)
rhot = Ptdt/Ptdt((2))
Integrate(rhot, {x, 0, h})
Ex = Integrate(x*rhot, {x, 0, h})
h = 20
Plot(rhot, {x, 0, h}, AxesOrigin -> {0, 0})
```

Please see my code to do a problem in Griffith’s quantum mechanics. But I have a feel that my code is really lengthy and is not general. Is there a way to make this general? or any easy alternatives?