I want to edit @MarcoB answers (because the code he gave doesn't answer the question appropriately)->(the function that need to be optimised is not implemented as asked)
But it seems like I am having some trouble (again) with his code. I made some modification (since I want it to be clear for others who might need something like this) and it look like this
resistors =
Flatten@Outer[Times,
PowerRange[1, 10000], {100, 110, 120, 130, 150, 160, 180, 200,
220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680,
750, 820, 910}];
capacitors =
Flatten@Outer[Times,
PowerRange[1/10, 100000000], {10, 15, 22, 33, 47, 68}];
combinations = {#1 #2 #3^2, 2 #2 #3} -> {#1, #2, #3} & @@@
Tuples[{capacitors, capacitors, resistors}];
{#1, #2, #3} -> {#1 #2 #3^2, 2 #2 #3} & @@@
DeleteDuplicates[Nearest[combinations, {384400, 1240}, {5, 1500}]]
this is all in one cell (as per @MarcoB suggestion -> so I don't get error with the memory, if I remembered right) but it doesn't give me any answer.
Even though I specifically chose {384400, 1240} which is the result I've got from this (same ?) code:
resistors =
Flatten@Outer[Times,
PowerRange[1, 10000], {100, 110, 120, 130, 150, 160, 180, 200,
220, 240, 270, 300, 330, 360, 390, 430, 470, 510, 560, 620, 680,
750, 820, 910}];
capacitors =
Flatten@Outer[Times,
PowerRange[1/10, 100000000], {10, 15, 22, 33, 47, 68}];
combinations = {#1 #2 #3^2, 2 #2 #3} -> {#1, #2, #3} & @@@
Tuples[{capacitors, capacitors, resistors}];
combinations[[20]]
(*Out:
{384400, 1240} -> {1, 1, 620}
*)
Notice anything different ?
What am I doing wrong ?
--------------------------------------------------------------------------------
Original Question :
I am in the early process of optimizing and simplifying my work load, but I can't seem to find the function I need to do the job.
Here is a description of my problem (as I currently have it set up in Excel):
I have a list of resistors and a list of capacitors (all sorted, in separate columns); I also have two values; $a_{target}$ and $b_{target}$ which are real numbers.
I want to obtain a few possible combinations of two capacitors and a resistor resulting in actual $a$ and $b$ values (calculated from the formula below) that best approximate my desired values.
$$ f_{(C_1,C_2,R)} = \begin{cases} a=C_1C_2R^2\\ b=2 RC_2 \end{cases} $$
- It is likely that I won't be able to get to the exact prescribed $a_{target}$ and $b_{target}$, but I want to get as close to it as possible with the material I've got.
- The output of the program I am trying to design are the values of capacitors and resistor used to get to this optimum value.
I am looking to optimize some quantity, but I would like to get more than one answer, not only one as with e.g. Minimize
or FindMinimum
, as those will only give back a single minimum.
I also tried to use FindFit
, but I honestly don't think it is made for that either since I am not trying to fit a function to some data (or am I?).
I'm already able to get the data from the excel spread sheet.
Any help on this?
Thanks
Nearest
would fail. Can you check that you actually have numbers in your list? For instance tryNumberQ /@ resistors
andNumberQ /@ capacitors
. If any of the results returnFalse
, then there's a problem (perhaps in the way those numbers were stored in Excel?) $\endgroup$ – MarcoB Jan 28 '16 at 19:32{#1, #2, #3} -> {#1 #2 #3^2, 2 #3 #2} & @@@ DeleteDuplicates[ Nearest[combinations, {147000, 1300}, {5, 1500}] ]
it didn't return something good (if i may say so) $\endgroup$ – Sebastien Comtois Jan 28 '16 at 19:37