Function evaluation in fortran

In summary, the conversation discusses the task of evaluating a function at a specific point. The user asks for help on how to approach this problem and a link is provided to a resource explaining how to program function expressions in FORTRAN. The user then mentions finding and modifying a code online to fit into their own code, as they are a beginner in FORTRAN.
  • #1
Antonija
18
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
  • #2
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.
 
  • #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...
 
  • #4
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.
 
  • #5
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:
  • #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...
 

What is function evaluation in Fortran?

Function evaluation in Fortran refers to the process of determining the output of a function based on the input values provided. This is an important aspect of programming in Fortran as it allows for the creation of reusable code and efficient computation of complex mathematical operations.

What is the syntax for writing a function in Fortran?

The syntax for writing a function in Fortran is as follows: function function_name(arguments) result(return_value) where the function name is followed by any arguments that are needed for the function and the result keyword is used to specify the return value of the function.

How do you call a function in Fortran?

To call a function in Fortran, you simply use the function name followed by the arguments within parentheses. For example, if you have a function called calculate_area that takes two arguments, you would call it like this: area = calculate_area(length, width).

What is the difference between a function and a subroutine in Fortran?

The main difference between a function and a subroutine in Fortran is that a function always returns a value, while a subroutine does not. This means that a function can be used as part of an expression, while a subroutine cannot. Additionally, a function must have a result keyword, while a subroutine does not.

Can you use external libraries or modules in Fortran functions?

Yes, you can use external libraries or modules in Fortran functions by using the use statement at the beginning of your code. This allows you to access functions and subroutines from other files or libraries within your own code.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
21
Views
307
  • Engineering and Comp Sci Homework Help
Replies
3
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
Back
Top