Hi,
I'm doing some calculator specs for our developer and having a tough time documenting this sanely.
Basically I need to solve for a variable, where one side of the equation contains both the variable and a function dependent on that variable. And the function doesn't resolve into something nice that I can plunk into the equation.
Here's the basic idea. Net income is gross income minus taxes. I have net income, want to solve for gross. Taxes are the function based on gross (and are a funky calc).
So basic equation to be solved for gross income is:
Gross - Taxes(Gross) = Net
The taxes function look something like this:
First $10,000 of gross, taxes are 0.
From $10,000 to $90,000 of gross, taxes are 20% of that amount above 10K.
From 90,000 and above of gross, taxes are 40% of the amount above 90K.
Which leaves me with a bunch of IF statements dependent on gross to calculate the taxes. And IF statements don't leave me with some nice equation I can reverse engineer and plunk into the equation to solve for Gross. At least, I don't think so.
My head tells me just to do some sort of iterative calculation, targetting and testing numbers until I get the right gross number. But I have this nagging feeling like I've done a problem like this in years past and had a somewhat elegant solution.
Thanks in advance for any kicks in the general direction.
Tough spec question
Started by wheel, Sep 09 2008 04:25 PM
6 replies to this topic
#1
Posted 09 September 2008 - 04:25 PM
|
|
|
#2
Posted 09 September 2008 - 04:50 PM
In PHP there is something known as a switch that eliminates what I like to call "if complexes". I used to use big blocks of if statements until John taught me how to use the switch.
An example is
I'm sure other languages have similar functions.
I have no other suggestions on how to cut runtime down. Hopefully someone else does.
An example is
$bool = true;
switch($bool){
case true:
//do something here
break;
case false:
//do false here
break;
}
I'm sure other languages have similar functions.
I have no other suggestions on how to cut runtime down. Hopefully someone else does.
#3
Posted 11 September 2008 - 12:21 AM
Which leaves me with a bunch of IF statements dependent on gross to calculate the taxes. And IF statements don't leave me with some nice equation I can reverse engineer and plunk into the equation to solve for Gross. At least, I don't think so.
seriöse Singlebörse best wrinkle creams
#4
Posted 11 September 2008 - 08:02 AM
First issue:
Determine the boundary values for resulting Net, that will change what you are looking for to an if-based solver:
First $10,000 of gross, taxes are 0.
From $10,000 to $90,000 of gross, taxes are 20% of that amount above 10K.
From 90,000 and above of gross, taxes are 40% of the amount above 90K.
if G<=10000 -> N = G
if 10000<G<=90000 -> N=10000 + (G-10000)*(.8)
if 90000<G -> N = 10000 + 64000 + (G-90000)*(.6)
So:
if N<= 10000 -> G = N
if 10000 < N <= 74000 -> G = 10000 + (N-10000)/(.8)
if 74000 < N -> G = 90000 + (N-74000)/(.6)
Determine the boundary values for resulting Net, that will change what you are looking for to an if-based solver:
First $10,000 of gross, taxes are 0.
From $10,000 to $90,000 of gross, taxes are 20% of that amount above 10K.
From 90,000 and above of gross, taxes are 40% of the amount above 90K.
if G<=10000 -> N = G
if 10000<G<=90000 -> N=10000 + (G-10000)*(.8)
if 90000<G -> N = 10000 + 64000 + (G-90000)*(.6)
So:
if N<= 10000 -> G = N
if 10000 < N <= 74000 -> G = 10000 + (N-10000)/(.8)
if 74000 < N -> G = 90000 + (N-74000)/(.6)
#5
Posted 12 September 2008 - 12:14 AM
Which leaves me with a bunch of IF statements dependent on gross to calculate the taxes. And IF statements don't leave me with some nice equation I can reverse engineer and plunk into the equation to solve for Gross. At least, I don't think so.
#6
Posted 12 September 2008 - 02:22 AM
butidonot said:
Which leaves me with a bunch of IF statements dependent on gross to calculate the taxes. And IF statements don't leave me with some nice equation I can reverse engineer and plunk into the equation to solve for Gross. At least, I don't think so.
I don't think there is any other elegant ways of doing this. What you want is really defendant on an if clause or a switch. Personally, I think the switch is more efficient.
#7
Posted 12 September 2008 - 05:35 AM
If a function is defined piece-wise (with if statements), the inverse usually is too. Sorry.


Sign In
Create Account

Back to top









