I'm having a lot of trouble maintaining consistency with directions in physics and would like to demonstrate this with a problem. I hope for an answer that does not just resolve the problem but clarifies the general issue of maintaining consistent directions (so no, I am not just asking for homework help).
My approach here is to start with the reference height $0$ at the very bottom and then change the reference height to the height of the spring. I want to do this by subtracting out the spring's height once I create the equation.
Attached is a diagram demonstrating this:
Defined are the height of the spring, $h_s$, the height of the block (relative to the surface) $h_b$, $h_F$, the final height of the block at max compression of the string, and $x_b$, the compression distance of the spring.
The compression distance of the spring, denoted as $ x_B $, is defined as the difference between the initial height $ h_s $ and the final height $ h_F $:
$$x_B = h_s - h_F.$$
The first equation:
The first equation: $$ mg(h_s + h_B) = \int\limits_{h_s}^{h_F} 105 \, x^{2.5} \, \mathrm{d}x \, \cos(180^\circ) + mg h_F $$
After subtracting ($h_s$): $$mgh_B = \int\limits_{0}^{h_F - h_s} 105 \, x^{2.5} \, \mathrm{d}x \, \cos(180^\circ) + mg(h_F - h_s)$$
In the final equation: $$mgh_B = \int\limits_{0}^{-h_B} 105 \, x^{2.5} \, \mathrm{d}x \, \cos(180^\circ) + mg(-x_B).$$
However, plugging this into my calculator gives an invalid answer. I get the correct answer when I remove the $\cos(180^\circ)$, though, but I don't understand why. Isn't the block going opposite the direction of the force?
Finally, what is a strategy for dealing with directions in physics? I seem to always mess them up/be inconsistent, and from class lectures/practice assignments, it almost feels subjective/speculatory what directions things are. I want to find a way to define one consistent axis and apply it, but so far, that isn't working (the problem is an example). I can't seem to understand why, and I would like your help understanding this.
This is beyond a homework answer, and any answers here can help people understand how directions work in physics and how to correctly define axes, baselines, and coordinates.