Re: Capture values that Min(imize)
- To: mathgroup at smc.vnet.net
- Subject: [mg117829] Re: Capture values that Min(imize)
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Fri, 1 Apr 2011 02:32:50 -0500 (EST)
There's also this: cList[[Ordering[#, 1]]] & /@ Outer[Abs@err[##] &, Range[15, 30], cList] Transpose@{Range[15, 30], %} {{7.9}, {6.9}, {6.9}, {6.9}, {6.9}, {3.2}, {3.2}, {3.2}, {3.2}, \ {3.2}, {3.2}, {2.2}, {2.2}, {2.2}, {2.2}, {2.2}} {{15, {7.9}}, {16, {6.9}}, {17, {6.9}}, {18, {6.9}}, {19, {6.9}}, \ {20, {3.2}}, {21, {3.2}}, {22, {3.2}}, {23, {3.2}}, {24, {3.2}}, {25, \ {3.2}}, {26, {2.2}}, {27, {2.2}}, {28, {2.2}}, {29, {2.2}}, {30, \ {2.2}}} Bobby On Thu, 31 Mar 2011 03:58:51 -0500, Bob Hanlon <hanlonr at cox.net> wrote: > Since Sqrt is Listable this can be writen slightly more compactly. > > L = 14.95; cList = {2.2, 3.2, 6.9, 7.9}; > > err[f_, c_] := (f - 1/(2 Pi Sqrt[L c*10^-6]))/f > > Table[{f, cList[[Ordering[Abs[err[f, cList]], 1]]]}, {f, 15, 30}] == > Table[{f, cList[[Ordering[Abs[err[f, #]] & /@ cList, 1]]]}, {f, > Range[15, 30]}] > > True > > > Bob Hanlon > > ---- Heike Gramberg <heike.gramberg at gmail.com> wrote: > > ============= > I don't know if this is slicker, but what about > > Table[{f, cList[[Ordering[Abs[err[f, #]] & /@ cList, 1]]]}, {f, > Range[15, 30]}] > > Heike > > On 29 Mar 2011, at 12:50, 1.156 wrote: > >> Hi, I finally found a way to get a list of c values from cList which >> minimize the err at each freq, f as below: >> >> L=14.95;cList={2.2, 3.2, 6.9, 7.9}; >> >> err[f_,c_]:=(f-1/(2Pi Sqrt[L c*10^-6]))/f >> >> Table[{f,Select[cList,(Abs[err[f,#]]==Min[Abs[err[f,#]]&/@cList])&]},{f,15,30}] >> >> This works but looks horrible. Surely there's a slicker way to Minimize >> on a list and retain the value that achieved the minimum. I did try to >> stuff Reap/Sow in various places but everything I did threw error >> messages. Thanks for any pointers, Rob >> > > -- DrMajorBob at yahoo.com