1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Function evaluation in fortran

  1. Feb 26, 2015 #1
    1. The problem statement, all variables and given/known data

    How can I evaluate function in some point of x?
    So, user inputs function in a character string, and he inputs the value of x. The program then needs to evaluate f(x).
    I have read something like this:http://faculty.cs.niu.edu/~hutchins/csci230/arith.htm [Broken]

    But, I'd like to see how it looks some routine/module for this...

    2. Relevant equations


    3. The attempt at a solution
    Unfortunatley didn't try anything because I don't know where to start and how to solve my problem.
     
    Last edited by a moderator: May 7, 2017
  2. jcsd
  3. Feb 26, 2015 #2

    jedishrfu

    Staff: Mentor

    This is not a trivial task and depends on the complexity of functions your program would allow.

    Can you be more specific?

    As an example, if your program only allowed the four basic arithmetic operations and no parentheses then it might allow simple expressions like 1+2*3

    You need to show some work before we can help further. We can't do your work for you.
     
  4. Feb 26, 2015 #3
    I'm sorry, now I see it looks bad, on my post. I'm going to try to work it out somehow and then I will post again...
     
  5. Feb 26, 2015 #4

    Mark44

    Staff: Mentor

    Some programming languages (the eval() function in JavaScript comes to mind) have the ability to evaluate strings that contain arithmetic and other expressions. Older languages such as Fortran don't have this capability, so your program has to parse the meaning of a string as simple as "2 + 5" and tokenize the symbols here to evaluate it.
     
  6. Feb 26, 2015 #5

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Just to be clear, the expression shown at the link was not something input by a user for evaluation. It was an illustration showing how to program function expressions in FORTRAN, what symbols are used for arithmetical operators, etc.
     
    Last edited by a moderator: May 7, 2017
  7. Mar 2, 2015 #6
    I did it well!! :) I don't know if I can put it here, so everyone who might need a help can see it, because I didn't do it myself, I just copy/paste some finished code which I found online (I'm sure I did it legally) and I modified it to fit into my original code...

    I'm just a begginer in fortran, so I'm not able to do the program to parse the expression, by myself, but I was able to understand it and to fit it into mine...
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Function evaluation in fortran
Loading...