+ Reply to Thread
Results 1 to 9 of 9

Need Help Running All Combinations of a Set Number of Values through 4 equations

  1. #1
    Registered User
    Join Date
    10-25-2018
    Location
    Fallbrook, CA
    MS-Off Ver
    2007
    Posts
    5

    Need Help Running All Combinations of a Set Number of Values through 4 equations

    I have 4 different equations in 4 separate cells. I am trying to test all possible value combinations from a set number to see which combination results in the smallest sum of results.

    This needs to be done with combinations not permutations as order does not matter

    For example...

    Say I have 100 available and 4 equations as follows:

    Equation 1) 2x + 5 Placed in cell A1
    Equation 2) 9x^3-3x+2 Placed in cell B1
    Equation 3) 3x^2-8 Placed in cell C1
    Equation 4) x^4+2x Placed in cell D1

    I want to run Equation 1 with x=100, Equation 2 with x=0, Equation 3 with x=0 and Equation 4 with x=0
    Next, Equation 1 with x=99, Equation 2 with x=1, Equation 3 with x=0 and Equation 4 with x=0
    Continuing with all possible combinations until I have Equation 1 with x=0, Equation 2 with x=0, Equation 3 with x=0 and Equation 4 with x=100.

    This example has 176,851 combinations

    I need to compare the sum of the results of the four equations for all iterations, and determine which iteration resulted in the smallest sum.

    Is this even possible? Thank you for any help provided.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    This needs to be done with combinations not permutations as order does not matter ...

    I want to run Equation 1 with x=100, Equation 2 with x=0, Equation 3 with x=0 and Equation 4 with x=0
    Next, Equation 1 with x=99, Equation 2 with x=1, Equation 3 with x=0 and Equation 4 with x=0
    Continuing with all possible combinations until I have Equation 1 with x=0, Equation 2 with x=0, Equation 3 with x=0 and Equation 4 with x=100.
    It appears that order does matter; otherwise {100,0,0,0} would be the same as {0,0,0,100}, no?
    Last edited by shg; 10-25-2018 at 12:11 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    I reckon if you consider it as a stars and bars problem, it is unordered samples with replacement:

    =combin(101+3-1,3) = 176,851

  4. #4
    Registered User
    Join Date
    10-25-2018
    Location
    Fallbrook, CA
    MS-Off Ver
    2007
    Posts
    5

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    Hello shg, Thank you for your reply.

    I am frequently confused by the difference between combinations and permutations, but I believe in this case, it is combinations.

    If we reduced the question to say, 4 into 3 equations, the results would be as follows:

    {4,0,0} -1
    {3,1,0} -2
    {3,0,1} -3
    {2,2,0} -4
    {2,1,1} -5
    {2,0,2} -6
    {1,3,0} -7
    {1,2,1} -8
    {1,1,2} -9
    {1,0,3} -10
    {0,4,0} -11
    {0,3,1} -12
    {0,2,2} -13
    {0,1,3} -14
    {0,0,4} -15

    identical items into distinct bins... n+r-1/r-1... 4+3-1/3-1... Gives 6 choose 2

    6!/2!(6-2)! = 6!/2!4! = 720/48 = 15

    I believe that should be the same logic for 100 identical items into 4 distinct bins, which results in the 176,851 combinations.

    Does that not seem correct?

  5. #5
    Registered User
    Join Date
    10-25-2018
    Location
    Fallbrook, CA
    MS-Off Ver
    2007
    Posts
    5

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    Yes, my thoughts exactly

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    This will list the values in A2:Dwhatever.

    Please Login or Register  to view this content.
    Adding the formula and sorting by sum,

    A
    B
    C
    D
    E
    F
    1
    x
    y
    z
    w
    Result
    2
    100
    0
    0
    0
    199
    E2: =(2*A2 + 5) + (9 * B2^3 - 3*B2 + 2) + (3 * C2^2 - 8) + (D2^4 + 2 * D2)
    3
    99
    0
    0
    1
    200
    4
    99
    0
    1
    0
    200
    5
    98
    0
    1
    1
    201
    6
    99
    1
    0
    0
    203
    7
    98
    1
    0
    1
    204
    8
    98
    1
    1
    0
    204
    9
    97
    1
    1
    1
    205
    10
    98
    0
    2
    0
    207
    176846
    0
    1
    1
    98
    92,237,020
    176847
    0
    0
    2
    98
    92,237,023
    176848
    0
    2
    0
    98
    92,237,077
    176849
    1
    0
    0
    99
    96,059,800
    176850
    0
    0
    1
    99
    96,059,801
    176851
    0
    1
    0
    99
    96,059,804
    176852
    0
    0
    0
    100
    100,000,199

  7. #7
    Registered User
    Join Date
    10-25-2018
    Location
    Fallbrook, CA
    MS-Off Ver
    2007
    Posts
    5

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    shg, I am in your debt. That was exactly what I needed!

    Thank you so much for the time you took to whip this piece of magic up.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    You're welcome.

  9. #9
    Registered User
    Join Date
    10-25-2018
    Location
    Fallbrook, CA
    MS-Off Ver
    2007
    Posts
    5

    Re: Need Help Running All Combinations of a Set Number of Values through 4 equations

    I'm sorry, can you tell me what I would need to do to adjust this code to work for 3 columns and 2 columns as well?

    Apologies and thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Can you use cell values in equations? (insert - equation)
    By tahi.laci in forum Excel General
    Replies: 5
    Last Post: 05-15-2016, 02:00 AM
  2. [SOLVED] Geting highest number value from list with values which are text/number combinations
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-25-2016, 10:48 AM
  3. Replies: 5
    Last Post: 11-24-2014, 02:28 PM
  4. Replies: 1
    Last Post: 06-04-2014, 05:40 PM
  5. Simulation running all combinations
    By redronin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2013, 12:43 AM
  6. Replies: 3
    Last Post: 11-24-2010, 03:43 AM
  7. Equations with numbers and letter values
    By Corey in forum Excel General
    Replies: 1
    Last Post: 02-15-2005, 10:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1