Algorithm for Average of N numbers PowerPoint PPT Presentation

presentation player overlay
About This Presentation
Transcript and Presenter's Notes

Title: Algorithm for Average of N numbers


1
Algorithm for Average of N numbers
  • GIVENS
  • X (An array of values)
  • N (Length of array X)
  • RESULTS
  • Average (The average of the values in
    the array X)
  • INTERMEDIATES
  • Sum (Sum of array values)
  • Index (Current position in array)
  • HEADER
  • Average ? FindAverage(X, N)

Sum ? 0Index ? 0
Index lt N ?
true
Sum ? Sum XIndex Index ? Index 1
false
Average ? Sum / N
2
Standard Deviation Algorithm (1)
  • GIVENSX (an array containing a collection of
    real numbers)N (the length of the array)
  • RESULTSStDev (the standard deviation of the
    values in the array)
  • INTERMEDIATESSum (accumulates the sum of the
    array)SumIndex (used as array index to find sum
    of array)Average (average of array
    elements)DiffSqSum (accumulates the sum of the
    squares of the differences)DiffSqIndex (used
    as array index to find sum of squares of
    differences)
  • HEADERStDev ? StandardDeviation(X, N)

3
Standard Deviation Algorithm (2)
Sum ? 0SumIndex ? 0
true
SumIndex lt N ?
false
Sum ? Sum XSumIndex SumIndex ? SumIndex 1
Average ? Sum / N DiffSqSum ? 0 DiffSqIndex ? 0
true
DiffSqIndex lt N ?
false
DiffSqSum ? DiffSqSum (XDiffSqIndex
Average) ? (XDiffSqIndex Average)
DiffSqIndex ? DiffSqIndex 1
StDev ? Sqrt( DiffSqSum / (N 1) )
4
Algorithm for Distance of Thrown Ball (1)
  • GIVENS
  • V (Initial velocity of the ball, in metres /
    second)
  • RESULTS
  • Range (An array of for how far the ball will
    travel for various angles. The values will be
    for 0 degrees up to 90 degrees, in increments
    of 10 degrees. Result is in metres)
  • INTERMEDIATES
  • G (Constant Acceleration due to gravity
    9.8 m/s2)
  • DegToRad (Constant Degrees to radians
    conversion ? / 180)
  • Theta (Current horizontal angle, in degrees)
  • ThetaRad (Current horizontal angle, in radians)
  • HEADER
  • Range ? FindDistance(V)

5
Algorithm for Distance of Thrown Ball (2)
Theta ? 0G ? 9.8DegToRad ? ? / 180Range ?
MakeNewArray(10)
Theta 90 ?
true
false
ThetaRad ? Theta DegToRad RangeTheta/10 ? 2
V V sin(ThetaRad) cos(ThetaRad) / GTheta
? Theta 10
Write a Comment
User Comments (0)
About PowerShow.com