Free Essay

Fortran the Lenght of a Parabola Segment

In:

Submitted By dimeji
Words 376
Pages 2
Programming Example: The Length of a Parabola Segment

http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap02/p-lengt...

Problem Statement
Given base b and height h, the length of a special segment on a parabola can be computed as follows:

Write a program to read in the values of base and height, and use the above formula to compute the length of the parabola segment. Note that both base and height values must be positive.

Solution
! ----------------------------------------------------------! Calculate the length of a parabola given height and base. ! ----------------------------------------------------------PROGRAM ParabolaLength IMPLICIT NONE REAL REAL :: Height, Base, Length :: temp, t 'Height of a parabola : ' Height 'Base of a parabola Base : ' *

WRITE(*,*) READ(*,*) WRITE(*,*) READ(*,*)

! ... temp and t are two temporary variables t = 2.0 * Height temp = SQRT(t**2 + Base**2) Length = temp + Base**2/t*LOG((t + temp)/Base) WRITE(*,*) WRITE(*,*) WRITE(*,*) WRITE(*,*) END PROGRAM

'Height = ', Height 'Base = ', Base 'Length = ', Length

ParabolaLength

Click here to download this program.

Program Output
Height of a parabola : 100.0 Base of a parabola 78.5 Height = 100. Base = 78.5 Length = 266.149445 :

The input values for Height and Base are 100.0 and 78.5, respectively. The computed length is 266.149445.

Discussion

1 of 2

4/5/2014 9:30 PM

Programming Example: The Length of a Parabola Segment

http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap02/p-lengt...

The values of base and height will be stored in REAL variables Base and Height, respectively. Length will be used to store the parabola segment length. Since the content in the square root is used twice, it would be more convenient to save the result in a variable. This value will be stored in temp. Since 2h also appears a few times, variable t is used to store this value. After reading in Height and Base, 2.0 * Height is computed and stored in t with the first assignment. Then, the second assignment computes the content in the square root and stores the result into temp. The third assignment compute the segment length and stores the result into Length. Note that intrinsic function LOG() is used. The four WRITE statements display the input and the results.

2 of 2

4/5/2014 9:30 PM

Similar Documents