How to Evaluate a Function in Fortran at a Given Point of x?

  • Context: Comp Sci 
  • Thread starter Thread starter Antonija
  • Start date Start date
  • Tags Tags
    Fortran Function
Click For Summary

Discussion Overview

The discussion revolves around evaluating a mathematical function at a specific point in Fortran, particularly focusing on how to handle user-inputted function expressions as character strings. Participants explore the challenges of parsing and evaluating these expressions in the context of Fortran programming.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant seeks guidance on how to evaluate a function given as a character string and a value for x, expressing uncertainty about where to start.
  • Another participant notes that the task is non-trivial and depends on the complexity of the functions allowed, suggesting that simple expressions might be manageable.
  • A participant mentions that older programming languages like Fortran lack built-in capabilities to evaluate strings as expressions, requiring manual parsing of the input.
  • One participant clarifies that their initial reference was not a user-input example but rather an illustration of programming function expressions in Fortran.
  • A later post indicates that a participant found a solution by modifying existing code from online sources, acknowledging their beginner status in Fortran and their inability to create a parser independently.

Areas of Agreement / Disagreement

Participants do not reach a consensus on a specific method for evaluating functions in Fortran, and multiple approaches and levels of understanding are evident throughout the discussion.

Contextual Notes

There is an acknowledgment of the limitations in Fortran regarding string evaluation and the need for custom parsing solutions, but specific methods or implementations remain unresolved.

Antonija
Messages
18
Reaction score
0

Homework Statement



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

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

Homework Equations

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:
Physics news on Phys.org
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.
 
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...
 
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.
 
Antonija said:

Homework Statement



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

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

Homework Equations

The Attempt at a Solution


Unfortunatley didn't try anything because I don't know where to start and how to solve my problem.

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:
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...
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K