Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Developing a program for finding functions

Status
Not open for further replies.

DarylMusashi

Technical User
Sep 10, 2014
1
DE
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?

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)?


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
 
You say that you want to generate all possible functions... You cannot. You have to choose one or several function forms (many are possible) with parameters and you have to adjust the parameters...

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
 
There is an ANCIENT fortran program called "Linear". This function would provide you with the (again) ARCHAIC code which easily forms the basis of such a project.

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


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top