Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any math experts know what I'm missing here? [Solved]
#1
Reply
#2
What's up with every line being in its own code block, Pete?
Tread on those who tread on you

Reply
#3
I do not understand your problem. Why about the extensions of the binomial theorem? You can easily calculate the cube root with the now well-known formula. Or am I misunderstanding the question?

Code: (Select All)
Dim As Double n, x, rootx

Print
Input "Wurzelexponent: ", n
Input "Radikand      : ", x

rootx = x ^ (1 / n)

Print Using "Kubikwurzel: ###.##########"; rootx

[Image: Kubikwurzel-2022-09-23.jpg]
Reply
#4
(09-23-2022, 01:37 PM)Spriggsy Wrote: What's up with every line being in its own code block, Pete?

I've had that also before. Something was wrong with the copying. Just delete and do it again.
Reply
#5
For Spriggsy:
Code: (Select All)
$Console:Only
Dim As Double d, h, i, j, n, r
n = 10: root = 3
For g = 1 To 5 ' Just do 5 iterations with no decimal point for this demo.
    Print "working number ="; n
    If h = 0 Then
        Print "Initial loop..."
        For h = 1 To 10
            If h ^ root > n Then Exit For
        Next
        h = h - 1
        x = h ^ root ' This is the answer digit for the first iteration.
    Else
        For h = 1 To 10
            j = h * (((root * (i * 10 ^ (root - 2))) * ((i * 10 ^ (root - 2)) + h) + h ^ (root - 1)))
            Print h; i, j; "<>"; n
            If j > n Then Exit For
        Next
        h = h - 1
        d = i * (10 ^ (root - 2))
        Color 2: Print "d ="; d, "h ="; h: Color 7
        x = h * (((root * d) * (d + h) + h ^ (root - 1)))
    End If
    Print "Number to subtract ="; x
    Rem i = i * (10 ^ (root - 2)) + h
    i = Val(LTrim$(Str$(i)) + LTrim$(Str$(h)))
    Color 14: Print " i as digits ="; i: Color 7
    r = (n - x)
    n = r * 10 ^ root
    Print "Remainder ="; r ' This is the remainder.
    Print "n ="; n; " d ="; d; " h ="; h; "remainder ="; r; "Answer ="; i
Next

Don't know why Pete didn't fix it himself, too tired?


Quote:I do not understand your problem. Why about the extensions of the binomial theorem? You can easily calculate the cube root with the now well-known formula. Or am I misunderstanding the question?


I think Pete is looking for a routine to do roots he can translate to string math. I don't get the Binomial Theorem reference either but the code does get the first digits of 10^.3333... and some other like n = 5 or 27 or .027 or 125 (but not 125^3) but no decimal placements.
b = b + ...
Reply
#6
I think I either pranked myself or Steve is feeling better and did it for me! Individual code boxes. I sure as hell didn't stay up all night making those. Weird. Fixed now.

Hey guys, binomial expansion as in, if you've ever prayed for death: https://www.youtube.com/watch?v=RD_Ybm86fu8

Your prayers got answered!

Easier read: https://www.wikihow.com/Calculate-Cube-Root-by-Hand

Okay, so the binomial expansion works for cubes, but as written won't do anything but cubes when I change the root variable to say 2, 4, or 5. So either I goofed up something in the algorithm, and amazingly it still works for cubes, or there is some more complicated factorials that need to be considered with other nth roots that i haven't figured out and applied.

In regard to decimal point, I have not bothered with that part yet. Just trying to get the digits for now, but mainly I'm looking for a long division (instead of approximation) process for nth roots (meaning all roots like squares, cubes, 4ths, 5ths...).

Pete
Shoot first and shoot people who ask questions, later.
Reply
#7
(09-23-2022, 01:53 PM)Kernelpanic Wrote: I do not understand your problem. Why about the extensions of the binomial theorem? You can easily calculate the cube root with the now well-known formula. Or am I misunderstanding the question?

Code: (Select All)
Dim As Double n, x, rootx

Print
Input "Wurzelexponent: ", n
Input "Radikand      : ", x

rootx = x ^ (1 / n)

Print Using "Kubikwurzel: ###.##########"; rootx

[Image: Kubikwurzel-2022-09-23.jpg]

It's great for limited digit numeric math, but I couldn't use it for string math because the only algorithm I was able to convert to handle the decimal roots needed by that algorithm was done with approximation decimal form, and in string math that leads to rounding errors. In string math, you need to work with fractions so 1/3 is really 1/3 and not .333.

For example: Take the cube root of 125. Simple, 5, right? Well, let's look at the equation in terms of string math when decimal powers are encountered an calculated by approximation with Newton's work:

125 ^ (1 / 3) is "125"^ ".333..."

125^.333... in string math = 4.996 to three digits, not 5. Now since string math can easily handle a 1,000+ digits, the accuracy problem with larger numbers would be immense. Let's say, and I'll just make up a number for this: 4.9665242234315151119541094114141414143678 and it is supposed to be 5. So if we cube it it falls just short of 125. Now because there are so many digits, it would take several iterations to correct it by approximation. So two processes would be needed, and the latter one would be lengthy. This would really slow up computations of 200+ digit numbers coupled with very large nth roots.

Pete
Reply
#8
Okay, it appears after a bit more research the binominal expansion is written correctly, but only for cubes. As one of my hunches should prove out that algorithm needs to be expanded upon for larger nth roots, so just plugging in the higher roots to the existing formula is a fail.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#9
I've had extra tags appear after too many edits, but nothing on that scale!

Can't entirely rule out the had of Steve, tho.
Reply
#10
Yeah, I have no idea if I did something out of the ordinary to cause that line by line code fiasco. Hope to never see it again. Hell of a thing to wake up to.

Well in better news, I've got a good handle on an iterative formula working with square roots and cube roots in a test phase. I need to add the part where the remainder is brought down, according to the nth root size, to finish it.

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 9 Guest(s)