How do you compare negative numbers with positive numbers?
Mark Schonewille
m.schonewille at economy-x-talk.com
Sun Dec 12 15:34:40 EST 2010
Hi Charles,
It's been a long time for me, but if I remember well you want either the first differences or the standard deviation.
function mean theNumbers
return sum(theNumbers)/number of items of theNumbers
end mean
function firstDifferences theNumbers
put mean(theNumbers) into myMean
repeat for each line myLine in theNumbers
add abs(myLine-myMean) to myCumulDiff
end repeat
return myCumulDiff/number of items of theNumbers
end firstDifferences
function standardDeviation
put mean(theNumbers) into myMean
repeat for each line myLine in theNumbers
add( abs(myLine-myMean))^2 to myCumulDiff
end repeat
return sqrt(myCumulDiff/number of items of theNumbers)
end standardDeviation
on mouseUp
put "-3.5,2.23" into myRow
put mean(myRow) into myMean
put firstDifferences(myRow) into myMeanDifferences
put standardDeviation(myRow) into myStandardDeviation
-- do with the variable whatever you want
end mouseUp
(Untested, please mind typos and other mistakes)
--
Best regards,
Mark Schonewille
Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553
How to receive a free Color Converter license http://qurl.tk/kv (read the conditions)
On 12 dec 2010, at 21:20, Charles Szasz wrote:
> I am computing an average of a series of numbers and then comparing each number with the average, which yields a deviation. Of course, there are instances where a negative deviation will occur when it is below the average.
>
> Here is my problem. I need to be able to compare a negative number with a positive number and then give the user feedback about whether the negative number is greater in magnitude than the positive number. For example, comparing -3.5 with 2.23. How do you do this?
>
> Charles Szasz
> cszasz at mac.com
More information about the use-livecode
mailing list