English
Source / code snippets

Kubikwurzel from negativen numbers

 

p.specht

roots ungerader ganzzahliger Radix (3. root, 5., 7. etc.) from negativen numbers are mathematically permitted. Reelle Argumente having thereby real Results, The the same omen carry How the Radikand, d.i. the worth from the The root pulled becomes.

unfortunately know many Programmiersprachen not, and XProfan is there no exception. The suitable Abstürze having me to that subesquent comparison unterschiedlicher Kubikwurzel-Algorithms led, those not crash.
Windowtitle "Diverse Kubikwurzelalgorithmen in the Vergleich"
cls:font 2:set("decimals",17)
declare x!,y1!,y2!,y3!,y4!,w$,ex!

Repeat

    Print "\n Radikand x = ";:input w$:case w$="":end
    w$=upper$(trim$(w$)):ex!=if(instr("E",w$), val(substr$(w$,-1,"E")),0)

    ifnot between(ex!,-53,53):beep:print "\n *** Exponent out of brat! ***"

        waitinput:cls:continue:endif:x!=val(w$)
        y1!=cubrt1(x!):y2!=cubrt2(x!):y3!=cubrt3(x!)
        locate 4,3
        print "     cubrt1(x)            cubrt2(x)             cubrt3(x)"
        locate 6,3 :print stature$("%g",y1!)
        locate 6,27:print stature$("%g",y2!)
        locate 6,52:print stature$("%g",y3!)
        print "\n Abs.Diff: y2-y1=          y3-y1=                y3-y2="
        locate 9,3 :print stature$("%g",y2!-y1!)
        locate 9,27:print stature$("%g",y3!-y1!)
        locate 9,52:print stature$("%g",y3!-y2!)
        print "\n   Probe: y1^3             y2^3=                  y3^3="
        locate 12,3 :print stature$("%g",sqr(y1!)*y1!)
        locate 12,27:print stature$("%g",sqr(y2!)*y2!)
        locate 12,52:print stature$("%g",sqr(y3!)*y3!)
        waitinput
        cls

    until 0

    proc cubrt1 :parameters x!

        var sgn!=1-2*(x!<0):x!=abs(x!)
        return if(x!=0,0,sgn!*x!^0.333333333333333333)

    endproc

    proc cubrt2 :parameters x!

        var sgn!=1-2*(x!<0):x!=abs(x!)
        return if(x!=0,0,sgn!*sqrt(x!)/x!^(1/6))

    endproc

    proc cubrt3 :parameters v!

        case V!=0:return 0.0:declare sg!,epsi!,r!,last_r!,i&
        sg!=if(V!<0,-1,1):v!=abs(v!):r!=1:i&=0
        epsi!=1.77*10^(-15+lg(V!)*(lg(V!)>0)/3)
        'lg(x)=ln(x)*0.434294481903251827

        while i&<=3000:last_r!=r!:r!=(2*r!+V!/sqr(r!))/3

            inc i&:case abs(r!-last_r!)<=epsi!:break
            endwhile:case i&>3000:return -9.9999999999e-52
            return r!*sg!

        endproc


P.s.: at that Kubieren (thrice with itself self multiplizieren) of zero and negativen numbers with the ^-symbol occur ditto Abstürze, there it no such Argumente verträgt. here's remedy but plainer :proc cub :parameters x!:return sqr(x!)*x!:endproc
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/22/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.347 Views

Untitledvor 0 min.
Rschnett08/06/22
p.specht11/21/21
R.Schneider11/20/21
Uwe Lang11/20/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie