Algorithm for Generating Percentage Amounts

  • Thread starter Thread starter natedgreat3
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary
An algorithm is needed to generate a pie chart with wedges that increase in size by a fixed percentage while ensuring the total equals 100%. The sizes of the wedges form a geometric series, where each subsequent wedge is a specific percentage larger than the previous one. To find the initial wedge size, the equation a + 1.2a + (1.2)²a + ... must be solved to equal 100%. By setting the first wedge to a value of 1, the total can be scaled to fit the 100% requirement. This approach simplifies the calculation and eliminates the need for trial and error.
natedgreat3
Messages
3
Reaction score
0
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 =]
 
Physics news on Phys.org
Okay cool, except a geometric series doesn't have to add up to a maximum amount, in this case 100% =/
 
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.
 
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.
 
Thanks guys, you rock =]
 
Thread 'How to define a vector field?'
Hello! In one book I saw that function ##V## of 3 variables ##V_x, V_y, V_z## (vector field in 3D) can be decomposed in a Taylor series without higher-order terms (partial derivative of second power and higher) at point ##(0,0,0)## such way: I think so: higher-order terms can be neglected because partial derivative of second power and higher are equal to 0. Is this true? And how to define vector field correctly for this case? (In the book I found nothing and my attempt was wrong...

Similar threads

  • · Replies 56 ·
2
Replies
56
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 61 ·
3
Replies
61
Views
11K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 48 ·
2
Replies
48
Views
12K