(Sign in to Post a Comment)

Comment on: Math problem

Posted: 4 years 10 months 4 days 19 hours 54 minutes ago

Posted: 4 years 10 months 4 days 19 hours 54 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.

Comment on: Math problem

Posted: 4 years 10 months 4 days 19 hours 15 minutes ago

Posted: 4 years 10 months 4 days 19 hours 15 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.

Comment on: Math problem

Posted: 4 years 10 months 4 days 18 hours 5 minutes ago

Posted: 4 years 10 months 4 days 18 hours 5 minutes ago

Well it seems to work, when I play with numbers on a calculator. Now I have to wait until Monday when we have the control tables populated, so I can run the program and see what screwed up results get pushed out the back.