goalseek (as in Excel)

Q&A's, tips, howto's
Locked
jazper
Posts: 92
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

goalseek (as in Excel)

Post by jazper »

I use GoalSeek a fair amount in spreadsheets. It's fast enough, but I confess I don't understand how it works. Googling produced discussions about Newton Rhapson, something that Computer Science and Math students seem to know about. Having last looked at math a half century ago on finishing my schooling, I can't pick up what it's about.

Recently some other clever mathematical stuff was added to newLISP. Has anybody ever tried something like GoalSeek in newLISP? If so, I'd appreciate an explanation of the algorithm.

As an example, I use it in spreadsheets to arrive at what a payment instalment will be over [n] months, at a certain rate of interest. It isn't simply a matter of dividing sum of principle + interest by number of months, because interest is compounded monthly. It looks to me like GoalSeek is able to cope with this, as though it calculates the a root of compound interest. Microsoft gives an simple explanation of the algorithm which didn't help me at all. Perhaps it just iterates, adding a cent at a time, until its guess subtracted from target is close enough to zero. I'd imagine it would be easier to bisect, as in a binary search, but I can't get my head around the code even in pseudocode. Any ideas?

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: goalseek (as in Excel)

Post by xytroxon »

I have never used them, but you should be able to find what you want here:

http://www.newlisp.org/downloads/newlis ... #financial

Financial math functions

fv returns the future value of an investment
irr calculates the internal rate of return
nper calculates the number of periods for an investment
npv calculates the net present value of an investment
pv calculates the present value of an investment
pmt calculates the payment for a loan

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Re: goalseek (as in Excel)

Post by xytroxon »

Also be sure to use floating point math functions for any calculations, that is: add sub mul div, instead of: + - * /

http://www.newlisp.org/downloads/newlis ... ting_point

Floating point math and special functionsabs returns the absolute value of a number

acos calculates the arc-cosine of a number
acosh calculates the inverse hyperbolic cosine of a number
add adds floating point or integer numbers and returns a floating point number
array creates an array
array-list returns a list conversion from an array
asin calculates the arcsine of a number
asinh calculates the inverse hyperbolic sine of a number
atan calculates the arctangent of a number
atanh calculates the inverse hyperbolic tangent of a number
atan2 computes the principal value of the arctangent of Y / X in radians
beta calculates the beta function
betai calculates the incomplete beta function
binomial calculates the binomial function
ceil rounds up to the next integer
cos calculates the cosine of a number
cosh calculates the hyperbolic cosine of a number
crc32 calculates a 32-bit CRC for a data buffer
dec decrements a number in a variable, list or array
div divides floating point or integer numbers
erf calculates the error function of a number
exp calculates the exponential e of a number
factor factors a number into primes
fft performs a fast Fourier transform (FFT)
floor rounds down to the next integer
flt converts a number to a 32-bit integer representing a float
gammai calculates the incomplete Gamma function
gammaln calculates the log Gamma function
gcd calculates the greatest common divisor of a group of integers
ifft performs an inverse fast Fourier transform (IFFT)
inc increments a number in a variable, list or array
inf? checks if a floating point value is infinite
log calculates the natural or other logarithm of a number
min finds the smallest value in a series of values
max finds the largest value in a series of values
mod calculates the modulo of two numbers
mul multiplies floating point or integer numbers
NaN? checks if a float is NaN (not a number)
round rounds a number
pow calculates x to the power of y
sequence generates a list sequence of numbers
series creates a geometric sequence of numbers
sgn calculates the signum function of a number
sin calculates the sine of a number
sinh calculates the hyperbolic sine of a number
sqrt calculates the square root of a number
sub subtracts floating point or integer numbers
tan calculates the tangent of a number
tanh calculates the hyperbolic tangent of a number
uuid returns a UUID (Universal Unique IDentifier)
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

jazper
Posts: 92
Joined: Thu Dec 10, 2009 8:26 am
Location: South Africa

Re: goalseek (as in Excel)

Post by jazper »

Thanks, xytroxon. I will have to roll my own Goal Seek. Perhaps some of these functions will help.

Locked