DarylMusashi
Technical User
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
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