(newbie) Find Max Number In An Array



JRS: In article <e7r19d$31a$1@xxxxxxxxxxxxxxxxxxx>, dated Tue, 27 Jun
2006 13:29:00 remote, seen in news:comp.lang.pascal.delphi.misc,
Nektarios - Greece <eizo5@xxxxxxxxxxxx> posted :

Suppose you have a variable X as an input.
The program should calculate Y=2X+3 (for example) for X=X+1 up to
X=X+50 and then find the minimum Y among these 50 Y's (Y1,Y2,Y3,...Y50).

If that is a coursework problem, review your notes, read the books, ask
an adviser.


To find the minimum of a completely arbitrary function, it is necessary
to examine every point, comparing with the lowest so far found.

If there is known to be a single extremum in the range, with the
function monotonic on each side of it, then the method requiring fewest
function evaluations is based of Fibonacci numbers; it can be seen in
<URL:http://www.merlyn.demon.co.uk/js-demos.htm#FP>, coded in javascript
- there is a "Show Functions" button below.

If the function is known to vary smoothly in the region of the minimum,
then pick three points in the region (the ends and the middle), evaluate
Y for each, fit a parabola, and get a new estimate of the position of
the minimum. You can then repeat if necessary but beware of using
points too close together.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.


Quantcast