18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>SIMSCRIPT</strong> <strong>II.5</strong> <strong>Programming</strong> <strong>Language</strong><br />

Program 1-4.<br />

_______________________________________________________________________________<br />

''Program to Compute the Maximum, Minimum and Average<br />

'' of a Set of Numbers<br />

read NUMBER<br />

'' NUMBER OF DATA OBSERVATIONS<br />

if NUMBER < 1<br />

go to FINISH<br />

otherwise<br />

read VALUE<br />

let MAX = VALUE<br />

let MIN = VALUE<br />

let SUM = VALUE<br />

for COUNT = 2 to NUMBER by 1<br />

do<br />

read VALUE '' DATA VALUE<br />

add VALUE to SUM<br />

if VALUE > MAX<br />

let MAX = VALUE<br />

always<br />

if VALUE < MIN<br />

let MIN = VALUE<br />

always<br />

loop<br />

print 3 lines with SUM / NUMBER, MAX, MIN thus<br />

THE AVERAGE VALUE IS ***.****<br />

THE MAXIMUM VALUE IS ***.****<br />

THE MINIMUM VALUE IS ***.****<br />

'FINISH'<br />

stop<br />

end<br />

_______________________________________________________________________________<br />

1.22.4 Computing Square Roots<br />

The square root of a number is required in many calculations. In fact, in two of the preceding examples,<br />

square roots were obtained using exponentiation. The following is an implementation of<br />

Newton's method to approximate square roots.<br />

The example demonstrates the use of a logical control phrase to control an iterative computation.<br />

The logical condition specifies a relative precision of the estimated square root as a stopping<br />

criterion. Note that the first statement within the loop calculates a new estimate for the square root,<br />

using the last estimated value. This technique is fundamental to such iterative procedures. Note<br />

also the explanatory comment appearing beside the statement to invert the sign of DELTA, should it<br />

be negative.<br />

34

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!