views:

308

answers:

3

After painful trial and error, I arrived at a grotesque function that behaves the way I want it to:

(exp(- abs(6 * (x - 0.7)) ^ 2.5 ) + exp(- (x-1.7) ^ 8 ) * 1.2)/1.5785

I only care about the values for the range 0 <= x <= 1 and the slope at x = 1. In this interval, 0 <= y <= 1 as well.

Are there any free tools (web-based or MAC OS X) that will generate the Taylor series expansion for this? (I found one, but it choked on such a complex formula and does not support abs.)

My purpose in generating the series expansion is that it may be more efficient to compute. (This function will be called hundreds of thousands of times in Javascript, so performance is an issue.)

Alternately, I could sample the points and do a curve fitting if I had a curve fitting tool. (I do not own MS Excel, alas.) Know of any free non-linear curve-fitting tools (web-based or MAC OS X)?

A: 

GNU Octave is a free package that, among other things, has a function polyfit to do least-squares polynomial curve fitting. I think this (or some other package with an equivalent function) is probably a better match for your problem than Taylor series expansion. That absolute value term might make it hard to find a Taylor series that extrapolates well through the point at x=0.7, where the first derivative has a discontinuity.

Jim Lewis
Thank you. And you are right about the discontinuity. Wasn't paying attention. I can probably find a way to remove it by messing with the other terms.
Paul Chernoch
A: 

You can compute the derivatives (and so the taylor series) yourself.

Consider the f(x) = e^h(x) (since your formula is just a sum of two exp terms).

Now f'(x) = e^(h(x)) * h'(x) = h'(x)f(x)

Using leibniz's formula

f^(n+1) = Sum (r = 0, r = n) (n choose r) f^n * h^(r+1)

where f^(k) is the kth derivative (similar for h), and f^0 is just f.

You only need to calculate the derivates at say x = 0 for few powers, and this gives you a recursive formula which can be coded up pretty quickly and give you the values you need.

Moron
A: 

Maxima does this. See the taylor function.

Alex