endy_tj
4/28/2006 1:59:00 AM
Hi,
In MS Excel there is a feature called Goal Seek. If you have a function
and you need certain output from the function, you can ask goal seek to
find the input for that function. The search for input value is done
brute force style.
I tried to imitate this feature in ruby when I wanted to calculate tax
subsidy (tax subsidy is also taxed, tax calc utilizes tax brackets, non
reversible, etc.) Here's my function:
def subsidy_seek(net_salary, &net_if_subsidy)
subsidy = 0
net_calc = net_if_subsidy.call(subsidy)
increment = 65536
until net_salary - net_calc < 10
until net_if_subsidy.call(subsidy + increment) < net_salary
increment /= 2
end
subsidy += increment
net_calc = net_if_subsidy.call(subsidy)
end
subsidy
end
It works, but it's a very specific function.
Is there a ruby library for this kind of feature?
Is there a mathematical term for goal seek? So if I want to learn more
I can key in that term in google?
Anybody know what kind of process goes behind goal seek? It seems to be
able to handle most situations.
--
Endy