As @petter suggests, Expression element is great for this as it provides an automatically updating dynamic state. This is very similar to doing it “the vanilla Bubble way” where you might use two disabled inputs to hold your ratios. These will automatically update as their source inputs change – and without having to add “when an input’s value is changed” workflows as you would have to do if updating a custom state.
NOTE, whether you use math.js or Expression, those things may throw errors all over the place when your dynamic source values are null, right? So you need to set it up correctly (unless you don’t mind throwing console errors all over the place).
I set up a little sample project so you can see how you should do this. (Links at end, anyone can view editor). It demonstrates both using disabled inputs and using Expression.
See my earlier comment as well about what you likely did wrong with math.js. The same applies here.
Here’s how you would do this with Expression:
And of course you can see the condition here avoids evaluating the expression when any of the source values are undefined and thus we avoid throwing errors.
Examine sample project for more:
Hit F12 to open console to prove errors aren’t being thrown.
Edit: Made editor visible.