Two questions: Drawing Normal Curve and setting start & end values on a slider

Michael J. Lew michaell at unimelb.edu.au
Mon Nov 22 23:56:40 EST 2004


This should get you going:

You need a graphic called "DistHistoBox", a text field at either end 
of its base, "distMin" and "distMax" to hold the scale values and two 
scrollbars, "mean" and "stdev". Put the following script into a 
button and that should do it.

on mouseUp
   put the thumbposition of scrollbar "mean" into tmean
   put the thumbposition of scrollbar "stdev" into tstdev
     put standardNormalPDF() into myPoints
   set the points of graphic "DistHistoLine" to myPoints
   set the rect of graphic "DistHistoLine" to the rect of graphic "DistHistoBox"
   put tmean-3*tstdev into fld "DistMin"
   put tmean +3*tstdev into fld "DistMax"
end mouseUp

function StandardNormalPDF
   put 1/(1*sqrt(2*pi)) into bit1
   --1/(sigma*sqrt(2*pi)) if it wasn't the *standard* normal PDF
   repeat with xhundred=-300 to 300 --600 points, more than enough
     put xhundred/100 into x
     put exp((-1/2)*((x)/1)^2) into bit2
     --exp((-1/2)*((x-mu)/sigma)^2) if it wasn't the *standard* normal PDF
     put xhundred &"," & round(-600*bit1*bit2) & return after PDFpoints
     --multiplied by -600 to avoid loss of data due to
     --the rounding (needed to make valid points)
     --and to turn the curve up the right way
   end repeat
   return PDFpoints
end StandardNormalPDF

The whole thing runs fast enough that you could make it refresh as 
the scrollbar values are changed:

on scrollbarDrag
   send mouseUp to btn "Plot Dist"
end scrollbarDrag

Hope that helps.

At 11:10 PM -0500 22/11/04, Ruben Silenas wrote:

>I would like to draw a normal curve based on some normal stats 
>provided by a user.
>
>One method I have thought of is adapting the start and end values on 
>a slider to a value (say +/- 3 sigma) and then the thumbstick to the 
>mean...that would give me the values on a pre-drawn curve...
>
>But can I actively dra a new curve every time normal stats are 
>entered (mean and std dev)?
>
>Thanks in advance.
>
>Ruben

-- 
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: michaell at unimelb.edu.au
**


More information about the use-livecode mailing list