Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Any work-around for math

I've added a nifty little calculator to my GURPS sheet to calculate relative velocity for Slam attacks. I got as far as calculating the square of the relative speed, but, since there is no square root function, I can't complete it. On a whim, I tried a veeerry long brute force equation, but I guess it was too much and it didn't work. Is there any other way to work around this?
1403060326
Lithl
Pro
Sheet Author
API Scripter
Another user asked for a workaround for sqrt in the mentors forum a little while ago, and I directed him to the Babylonian method of approximating square roots. <!-- let's calculate sqrt(a^2 + b^2) shall we? --> <input type="hidden" disabled="true" name="attr_s" value="(@{a} * @{a} + @{b} * @{b})" /> <!-- Choose a different initial guess if you like, just make sure the result will be positive --> <!-- The better the initial guess is, the more accurate the result will be --> <input type="hidden" disabled="true" name="attr_x0" value="@{s} / 2" /> <!-- Add additional iterations if you need additional accuracy --> <input type="hidden" disabled="true" name="attr_x1" value="((@{x0} + @{s} / @{x0}) / 2)" /> <input type="hidden" disabled="true" name="attr_x2" value="((@{x1} + @{s} / @{x1}) / 2)" /> <input type="hidden" disabled="true" name="attr_x3" value="((@{x2} + @{s} / @{x2}) / 2)" /> <input type="hidden" disabled="true" name="attr_x4" value="((@{x3} + @{s} / @{x3}) / 2)" /> <input type="hidden" disabled="true" name="attr_x5" value="((@{x4} + @{s} / @{x4}) / 2)" /> <input type="hidden" disabled="true" name="attr_x6" value="((@{x5} + @{s} / @{x5}) / 2)" /> <input type="number" disabled="true" name="attr_result" value="@{x6}" /> This method works by convergence of the arithmetic means of over- and under-estimates of your target number. For an example, look at sqrt(100) = 10: s = 100 x0 = s / 2 = 50 x1 = (50 + 100 / 50) / 2 = (50 + 2) / 2 = 26 x2 = (26 + 100 / 26) / 2 = (26 + 3.846) / 2 = 14.923 x3 = (14.923 + 100 / 14.923) / 2 = 10.812 x4 = (10.812 + 100 / 10.812) / 2 = 10.030 x5 = (10.030 + 100 / 10.030) / 2 = 10.00004 x6 = (10.00004 + 100 / 10.00004) / 2 = 10.000000000107445793143744907022 The worse your initial estimate is, the more iterations you need for a good approximation. Your initial guess (x0) can be literally any positive number, and it doesn't need to be based on s like mine (s / 2). The final value will always be an overestimate, because an arithmetic mean is always going to be greater than a geometric mean.
Awesome - once again you have the answer. Thanks!