2

I have a list in maxima like:

x:[1,3,7,98,211,3,2.44,23]

I need to find the maximun value of the list and on which position(s) the maximum value is situated.

The only thing that has occurred to me is to rewrite the list as a sequence and apply the 'max' command

max(first(x),second(x),...,last(x))

But it is not efficient, and I don't know get the index of the maximum value.

Can anybody help me?

Adam
  • 1,254
  • 12
  • 25
Marco R
  • 45
  • 1
  • 7

1 Answers1

5

lmax returns the maximum value of a list. Given x is a list, then

 lmax(x)

returns the maximum value of x.

Getting the index of the maximum value is a little more involved. The most relevant built-in function (unless I'm forgetting something -- could happen) is sublist_indices, which returns the indices of the elements which satisfy a predicate. The predicate is a function of one variable which returns true or false. To continue the example, `

sublist_indices(x, lambda([x1], x1 = lmax(x)))

returns one or more indices at which the elements of x take on the maximum value.

Jan Rothkegel
  • 737
  • 3
  • 21
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48