0
$\begingroup$

I found this post which applying a function to a list of functions and arguments. I thought I could change my code with a table to something more elegant. I am not wedded to the Inner so if anyone has a different idea, I'm open to it.

My original Table code is

Table[ArgMin[{f[[i]][z], {z} \[Element] 
 Interval[{Min[lim[[i]]], Max[lim[[i]]]}]}, z], {i, Length[f]}];

and the Inner code I tried was

Inner[ArgMin[#1[z], {z} \[Element] Interval[{Min[#2], Max[#2]}], z] &, f, lim, List, 1]

However, The new code puts out the equivalent of Transpose[lim].

An example input is

f = {Cos[#] &, Abs[#] &};
lim = {{0, \[Pi]}, {-1, 1}};

Edit:

Is there someway to get the same output as with the table, without using Table?

$\endgroup$
  • $\begingroup$ What is your question here exactly? $\endgroup$ – MarcoB Jul 10 '15 at 21:15
1
$\begingroup$

Inner doesn't work here because f and lim have different tensor shape, so Inner does generalized matrix multiplication rather than vector inner product.

The most straightforward method is probably using MapThread:

MapThread[ArgMin[{#1@z, {z} ∈ Interval@MinMax@#2}, z] &, {f, lim}]

(MinMax is a version 10.1 shorthand function.)

If you want to get Inner to work you can feed it the one-dimensional list of intervals rather than the two-dimensional list of endpoints:

Inner[ArgMin[#1[z], {z} ∈ #2, z] &, f, Interval /@ MinMax /@ lim, List]

The MapThread method can also be converted into a method using Transpose and Apply:

ArgMin[{#1@z, {z} ∈ Interval@MinMax@#2}, z] & @@@ Transpose@{f, lim}
$\endgroup$
  • $\begingroup$ The only odd thing is I have v10 but don't have MinMax besides that it works. $\endgroup$ – user1543042 Jul 10 '15 at 22:26
  • $\begingroup$ Oh, sorry, I guess it's v10.1. $\endgroup$ – Simon Rochester Jul 10 '15 at 22:28

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.