Re: Normal areas between two values: a home-made program



On Jun 26, 5:58 pm, Old Mac User <chendrixst...@xxxxxxxxx> wrote:
On Jun 24, 6:03 pm, "Luis A. Afonso" <lic...@xxxxxxxxxxx> wrote:



Normal areas between two values: a home-made program

Input [z0 , z1]          area

___ -2,  -1_______0.135905__
___ -1,   3 ______ 0.839995__
___  1 ,  2.5 ____  0.152446__

The program below is based on a power series [26.2.10] Abramovitz, Stegun, handbook of Mathematical Functions; the last term absolute value set at 0.00000005. Surely one could be further, but it is completely unnecessary because 6 exact decimal places are sufficient to all practical purposes.
Because the algorithm was do to span values greater (or equal) than 0, the different signals of interval bounds were took into consideration. (See listing, indT).

Luis A. Afonso

        REM "ZZ"
        CLS
        DEFDBL A-Z
17      REM
        PRINT "***** NORMAL LAW ***** ZZ ****"
        PRINT "     prob. [Z0 , Z1]        Z0<Z1  "
        LOCATE 10, 10
        INPUT "  Z0, Z1  "; x(1), x(2)
        IF x(1) < -6 THEN x(1) = -6
        IF x(2) > 6 THEN x(2) = 6
        IF x(1) > x(2) THEN GOTO 17
        pi = 4 * ATN(1): c = 1 / SQR(2 * pi)
        IF x(1) * x(2) >= 0 THEN indT = 1
        IF x(1) * x(2) < 0 THEN indT = 2: REM THEN x(1)<0
        IF x(2) < 0 THEN ind1 = 1
        DEF fng (x, j) =
 -x ^ 2 * (2 * j + 1) / ((j + 1) * (2 * j + 3)) * .5
        FOR k = 1 TO 2: s(k) = 0
        x = ABS(x(k))
        s(k) = c * x: antes = c * x
        FOR j = 0 TO 100
        xx = antes * fng(x, j)
        s(k) = s(k) + xx
        antes = xx
        IF ABS(xx) < .00000005# THEN GOTO 100
        NEXT j
100     NEXT k
        LOCATE 12, 1: COLOR 3
        PRINT " ----->    prob. [Z0 , Z1]    ";
        IF indT = 2 THEN GOTO 11
        IF indT = 1 THEN GOTO 12
11      PRINT USING "#.###### "; s(1) + s(2)
        END
12      PRINT USING "#.###### "; ABS(s(2) - s(1))
        END

Luis,

I tried to run this code using Microsoft Basic and it failed.
It ran just so far and then quit with no clue to what went wrong/

????

My faith is fading.

OMU

Afonso,

I checked this code using Microsoft Basic on my PC and it worked. I
actually tested it to about 5 standard deviations and it is
surprisingly accurate. I don't pretend to know the background or
origin of the concept for this algorithm, but from my viewpoint it
works nicely.

I did have to make a few slight changes by making some lines near
the top be "Remarks". Other than that, it ran just fine.

My previous attempt with it was Microsoft Basic on a vintage
Macintosh. There are small differences between MS Basic (actually
QuickBasic) on the Mac and on the PC. I'll locate the difference that
were causing a problem on my previous attempt. These differences are
usually obvious... it's just a matter of having an "ah ha" moment.

Yes, I know that in 2009 there are a lot of people who think that
Basic is a dead language. I continue to use it in part because Basic
code is almost intuitive and can be read and understood by
almost anyone who knows anything about writing code. But I also
continue to use it because it is easily transported to almost any sort
of computer hardware including process control computers.

I've written code in other languages including C and C++. But when
teaching computational methods it's very difficult to get a room full
of people to "see" what I'm doing in those languages.
They can take the Basic code and change it into whatever they want it
to be. Including Excel macros if that's the kind of people they are
(I'd never attempt that.)

I also know that many people think that Basic is simplistic. True,
some modern languages let us do a lot with just a few lines of code.
Personally, I prefer to write my own code so that I can see precisely
what I'm doing. I've written my own code since I first encountered
digital computers while working at NASA in the late 1950s, beginning
with autocoder. Strange though it may seem, I do not use any
commercial statistical software other than for certain graphics. I
fully understand that writing code is not for everyone.

To make life even more interesting, in 2001 I had the need for an
interpreter (somewhat like Basic, but different) that would be
transportable but with math capabilities not found in any of the more
than 150 existing versions of Basic. So I wrote my own interpreter
which is embedded in a lot of my personal software.

That said... yes, your code works and does what I expected it to do. I
may find a use for it. Thanks for your patience. OMU

.



Relevant Pages

  • Re: OS X.4.X update...
    ... back" some languages you have removed, unless they are smart enough not ... has very little in the way of multiple language support. ... applications which support Unicode - AppleWorks is not one of them). ... It doesn't even touch on the other things you can do with computers now ...
    (comp.sys.mac.system)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... and Richard made it clear that he understands the order ... >> of evaluation of a for loop. ... > using strlen but using an Oalgorithm when there is a trivial O ... >> In most other languages the terminating ...
    (comp.programming)
  • Re: your assistance is requested
    ... I take this proof that chicks don't know shit about computers? ... Park-Miller PRNG has an even smaller range of internal states, ... and the RC5 algorithm is far more involved ... should try to publish in a crypto conference or journal. ...
    (comp.compression)
  • Re: Consciousness: whats the problem?
    ... will know all you really need to know about digital computers. ... unknown algorithm is being run. ... the idealized and actual instruction sets are well known. ...
    (comp.ai.philosophy)
  • Re: Meyer(s) gets it wrong
    ... but not in the same way that many, supposed, OO languages support them. ... I have two programs running on seperate computers. ... TBH I find the idea of seperate processes which have defined interfaces, ... be described as being 'just' good SP practice. ...
    (comp.programming)

Loading