Midrange News for the IBM i Community

Posted by: neilrh
A/P
Jackson, MI
Math problem
has no ratings.
Published: 17 Aug 2012
Revised: 23 Jan 2013 - 2552 days ago
Last viewed on: 17 Jan 2020 (3643 views)

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

I'm having some math issues, around the concept of rectangles: lengths, widths and areas.

Now back at school we all learnt that Area = Length x Width.Ā But the problem I am facing is to calculate the change in length and width that an increase to the area would create.Ā Thus I have area (A) and I need to add P% scrap/waste to it, what is the new Length and Width?Ā I'm kind of thinking that log tables might enter into this, but it's been so long since I messed with log tables that I have no recollection of where to start.

Oh and to add a kink in the works, I'm not sure which solution I need:Ā

```Area = Width x Length
NewArea = Area + 10%

Option 1:
NewArea = (Width + Fixed) * (Length + Fixed)
Fixed = ??

Option 2:
NewArea = (Width + Perc%) * (Length + Perc%)
Perc = ??```

Ā

Sort Ascend | Descend Posted by: DaleB
Comment on: Math problem
Posted: 7 years 5 months 3 days 10 hours 41 minutes ago

It's just algebra...

You want the same amount of scrap in both directions? So ...
A = W * L
// NewArea is Area + Scrap%
NewA = A + S% = A * (1 + S/100) = A * (100 + S)/100
NewA = W * L * (100 + S)/100
// NewArea is still a rectangle
NewA = NewW * NewL
// If you want the same amount of scrap all around...
NewW = W + NewS% = W * (1 + NewS/100) = W * (100 + NewS)/100
NewL = L + NewS% = L * (1 + NewS/100) = L * (100 + NewS)/100
// So...
NewA = W * (100 + NewS)/100 * L * (100 + NewS)/100
NewA = W * L * (100 + NewS)/100*(100 + NewS)/100
NewA = W * L * (100 + NewS)*(100 + NewS)/(100*100)
// But the new area is the new area
W * L * (100 + S)/100 = W * L * (100 + NewS)*(100 + NewS)/(100*100)
// As long as W and L are not zero, we can divide
(100 + S)/100 = (100 + NewS)*(100 + NewS)/(100*100)
// Multiply both sides by 100*100
(100 + S)*100 = (100 + NewS)*(100 + NewS)
// Multiply it out
10000 + 100*S = 10000 + 200*NewS + NewS*NewS
0 = NewS*NewS + 200*NewS - 100*S
// This is just a quadratic equation in NewS
// aX**2 + bX + c = 0, so a = 1, b = 200, c = -100*S
// First calculate the discriminant, b**2-4*a*c
Disc = 200*200 - 4*1*(-100*S)
Disc = 40000 + 400*S
// As long as Disc is positive, you'll have real solutions
// Back to quadratic equation, X = (-b (+/-) sqrt(b**2-4ac))/2a,
// And we already have the b**2-4ac
NewS1 = (-200 + sqrt(Disc))/2
NewS2 = (-200 - sqrt(Disc))/2
// Simple obversation tells us NewS2 will be negative, so
NewScrap = (-200 + sqrt(Disc))/2

This is almost RPG syntax already. Square root can be either %SQRT(Disc) or Disc**0.5, your preference.

You could rework this math if you wanted to keep the Scrap in decimal form, e.g. 0.10 instead of 10 (percent), but it's probably easier to just divide the final answer by 100 if you need that.

The only requirement is that the discriminant must be greater than 0, which means the original Scrap percentage must be greater -100. Negative scrap doesn't make sense anyway, so that's not much of a limitation.

For original Scrap value of 10%, this works out to new length and widths having about 4.88 percent scrap. But that's the total length and width. If the original area is centered within the new area, this would mean 2.44% on all outside edges.

Ā Posted by: DaleB
Comment on: Math problem
Posted: 7 years 5 months 3 days 10 hours 2 minutes ago

OK - it wasn't that bad. If the original Scrap percentage (I'll call it Sp this time) is expressed as a decimal, it works out to

Disc Ā= 4 + 4*Sp
NewSp = (-2 + Disc**0.5)/2

Where NewSp is also expressed as a decimal. Disc is positive as longĀas Scrap percentage is >= -1 (i.e., -100%), so no danger there. As before, when Sp = 0.10, NewSp comes out to 0.0488.

Posted by: neilrh