Perimeter of Ellipse
|
12-05-2019, 03:17 PM
Post: #14
|
|||
|
|||
RE: Perimeter of Ellipse
This is an equivalent Decimal BASIC program of a C-program by Hugh Steers here. The port of this one or the original C-program to the Prime should be straightforward. The computational effort is a fraction of that involved in the computation of the elliptic integral, but that may not make a significant difference in fast calculators like the Prime.
OPTION ARITHMETIC DECIMAL_HIGH INPUT PROMPT "a, b: ":ae,be LET nd = 1000 LET tm = TIME LET b = be/ae LET s = (1 + b*b)/2 LET a = 1 LET t = 1 DO LET a1 = (a + b)/2 IF a = a1 THEN EXIT DO LET c = (a - b)/2 LET b = SQR(a*b) LET a = a1 LET s = s - t*c*c LET t = t + t LOOP LET p = 2*PI*ae*s/a LET r = TIME - tm LET r$ = STR$(p - INT(p)) PRINT STR$(INT(p)); PRINT r$(0:1); FOR i = 2 TO nd + 1 PRINT r$(i:i); IF MOD((i - 1),10) = 0 THEN PRINT " "; IF MOD((i - 1),50) = 0 THEN PRINT REPEAT$(" ",1 + LEN(STR$(INT(p)))); END IF NEXT i IF MOD (i - 2,50) <> 0 OR nd = 0 THEN PRINT PRINT "Runtime: "; PRINT USING "0.##": r; PRINT " seconds" END --------------- a, b: 3,4 22.1034921607 0950504528 5586463872 4607782782 8910007059 3992632612 5910396946 4959177286 6218309324 0390352083 5815953162 7467734138 2129000335 3896736622 8442994174 6192287204 5014970302 5317033312 3929977604 0095275908 3220930141 4469558250 9419563787 3762863238 9667370976 2571981363 4931419230 9352895844 1906042118 2907229022 9686418117 2635887950 2052296943 0126681600 8830044762 7954774028 4076289798 3279618691 9046286983 5594397451 2356208773 7408645009 3309824766 6784863302 2726732463 0516083153 4972329406 0801844377 6345370790 6974256179 0156140823 0342896177 6736816934 6443281912 6179659392 2331855348 5127216985 8740979075 6632664289 7373983969 0524635361 8083080355 2201668145 2949128953 8470111771 1967401421 1827316426 8227257828 0215582400 2244838587 9322889687 7768410992 9363265305 7955533884 5140145875 1572214188 4766228802 8889719384 4198561575 6084702523 4710513780 8869298904 8167827143 0007524734 3709238837 9951007032 1404352133 5658034012 3750989012 2020953649 3147176616 2140936028 0496095218 3637964950 6346311041 3538836238 7660229689 7814732208 7377779791 016495137 Runtime: 0.05 seconds |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)