1
$\begingroup$

Suppose I have a list:

$lst= \{\{k_1, g_1\},\{k_2,g_2\},...,\{k_{max},g_{max}\},...,\{k_n,g_n\}\}$

Here $\{k_{max},g_{max}\}$ is a special element, in which $g_{max}$ is the maximum of all $g_{i}$

I can use Ordering to find the ordering that sorts the list with respect to the second element of it sublist:

lst[[Ordering[lst[[All, 2]]]]];

then pick out the list having $g_{max}$ with lst[[Ordering[lst[[All, 2]]]]][[-1]].

My question is how to pick out a more special list $\{k^\ast, g^\ast \}$, for example, having $g^\ast$ such that ${\rm{Abs}}[g^\ast] = 50 g_{max}$? In a real case, the equal sign may not hold exactly. In this case, I still want to find the list, which fits the relation best. It means that to find a list such that ${\rm{Abs}}[g^\ast]$ is most close to $50 g_{max}$ Here is a sample list for your experiment. Thank you very much.

$\endgroup$
0
$\begingroup$

You can try Nearest:

gmax = lst[[Ordering[lst[[All, 2]], -1]]][[1, -1]];

lst[[Nearest[Abs[lst[[All, 2]]] -> "Index", 50 gmax]]]

{{3.75, -0.827334}}

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.