For illustration, you could pass an Empty down the length of the cube, create a vertex group in the cube, (say, 'Prox',) and give the cube a Vertex Weight Proximity modifier, modifying the weights in the group by the proximity of the Empty.
Here, we see the Vertex Weight Proximity modifier, affecting the 'Prox' group, targeted on the plain-axis Empty, and the consequent weights (made visible in the 'Overlay' settings,in Edit Mode).
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/AWp5Y.png)
Those weights can then be used to control other modifiers. For longitudinal compression, you could parent a plane to the Empty, and give the cube a Shrinkwrap modifier, projected in + and - of the length-axis (mine is X) towards the plane, weighted by the 'Prox' group:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/uzPfx.png)
If, for example, you wanted a leading compression front, rather than contraction on both sides of the plane, you could get the shrinkwrap to project on one side only.
This, though, is as shown:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/SOQlX.gif)
For transverse compression, you could use a Displace (along normals) modifier instead of the shrinkwrap.. no need for the plane:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/sxhLh.gif)
If you needed something more mathematically exact, I'm sure there will be a Geometry Nodes solution. For that, maybe you could provide your wave function.
![](https://cdn.statically.io/img/blend-exchange.com/embedImage.png?bid=KSzNq8A7)