# Fortrain and C program

Programming Languages Assignment 1 (Write 2 programs, one in Fortran and one in C, both do the same thing as described below) In this first assignment, since we have been discussing efficiency and FORTRAN, let's run a race between FORTRAN and C on the RS-6000 system. I have made a function to allow you to do CPU timings from FORTRAN (by calling on C), and so what we will do is a long winded series of floating point computations and CPU time the thing. You will simply write a FORTRAN module to do numerical integration and CPU time how long it takes, using 1 million subintervals. I will discuss FORTRAN in class; here I will simply outline the trapezoidal rule, and how to do the CPU timing. For CPU timing, first get the file getclock.o as with getfile getclock.o Then in your FORTRAN code, use implicit real*8(a-h,o-z) external getclock start = getclock(0) ... elap = (getclock(0) - start) / [url removed, login to view] Then, elap is the CPU elapsed time in seconds that ... took to do. Trapezoidal rule: To integrate a function f(x) over an interval [a,b] with n subintervals, break up [a,b] into n equal subintervals a = x0 < x1 < x2 < ... < xn = b and let h = (b - a) / n = width of each subinterval. Then the integral of f over [a,b] is approximately h * (f(a)/2 + f(x1) + f(x2) + ... + f(xn-1) + f(b)/2) Use the following function to integrate : f(x) = (tan(atan(exp(log(sqrt(x * x)))))) ** 2 To compile your code, use f77 -O myfile.f getclock.o which will make executable [url removed, login to view] if it compiles OK. In the C version, just call clock() to get the start and elapsed time, and then divide the difference by CLOCKS_PER_SEC as a double to get the elapsed time in seconds. Be sure in both cases to print the approximated integral value! Mathematically you are integrating x^2 over [0,1] so the exact answer is just 1/3 (0.333333...). However due to floating point roundoff, the result will likely be a bit off.

## Deliverables

Complete and fully-functional working program(s) in executable form as well as complete source code of all work done. Complete copyrights to all work purchased.

Mon 2/4/02

( 25 comentários ) United States

ID do Projeto: #2837718

## Concedido a:

belovlabs

See private message.

\$7 USD em 14 dias
(33 Comentários)
4.0

## 3 freelancers estão ofertando em média \$31 para esse trabalho

anatprogeu

See private message.

\$21.25 USD in 14 dias
(4 Comentários)
1.2
aslamvw

See private message.

\$63.75 USD in 14 dias
(0 Comentários)
0.0