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
Click For Summary
SUMMARY

The discussion centers on the lack of a direct equivalent to MATLAB's eval function in Fortran for dynamically calling functions by name. Users can define functions within the main program or encapsulate them in a MODULE, which can then be included in the main program. This allows for standard function calls without the need for dynamic evaluation. The recommended approach is to structure the code using MODULEs for better organization and reusability.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with Fortran MODULEs
  • Knowledge of Newton's method for solving non-linear equations
  • Basic concepts of function definitions in Fortran
NEXT STEPS
  • Explore Fortran MODULEs and their usage in code organization
  • Research Newton's method implementation in Fortran
  • Learn about function pointers and dynamic function calls in Fortran
  • Investigate best practices for structuring Fortran programs
USEFUL FOR

Fortran developers, computational scientists, and anyone implementing numerical methods in Fortran will benefit from this discussion.

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 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 11 ·
Replies
11
Views
6K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
10K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K