Is there any command in Fortran that is similar to eval in MATLAB?

  • Thread starter Thread starter phanlada
  • Start date Start date
  • Tags Tags
    Fortran Matlab
AI Thread Summary
Fortran does not have a direct equivalent to MATLAB's eval function for dynamically calling functions by name. Instead, users can define the function directly within the main program or encapsulate it in a MODULE, which can then be included in the main program. This allows for straightforward function calls without the need for dynamic evaluation. The discussion emphasizes using standard Fortran practices to achieve similar functionality. Understanding these methods is essential for implementing Newton's method for solving non-linear equations in Fortran.
phanlada
Messages
2
Reaction score
0
Hello,

I am trying to write a Fortran subroutine to solve non-linear equations (given by external function fnxname) using Newton's method, where the derivative is given by finite difference calculation. How may I use the function in the program.

Suppose the desired function name is given by a string "fnxname", I cannot write fnxname(x), can I? In MATLAB, I may write eval(cat('fnxname','(x)')) or something like that. Is there a similar command in Fortran?

Replies would be much appreciated. Thank you very much.
 
Physics news on Phys.org
You can either just put the function inside of the main program's file, or put the function inside of a MODULE and INCLUDE that module in the main program. Then you can simply call the function as normal.
 

Similar threads

Replies
5
Views
5K
Replies
11
Views
6K
Replies
3
Views
7K
Replies
4
Views
3K
Replies
4
Views
10K
Replies
7
Views
2K
Replies
1
Views
2K
Replies
2
Views
9K
Back
Top