Find maximum value and index in a Maxima list?

余生长醉 提交于 2019-12-08 04:00:42

问题


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?


回答1:


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

 lmax(x)

returns its minimum value.

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.



来源:https://stackoverflow.com/questions/43714455/find-maximum-value-and-index-in-a-maxima-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!