Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Algorithm for Generating Percentage Amounts

  1. Jan 28, 2014 #1
    Hey guys,

    Not totally sure this thread belongs in this section, feel free to move.

    I'm trying to formulate an algorithm for an unusual problem.

    - Generate a pie chart with X number of wedges.
    - Each wedge is X percentage bigger then the one before it.
    - Percentage amounts of all wedges must add up to 100 (thereby completing the pie chart)

    So for example, in Excel I can create a pie chart with 5 wedges, and each wedge is 20% bigger then the previous one. It gives me these numbers (rounded).

    Wedge 1: 13.43797%
    Wedge 2: 16.125564%
    Wedge 3: 19.3506768%
    Wedge 4: 23.22081216%
    Wedge 5: 27.86497459%

    But I got that result by trial and error of Wedge 1's value until the final output of the pie chart hit 100%. How do I calculate Wedge 1's value simply based off the number of wedges in the pie, and the percentage amounts from one wedge to the next?

    I appreciate any help you guys can provide =]
     
  2. jcsd
  3. Jan 29, 2014 #2

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

  4. Jan 29, 2014 #3
    Okay cool, except a geometric series doesn't have to add up to a maximum amount, in this case 100% =/
     
  5. Jan 29, 2014 #4

    Office_Shredder

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    That's where doing math comes in. If your starting wedge has a%, then you want
    a + 1.2a + (1.2)2a + 1.23a + 1.24a = 100

    Notice that 1.2 a is 20% larger than a, and 1.22a is 20% larger than 1.2a, etc. Now all you have to do is solve for a.
     
  6. Jan 29, 2014 #5

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    If you don't like algebra, suppose the first wedge is size 1.
    You then have 5 wedges with sizes 1, 1.2, 1.44, 1.728, 2.0736 which add up to 7.4416
    So you need to scale up the sizes by 100 / 7.4416 = 13.43797 - which is what you got by trial and error.
     
  7. Jan 29, 2014 #6
    Thanks guys, you rock =]
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Algorithm for Generating Percentage Amounts
  1. Musical algorithm (Replies: 14)

  2. Eigenvalue Algorithm (Replies: 0)

  3. Householder algorithm (Replies: 13)

Loading...