在Maxima列表中找到最大值和索引? [英] Find maximum value and index in a Maxima list?

查看:534
本文介绍了在Maxima列表中找到最大值和索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最大值列表,例如:

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.

我发生的唯一一件事就是将列表重写为序列并应用'max'命令

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.

有人可以帮助我吗?

推荐答案

lmax返回列表的最大值.给定x是一个列表,然后

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

 lmax(x)

返回x的最大值.

获取最大值的索引要花些时间.最相关的内置函数(除非我忘记了可能发生的事情)是sublist_indices,它返回满足谓词的元素的索引.谓词是一个返回true或false的变量的函数.要继续该示例,`

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)))

返回一个或多个索引,x的元素将在该索引处达到最大值.

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

这篇关于在Maxima列表中找到最大值和索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆