FORTRAN Help: Concept of User Defined Functions

In summary, the conversation was about creating a user defined function and then using the bisection method to find the zeros of said function. The issue was figuring out how to call on the user defined function to evaluate at different values. The solution was to use the format Y1 = F1(A) in the calling program or subroutine, where the function F1(x) is evaluated at x = A and the result is assigned to the variable Y1. The conversation also mentioned struggling with conceptualizing the material and not receiving clear direction from the textbook or professor.
  • #1
mattmac.nuke
22
0
Alright, I have a situation where I need to create a user defined function (I've done that) next I need to write a subroutine that uses the bisection method to find the zeros of said function (I've also done that) but I can't figure out how to call on the user defined function to evaluate at different values... more specifically, I have a function, f1 (x), where it takes a value x and makes some computations with it, but I need that same function to be called on to evaluate 'a' (the lower bound) and 'b' (the upper bound) and the 'm' (the midpoint), but I'm not sure how to do that... my textbook doesn't cover it, and my professor didn't provide any useful direction. I haven't conceptualized some of this material well enough to draw logical solutions.
 
Physics news on Phys.org
  • #2
In the calling program or subroutine, if you wanted to evaluate f1(x) at a particular value, you would write something like

Y1 = F1 (A)

where the function F1 (x) is evaluated at x = A and the result assigned to the variable Y1.
 
  • #3
Thank you! I figured out where the error was, in passing the variables, but after reading that I was reaffirmed on what I thought the program should be doing.
 

1. What is a user defined function in FORTRAN?

A user defined function in FORTRAN is a subroutine that is defined by the user to perform a specific task. It is a block of code that can be called multiple times throughout a program, making it reusable and efficient.

2. How do you define a user defined function in FORTRAN?

To define a user defined function in FORTRAN, you must use the FUNCTION statement followed by the name of the function and its argument list. The function must also have a RETURN statement to specify the value it will return to the calling program.

3. Can a user defined function in FORTRAN have multiple return values?

Yes, a user defined function in FORTRAN can have multiple return values. This is achieved by using the RESULT statement within the function to specify the different return values.

4. How are user defined functions called in FORTRAN?

User defined functions in FORTRAN are called by using their name followed by the arguments required by the function. The returned value can then be assigned to a variable or used directly in the program.

5. What are the benefits of using user defined functions in FORTRAN?

There are several benefits of using user defined functions in FORTRAN. They make the code more organized and easier to read, as well as reducing the amount of code that needs to be written. They also allow for code reusability, making the program more efficient. Additionally, user defined functions can improve the overall performance of a program by reducing the number of times a particular task needs to be performed.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
864
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
31
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
Back
Top