## Developing a program for finding functions

## Developing a program for finding functions

(OP)

Hello everyone,

I am an intermediate at FORTRAN and want to discuss the main idea of my next project before I begin. Basically I am going to program a function finder for simple, one-dimensional functions in the first place. Later I plan to extend it to higher dimensions. The pseudo-code is as follows:

1. Read in an array from an external file with given x- and y-values of the unknown function (DONE)

2. Generate a possible function.

3. Check the differences of the given values and calculated values of the function. If this global error is below a certain value (1E-5 or so) the function is found. If not, go back to 2. (DONE)

As one can see I have difficulties with point 2:

I want to generate all possible functions for the given problem successively. Lets suppose I only know that the function depends on one variable (x). It may contain brackets and all possible arithmetic operators.

What I want to know is: How can I realize it to try out all arithmetic operators and brackets at every digit? At an arbitrary point the program should generate the following functions for example:

(3*x+5*x)

(3*x*5+x)

(3+x+5*x)

(3+x*5*x)

...

3*(x+5*x)

3*(x*5+x)

3+(x+5*x)

....

This might be not be the best example, because some expressions are equivalent, but that does not matter here. I hope this example points out what I want to realize. Is the conversion of a generated string into a function a good idea?

Some hints or other ideas how to realize this are welcome.

======

I am aware of the fact, that each function must be checked for correctness at first to avoid runtime errors, means the number of opening and closing brackets must be the same, arithmetic operators are not allowed to follow on each other, between two brackets should be one operator with two other values at least and so on. Furthermore all senseless possibilites can be skipped to increase efficiency.

Thanks for reply,

Daryl Musashi

I am an intermediate at FORTRAN and want to discuss the main idea of my next project before I begin. Basically I am going to program a function finder for simple, one-dimensional functions in the first place. Later I plan to extend it to higher dimensions. The pseudo-code is as follows:

1. Read in an array from an external file with given x- and y-values of the unknown function (DONE)

2. Generate a possible function.

3. Check the differences of the given values and calculated values of the function. If this global error is below a certain value (1E-5 or so) the function is found. If not, go back to 2. (DONE)

As one can see I have difficulties with point 2:

I want to generate all possible functions for the given problem successively. Lets suppose I only know that the function depends on one variable (x). It may contain brackets and all possible arithmetic operators.

What I want to know is: How can I realize it to try out all arithmetic operators and brackets at every digit? At an arbitrary point the program should generate the following functions for example:

(3*x+5*x)

(3*x*5+x)

(3+x+5*x)

(3+x*5*x)

...

3*(x+5*x)

3*(x*5+x)

3+(x+5*x)

....

This might be not be the best example, because some expressions are equivalent, but that does not matter here. I hope this example points out what I want to realize. Is the conversion of a generated string into a function a good idea?

**Is it at all possible to develop a code, which**

- generates a string where

- all possible function elements (numbers, arithmetic operators, brackets...) are tried out at every digit,

- then this string is converted into a function, which is used for the calculation in step 3 (see above)?- generates a string where

- all possible function elements (numbers, arithmetic operators, brackets...) are tried out at every digit,

- then this string is converted into a function, which is used for the calculation in step 3 (see above)?

Some hints or other ideas how to realize this are welcome.

======

I am aware of the fact, that each function must be checked for correctness at first to avoid runtime errors, means the number of opening and closing brackets must be the same, arithmetic operators are not allowed to follow on each other, between two brackets should be one operator with two other values at least and so on. Furthermore all senseless possibilites can be skipped to increase efficiency.

Thanks for reply,

Daryl Musashi

## RE: Developing a program for finding functions

Such functions could be calculated by several methods - see for example:

http://en.wikipedia.org/wiki/Curve_fitting

http://en.wikipedia.org/wiki/Interpolation

http://en.wikipedia.org/wiki/Polynomial_interpolat...

http://en.wikipedia.org/wiki/Least_squares

## RE: Developing a program for finding functions

For instance, a possible form could be polynomial : a0 + a1*x + a2*x^2 + a3*x^3, but a serie of cosinus or sinus functions is possible too (see Fourier).

Then, for a given table, you can find the best parameters fitting the table (least square method for instance).

Another direction could be the approximations by NURBS. Non Uniform Rational Bezier Splines are the way to model complex curves or surfaces with a minimum set of construction points. The result is not analytical (you still have a table of points) but you can manage the final smoothness as you want (NURBS of class C1, C2 ...). The advantage of the NURBS is that you can adjust the number of constructions points to match the initial table.

François Jacq

## RE: Developing a program for finding functions

This was "once upon a time ... in a land far away ... available from Oak Ridge National Laboratory

under contract # W-7405.eng-26 as ORNL4264

There was also a FOTRTAN IV program listing. The entire program source code was ~~~ 400 lines.

MichaelRed