+ Reply to Thread
Results 1 to 8 of 8

HELP! Problem with combinations

  1. #1
    Registered User
    Join Date
    08-22-2005
    Posts
    8

    HELP! Problem with combinations

    Hi all,

    i have a problem that goes like this;

    Q = Q1 + Q2 + Q3, where Q is constant

    Q1 is between 1 and 2. Q2 is between 1.5 and 5. Q3 is between 2 and 4. All values at Intervals of 0.1 (ie. Q1 = 1, 1.1, 1.2, ... 2)

    i need to generate all combinations of values of Q1, Q2 and Q3 such that the above relationship is satisfied.

    Are that any kind souls that can help me with this?
    Thanks in advance !!!

  2. #2
    Tom Ogilvy
    Guest

    Re: HELP! Problem with combinations

    Sub AAA()
    Dim i As Double, j As Double, k As Double
    Dim l As Long
    i = 1
    j = 1.5
    k = 2
    l = 2
    Do While Application.Round(i, 1) <= 2
    Do While Application.Round(j, 1) <= 5
    Do While Application.Round(k, 1) <= 4
    Cells(l, 1) = i
    Cells(l, 2) = j
    Cells(l, 3) = k
    Cells(l, 4) = i + j + k
    Debug.Print l, i, j, k, i + j + k
    k = k + 0.1
    l = l + 1
    Loop
    k = 2
    j = j + 0.1
    Loop
    j = 1.5
    i = i + 0.1
    Loop

    End Sub

    --
    Regards,
    Tom Ogilvy

    "highjumper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi all,
    >
    > i have a problem that goes like this;
    >
    > Q = Q1 + Q2 + Q3, where Q is constant
    >
    > Q1 is between 1 and 2. Q2 is between 1.5 and 5. Q3 is between 2 and 4.
    > All values at Intervals of 0.1 (ie. Q1 = 1, 1.1, 1.2, ... 2)
    >
    > i need to generate all combinations of values of Q1, Q2 and Q3 such
    > that the above relationship is satisfied.
    >
    > Are that any kind souls that can help me with this?
    > Thanks in advance !!!
    >
    >
    >
    > --
    > highjumper
    > ------------------------------------------------------------------------
    > highjumper's Profile:

    http://www.excelforum.com/member.php...o&userid=26516
    > View this thread: http://www.excelforum.com/showthread...hreadid=397849
    >




  3. #3
    Registered User
    Join Date
    08-22-2005
    Posts
    8

    Thumbs up

    Thanks a million man!

  4. #4
    Registered User
    Join Date
    08-22-2005
    Posts
    8
    Hi,

    I think you misunderstood the question ...

    Q is supposed to be a constant - meaning if i set Q as 6, i am generating all combinations of values of Q1, Q2, Q3 that satisfy 6 = Q1 + Q2 + Q3.

    Many thanks for your effort! I really appreciate it!


    Quote Originally Posted by Tom Ogilvy
    Sub AAA()
    Dim i As Double, j As Double, k As Double
    Dim l As Long
    i = 1
    j = 1.5
    k = 2
    l = 2
    Do While Application.Round(i, 1) <= 2
    Do While Application.Round(j, 1) <= 5
    Do While Application.Round(k, 1) <= 4
    Cells(l, 1) = i
    Cells(l, 2) = j
    Cells(l, 3) = k
    Cells(l, 4) = i + j + k
    Debug.Print l, i, j, k, i + j + k
    k = k + 0.1
    l = l + 1
    Loop
    k = 2
    j = j + 0.1
    Loop
    j = 1.5
    i = i + 0.1
    Loop

    End Sub

    --
    Regards,
    Tom Ogilvy

    "highjumper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi all,
    >
    > i have a problem that goes like this;
    >
    > Q = Q1 + Q2 + Q3, where Q is constant
    >
    > Q1 is between 1 and 2. Q2 is between 1.5 and 5. Q3 is between 2 and 4.
    > All values at Intervals of 0.1 (ie. Q1 = 1, 1.1, 1.2, ... 2)
    >
    > i need to generate all combinations of values of Q1, Q2 and Q3 such
    > that the above relationship is satisfied.
    >
    > Are that any kind souls that can help me with this?
    > Thanks in advance !!!
    >
    >
    >
    > --
    > highjumper
    > ------------------------------------------------------------------------
    > highjumper's Profile:

    http://www.excelforum.com/member.php...o&userid=26516
    > View this thread: http://www.excelforum.com/showthread...hreadid=397849
    >

  5. #5
    Registered User
    Join Date
    08-22-2005
    Posts
    8
    Anybody? Please help ...

  6. #6
    Tom Ogilvy
    Guest

    Re: HELP! Problem with combinations

    Sub AAA()
    Dim i As Double, j As Double, k As Double
    Dim l As Long, Q As Double
    Q = 6
    i = 1
    j = 1.5
    k = 2
    l = 2
    Do While Application.Round(i, 1) <= 2
    Do While Application.Round(j, 1) <= 5
    Do While Application.Round(k, 1) <= 4
    If Application.Round(i + j + k, 1) = Q Then
    Cells(l, 1) = i
    Cells(l, 2) = j
    Cells(l, 3) = k
    Cells(l, 4) = i + j + k
    l = l + 1
    End If
    k = k + 0.1
    Loop
    k = 2
    j = j + 0.1
    Loop
    j = 1.5
    i = i + 0.1
    Loop

    End Sub

    --
    Regards,
    Tom Ogilvy


    "highjumper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Anybody? Please help ...
    >
    >
    > --
    > highjumper
    > ------------------------------------------------------------------------
    > highjumper's Profile:

    http://www.excelforum.com/member.php...o&userid=26516
    > View this thread: http://www.excelforum.com/showthread...hreadid=397849
    >




  7. #7
    Registered User
    Join Date
    08-22-2005
    Posts
    8
    Hi,

    So sorry for not making it clear enough.

    1) My actual code will have all the way til Q10. Hence the time taken for running the code will be too long. Thus, it will be ideal if only the relevant combinations (those that satisfy the equation) are generated, instead of ignoring those irrelevant ones after generation.

    2) This code is actually not meant to write to worksheet. It forms part of the code for a larger code that will make further calculations and stuff.

    It is a program to churn out an ideal solution for an engineering problem as part of my final year project in my undergraduate studies.

    Gazillion thanks for your attention and help!


    Warmest Regards,
    Kenneth

    Quote Originally Posted by Tom Ogilvy
    Sub AAA()
    Dim i As Double, j As Double, k As Double
    Dim l As Long, Q As Double
    Q = 6
    i = 1
    j = 1.5
    k = 2
    l = 2
    Do While Application.Round(i, 1) <= 2
    Do While Application.Round(j, 1) <= 5
    Do While Application.Round(k, 1) <= 4
    If Application.Round(i + j + k, 1) = Q Then
    Cells(l, 1) = i
    Cells(l, 2) = j
    Cells(l, 3) = k
    Cells(l, 4) = i + j + k
    l = l + 1
    End If
    k = k + 0.1
    Loop
    k = 2
    j = j + 0.1
    Loop
    j = 1.5
    i = i + 0.1
    Loop

    End Sub

    --
    Regards,
    Tom Ogilvy


    "highjumper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Anybody? Please help ...
    >
    >
    > --
    > highjumper
    > ------------------------------------------------------------------------
    > highjumper's Profile:

    http://www.excelforum.com/member.php...o&userid=26516
    > View this thread: http://www.excelforum.com/showthread...hreadid=397849
    >

  8. #8
    Tom Ogilvy
    Guest

    Re: HELP! Problem with combinations

    the answers don't have to be written to the worksheet. That was for
    demonstration purposes. I am not aware of an algorithm that will generate a
    complete list of just the combinations of elements of 10 series of numbers
    that add to your number (without enumerating all possible combinations of
    course).

    Perhaps going to a math-sci newsgroup might get help on this.

    --
    Regards,
    Tom Ogilvy


    "highjumper" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi,
    >
    > So sorry for not making it clear enough.
    >
    > 1) My actual code will have all the way til Q10. Hence the time taken
    > for running the code will be too long. Thus, it will be ideal if only
    > the relevant combinations (those that satisfy the equation) are
    > generated, instead of ignoring those irrelevant ones after generation.
    >
    > 2) This code is actually not meant to write to worksheet. It forms part
    > of the code for a larger code that will make further calculations and
    > stuff.
    >
    > It is a program to churn out an ideal solution for an engineering
    > problem as part of my final year project in my undergraduate studies.
    >
    > Gazillion thanks for your attention and help!
    >
    >
    > Warmest Regards,
    > Kenneth
    >
    > Tom Ogilvy Wrote:
    > > Sub AAA()
    > > Dim i As Double, j As Double, k As Double
    > > Dim l As Long, Q As Double
    > > Q = 6
    > > i = 1
    > > j = 1.5
    > > k = 2
    > > l = 2
    > > Do While Application.Round(i, 1) <= 2
    > > Do While Application.Round(j, 1) <= 5
    > > Do While Application.Round(k, 1) <= 4
    > > If Application.Round(i + j + k, 1) = Q Then
    > > Cells(l, 1) = i
    > > Cells(l, 2) = j
    > > Cells(l, 3) = k
    > > Cells(l, 4) = i + j + k
    > > l = l + 1
    > > End If
    > > k = k + 0.1
    > > Loop
    > > k = 2
    > > j = j + 0.1
    > > Loop
    > > j = 1.5
    > > i = i + 0.1
    > > Loop
    > >
    > > End Sub
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "highjumper" <[email protected]>
    > > wrote
    > > in message
    > > news:[email protected]...
    > > >
    > > > Anybody? Please help ...
    > > >
    > > >
    > > > --
    > > > highjumper
    > > >

    > > ------------------------------------------------------------------------
    > > > highjumper's Profile:

    > > http://www.excelforum.com/member.php...o&userid=26516
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=397849
    > > >

    >
    >
    > --
    > highjumper
    > ------------------------------------------------------------------------
    > highjumper's Profile:

    http://www.excelforum.com/member.php...o&userid=26516
    > View this thread: http://www.excelforum.com/showthread...hreadid=397849
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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