Any math experts know what I'm missing here? [Solved]
#12
@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
DIM AS DOUBLE d, i, j, r, t, x, oldx
INPUT "Whole number: "; n%
INPUT "Root: "; r%
r = r%
n$ = LTRIM$(STR$(n%))
h&& = (r - (r - LEN(n$) MOD r)) + 1
t = VAL(MID$(n$, 1, h&& - 1))
limit&& = 8
DO
    lcnt&& = lcnt&& + 1
    PRINT "Target ="; t
    FOR j = 1 TO 10
        x = 0
        FOR i = 1 TO r
            IF i = 1 THEN
                PRINT "(10 ^"; (i - 1); "*"; i; "* d ^"; i - 1; " * j ^"; (r + 1 - i); ") + ";
                x = x + 10 ^ (i - 1) * i * d ^ (i - 1) * j ^ (r + 1 - i)
            ELSE
                PRINT "(10 ^"; (i - 1); "*"; r; "* d ^"; i - 1; " * j ^"; (r + 1 - i); ") + ";
                x = x + 10 ^ (i - 1) * r * d ^ (i - 1) * j ^ (r + 1 - i)
            END IF
        NEXT
        PRINT "<<<"; x
        IF x > t THEN EXIT FOR
        oldx = x
    NEXT
    d = VAL(LTRIM$(STR$(d)) + LTRIM$(STR$(j - 1)))
    PRINT "t - oldx as: "; t; "-"; oldx; "="; t - oldx,: COLOR 14: PRINT "d ="; d: COLOR 7
    tmp1$ = LTRIM$(STR$(t - oldx))
    tmp2$ = MID$(n$, h&&, r) + STRING$(r - LEN(MID$(n$, h&&, r)), "0")
    PRINT "tmp1$ = "; tmp1$, "tmp2$ = "; tmp2$, "n$ = "; n$
    t = VAL(tmp1$ + tmp2$) ' This will remove any leading zeros carried down.
    h&& = h&& + r
    IF t = 0 AND h&& >= LEN(n$) OR lcnt&& = limit&& THEN EXIT DO
LOOP
PRINT
RUN

Pete
If eggs are brain food, Biden takes his scrambled.
Reply


Messages In This Thread
RE: Any math experts know what I missing here? - by Pete - 09-23-2022, 07:40 PM



Users browsing this thread: 4 Guest(s)