09-23-2022, 06:34 PM
Pete, have you seen this? https://www.wikihow.com/Calculate-Cube-Root-by-Hand
Any math experts know what I'm missing here? [Solved]
|
09-23-2022, 06:34 PM
Pete, have you seen this? https://www.wikihow.com/Calculate-Cube-Root-by-Hand
@Jack
I did read that yesterday. That plus this https://en.wikipedia.org/wiki/Nth_root#Examples on Wikipedia helped me make this, which I think works... [NOTE: I haven't put a decimal place in yet, just digits.] Code: (Select All) $CONSOLE:ONLY Pete
Shoot first and shoot people who ask questions, later.
09-23-2022, 08:19 PM
(This post was last modified: 09-23-2022, 08:22 PM by Kernelpanic.)
Quote:Let's say, and I'll just make up a number for this: 4.9665242234315151119541094114141414143678 and it is supposed to be 5. The example with the number 4.9665 ... which is supposed to be 5 reminded me that I once had to solve a similar problem myself. A good 20 years ago I wrote an article in a Java magazine about a financial calculation. During programming I had to find out that the corresponding function in Java 1.1 had a nasty bug. If there was a 9 at the third decimal place, something like this: 4,869... then it was not rounded up, but 4,869 became 4.1. Very evil, and very nasty! I only recognized the error because I had previously programmed the same stuff in C. OK! In Java there was no way to separate the decimal part like in C with fmod(). The only way was to convert the number to a string, check the decimal part, and then convert everything back to a number. See the screenshot. You can do the same here too. Pseudocode: Exponent (n) is 5. If the decimal part is 9 in the first place and greater than 5 in the third place, then n = 5. Why still iterations?
09-23-2022, 08:45 PM
Well that's rounding for you, and rounding is tricky. Let's say I want the cube root of 7.997600239992. That is approximately 1.998. Rounding that as 2 would be an error. So then we start to require rules like: Do not round to a whole number if the number the root is extracted from is a decimal, etc., etc., etc.. I'm not sure who wrote the bible on rounding exceptions, but I'm not interested in becoming a disciple.
Pete
Shoot first and shoot people who ask questions, later.
09-23-2022, 08:56 PM
(09-23-2022, 08:45 PM)Pete Wrote: Well that's rounding for you, and rounding is tricky. Let's say I want the cube root of 7.997600239992. That is approximately 1.998. Rounding that as 2 would be an error. So then we start to require rules like: Do not round to a whole number if the number the root is extracted from is a decimal, etc., etc., etc.. I'm not sure who wrote the bible on rounding exceptions, but I'm not interested in becoming a disciple. Well Pete, it's your path you want to go!
09-23-2022, 10:13 PM
The path doesn't bother me. It's the damn rabbit holes along the path that bothers me.
Here's a beauty... For calculators it is easy enough to do fraction division, and express the result as a decimal. I just keep the fraction for the next calculation. Now with roots, I don't see a way to do that. Roots often result in very long or non-terminating decimals. The long division binomial expansion method I just put together does not appear to have any divisor to place a remainder over. So if that's so, and I want to use roots in my string math calculator, this would totally blow apart the accuracy of using fractions in division when a root extraction cannot be expressed as a fraction and blows all that work straight down the rabbit hole. Pete
Shoot first and shoot people who ask questions, later.
09-25-2022, 10:05 PM
(This post was last modified: 09-25-2022, 10:07 PM by Kernelpanic.)
Like cube root of 19 to 100 places?
2.668401648721944867339627371970830335095878569183101865664213586945793971672059716316681593100516540 or how about 1,000? 2.668401648721944867339627371970830335095878569183101865664213586945793971672059716316681593100516540971200115121674125395007158654306951149574674557937819247978231238324074345969306769527367552077588789283162098019865860310973250749366855816387636411912497141957497075505870839424737202877377620335424466759417959346644389526318379034086274805653954347616576587643586016635041559445622377433338136015881058842865546315105639472400872468056996811327861031078857024674652824263716248095765210682549755520817960718459266515565633668331455418178360503783875980933641063457961841915715468558854504732505707270369593102468158975185730051221532488066929421076424593422434976561310400347154900112534271679002569726757164211489255334200509328542492626608085317755137411050512911632210102102304034256017180280147241524905629502377797452960048708915324624653820450799494643975595244219506033096681932949861574867095932178514065043374071529672321318975592408317607496760349497350851789545929864955777170940718277 The hundred output took less than a second, but the 1000 output took nearly 3-minutes. I would need to figure out an estimate program to cut that down to around 15-30 seconds. Pete
09-26-2022, 04:52 PM
@Pete, do you have decimal place worked out for Square Roots?
I just modified an Extended Integer Square Root code to a Real Square Root in String Math. I wonderful improvement over the old estimate method I had, faster and accurate to any amount of decimals!
b = b + ...
09-26-2022, 05:57 PM
I do have the decimal places worked out for square roots. I need to either modify it for nth roots, or see if I need to tweak it for square roots, in case I missed something. One I settle on a working method, I'll probably scrap the square root one and just use the nth root routine.
Looking forward to getting this up as a "Work in Progress" soon. Right now, it has been fun learning, and putting together systems. While approximation methods are fun, they are just not practical, and too slow for very large numbers. Long division is accurate. Long division with a way to approximate the next part of the quotient is also fast. I'm not quite sure how to do that estimate with nth roots, yet. I have already incorporated a great estimate method in the standard long division process. I hope to apply something similar to nth roots, soon. 100 digits of a two-digit number cube root takes under 1-second, but it takes a 2-3 minutes to take that same two-digit number out to 1,000. places Anyway, here is a link to my latest nth root in string math, as well as a little routine to calculate the values in Pascal's Triangle. https://qb64phoenix.com/forum/showthread.php?tid=918 Will you be posting your modified extended square root code? Fun stuff! Pete
Shoot first and shoot people who ask questions, later.
|
« Next Oldest | Next Newest »
|