Docsity

Fortran 90 Lab: Function Subprograms - Limits & Quadratic Functions - Prof. Charles Pruett, Lab Reports of Mathematics

Toggle sidebar
bg1
Math 248 Computers and Numerical Algorithms–Pruett
LABORATORY ASSIGNMENT
Function Subprograms in Fortran 90
C In first-semester calculus, you learned that
lim
x→+∞
(1+1
x)x=e
Although you cannot prove this using a computer, you can nevertheless look at trends of functions
that suggest certain limits. On Blackboard under DEMONSTRATIONS are the files limit.f90 and
lim lib.f90 that contain the PROGRAM limit and the MODULE limit library on the reverse side
of this paper. Copy these into your working directory, compile the MODULE, and then compile the
PROGRAM. Run the program and briefly describe the results.
C Modify the MODULE and the PROGRAM to approximate the following limit:
lim
x→0+(1+x)1
x
Recompile, re-run, and briefly describe your results.
B On paper, write a quadratic function f(x)(with integer coefficients) one of whose roots is √7.
BWrite and compile a Fortran 90 MODULE, containing a single function subprogram, which returns the
value of the function f(x)above, given the value of x.
B Add to your Fortran 90 MODULE above a second function subprogram that returns the value of f0(x),
given the value of x. Recompile.
B Write, compile, and run a Fortran 90 PROGRAM that computes the √7 by Newton’s method and USEs
the two function programs in the MODULE above.
A Modify your MODULE and PROGRAM above to compute √a, where ais any non-negative real num-
ber (to be read by your program).
A+ Write the quadratic formula on paper.
A+ Rationalize the numerator of the quadratic formula, and simplify the result as much as possible.
A+ From Blackboard DEMONSTRATIONS also copy files quad2.f90 and quadlib.f90 to your working
directory. Files quad2.f90 and quadlib.f90 contain the main PROGRAM and (half of the) MODULE,
respectively, of the “smart” quadratic solver discussed in class. Add another function subprogram,
which exploits the alternative quadratic formula above, to the MODULE and recompile. Feel free to cut
and paste.
A+ Run your “smart solver” and verify that the results are correct for several different sets of values A,B,
and C.
pf2

Partial preview of the text

Download Fortran 90 Lab: Function Subprograms - Limits & Quadratic Functions - Prof. Charles Pruett and more Lab Reports Mathematics in PDF only on Docsity!

Math 248 Computers and Numerical Algorithms–Pruett

LABORATORY ASSIGNMENT

Function Subprograms in Fortran 90

C In first-semester calculus, you learned that

lim x→+∞

x

)x^ = e

Although you cannot prove this using a computer, you can nevertheless look at trends of functions that suggest certain limits. On Blackboard under DEMONSTRATIONS are the files limit.f90 and lim lib.f90 that contain the PROGRAM limit and the MODULE limit library on the reverse side of this paper. Copy these into your working directory, compile the MODULE, and then compile the PROGRAM. Run the program and briefly describe the results.

C Modify the MODULE and the PROGRAM to approximate the following limit:

lim x→ 0 +

( 1 + x)

(^1) x

Recompile, re-run, and briefly describe your results.

B On paper, write a quadratic function f (x) (with integer coefficients) one of whose roots is

B Write and compile a Fortran 90 MODULE, containing a single function subprogram, which returns the value of the function f (x) above, given the value of x.

B Add to your Fortran 90 MODULE above a second function subprogram that returns the value of f ′(x), given the value of x. Recompile.

B Write, compile, and run a Fortran 90 PROGRAM that computes the

7 by Newton’s method and USEs the two function programs in the MODULE above.

A Modify your MODULE and PROGRAM above to compute

a, where a is any non-negative real num- ber (to be read by your program).

A+ Write the quadratic formula on paper.

A+ Rationalize the numerator of the quadratic formula, and simplify the result as much as possible.

A+ From Blackboard DEMONSTRATIONS also copy files quad2.f90 and quadlib.f90 to your working directory. Files quad2.f90 and quadlib.f90 contain the main PROGRAM and (half of the) MODULE, respectively, of the “smart” quadratic solver discussed in class. Add another function subprogram, which exploits the alternative quadratic formula above, to the MODULE and recompile. Feel free to cut and paste.

A+ Run your “smart solver” and verify that the results are correct for several different sets of values A, B, and C.

PROGRAM limit ! !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! Program to illustrate a use of FUNCTION subprograms ! ! AUTHOR: Dave Pruett/JMU Math ! CREDITS: None !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! USE limit_library

IMPLICIT NONE

REAL (KIND=8) :: x, y INTEGER :: i

DO i = 1,

x = 2.0i y = my_function(x) WRITE (,) ’ i = ’, i, ’ x = ’, x, ’ y = ’, y

END DO

STOP

END PROGRAM limit

MODULE limit_library

CONTAINS ! ! Enter user-defined function in this subprogram ! FUNCTION my_function(x)

IMPLICIT NONE

REAL (KIND=8), INTENT(IN) :: x! x may NOT be redefined REAL (KIND=8) :: my_function

my_function = (1. + 1./x)**x! user-defined function

RETURN! return value to main program

END FUNCTION my_function

END MODULE limit_library