Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Fortran90 Program - Numerical Methods and Computing - Old Exam Paper, Exams of Mathematical Methods for Numerical Analysis and Optimization

Main points of this past exam are: Fortran90 Program, Sequence of Integers, Sample Run of Program, Positive and Negative Integers, Partial Credit, Important Design Feature, Inner Control Limits, Experimental Reading, Tabular Form

Typology: Exams

2012/2013

Uploaded on 03/28/2013

shona
shona 🇮🇳

4

(1)

18 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Q1 continues
Cork Institute of Technology
Bachelor of Engineering (Honours) in Structural Engineering - Stage 1
Summer 2008
COMPUTING & NUMERICAL METHODS – Old Syllabus
Time : 3 Hours
Answer Question 1 and 2 other questions. Examiners :
Prof. P.E. O Donoghue
Mr. P. Anthony
Dr M.G. Murphy
Q1[ 40 marks] Please answer each of the following questions.
Q1a[ 8 marks]
What is the output from the following Fortran90 program?
NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.
PROGRAM a2004_q1a
implicit none
integer::john = 9, george = 4
real::paul = 9.0, ringo = 4.0
character::damien = 'Z'
print*, john + 1 / george
print*, george + 1 / john
print*, john / george + 1
print*, george / john + 1
print*, (paul - 3)/ ringo
print*, ringo / (paul + 11)
print*, (john + 1)/ ringo
print*, george / (paul - 1)
print*,'take a deep breath'
print*, 3 * george - 2 * ringo
print*, (george * 2 == ringo * 3)
print*, damien
STOP'a2004_q1a.f90 ends .'
END PROGRAM a2004_q1a
pf3
pf4
pf5
pf8

Partial preview of the text

Download Fortran90 Program - Numerical Methods and Computing - Old Exam Paper and more Exams Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Q1 continues

Cork Institute of Technology

Bachelor of Engineering (Honours) in Structural Engineering - Stage 1

Summer 2008

COMPUTING & NUMERICAL METHODS – Old Syllabus

Time : 3 Hours

Answer Question 1 and 2 other questions. Examiners :

Prof. P.E. O Donoghue

Mr. P. Anthony

Dr M.G. Murphy

Q1[ 40 marks] Please answer each of the following questions.

Q1a[ 8 marks] What is the output from the following Fortran90 program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2004_q1a implicit none

integer::john = 9, george = 4 real::paul = 9.0, ringo = 4. character::damien = 'Z'

print, john + 1 / george print, george + 1 / john

print, john / george + 1 print, george / john + 1

print, (paul - 3)/ ringo print, ringo / (paul + 11)

print, (john + 1)/ ringo print, george / (paul - 1)

print*,'take a deep breath'

print, 3 * george - 2 * ringo print, (george * 2 == ringo * 3)

print*, damien

STOP'a2004_q1a.f90 ends .' END PROGRAM a2004_q1a

Q1 continues

Q1b[ 8 marks] What is the output from the following Fortran90 program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2004_q1b implicit none

integer::cork = 15, clare = 10, cavan = 5

if( (clare /= 5) .and. (clare /= 15) )then if(cork == 10)then print, 'ring' else print, '*setanta' end if end if

cork = cork - 5

if( (cork == clare) .and. (clare > cavan) )then print, 'ronan' end if clare = cavan cavan = cavan + 5 if( (cork > clare) .and. (clare < cavan) )then print, '****DJ' clare = cork + cavan end if if( (cavan > clare) .and. (clare > cork) )then print, 'shevlin' else print, 'gilligan' end if

STOP'a2004_q1b.f90 ends ..' END PROGRAM a2004_q1b

Q1 continues

Q1d[ 8 marks] What is the output of the following Fortran90 program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2004_q1d implicit none

integer::limit = 6 integer::a, b

do a = limit,0, - do b = limit, 0, - if( (0 == a) .or. (limit == a) )then write(,'(i1)',advance='no')a else if( (b - a == 0))then write(,'(i1)',advance='no')a else if( (b + a == limit))then write(,'(i1)',advance='no')b else write(,'(a)',advance='no')'#' end if end do print* end do

STOP'a2004_q1d.f90 ends ....' END PROGRAM a2004_q1d

Q1e[ 8 marks] What is the output of the following Fortran90 program? What is the variable thatOne doing in the code?. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM a2004_q1e implicit none

integer::thisOne, thatOne

thisOne = 17 thatOne = 1 do write(, '(i5)', advance= 'no')thisOne if(mod(thatOne, 5) == 0)then print end if if(thisOne == 1)exit

if(mod(thisOne, 2) == 0)then thisOne = thisOne / 2 else thisOne = thisOne * 3 + 1 end if thatOne = thatOne + 1 end do print* print*

stop'a2004_q1e.f90 ends ...' END PROGRAM a2004_q1e

Q2 continues

Q2[ 30 marks]

The experimental data for an important design feature of a structure are stored in the file f:\myExperiment\theData.dat. The data is raw(without any explanatory text or headings) and each line contains one experimental reading x for the feature as shown in fig 2.1 below(10 data items are shown but there are probably several hundreds of values in the file). We use x to preserve confidentiality.

Each value of x is taken regularly, at intervals of 3 hours. The value is monitored against a Control Chart to ensure that it stays stable: ƒ If a value falls outside the Outer Control Limits (OCL) the structure is closed for immediate analysis and repair, ƒ if a value falls outside the Inner Control Limits(ICL) (but NOT outside the OCL) a warning state is declared but the structure is NOT closed.

Please write Fortran90 code / program ƒ to connect to this file, ƒ to read the data calculating the mean and standard deviation for the data on file, ƒ to calculate the max and min values for the data on file, ƒ to calculate the inner control limits, the outer control limits ƒ to transfer them (for printing for monitoring technicians at the start of each day) to the new file f:\myExperiment\theControlLimits.dat in tabular form as shown if fig. 2.2 below.

The relevant formulas are detailed on the next page.

etc etc

Control Chart Update:

number of data : n ---> 30

max value : ---> 6.

min value : ---> 4.

mean value : ---> 5.

standard dev : ---> 0.

Outer Control Limits ( 4.343 , 6.751 )

Inner Control Limits ( 4.783 , 6.311 )

Fig 2.1 Fig 2.

Q3[ 30 marks]

Write a Fortran90 program to calculate and display the perimeter and the area of triangles whose vertices (i.e. the x, y coordinates of the vertices) are specified by the user.

The code should feature

  • user specification of the triangle vertices^ A (^ a _ x , a _ y ),^ B ( b^ _ x , b _ y ),^ C (^ c _ x , c _ y )
  • verification that A , B , C are valid triangle vertices i.e. that they are distinct(i.e. separate points), loop until user enters valid vertices
  • calculation of the lengths of the sides i.e. aAB , bBC , cCA
  • calculation of the perimeter p = a + b + c ,
  • calculation of the area using Hero’sFormula area = s^ (^ sa )(^ sb )(^ sc )where s = p * 0. 5
  • display of perimeter and area with appropriate commentary and correct to 3 decimal places
  • user option to repeat the calculations for another triangle a, b, c

Q4[ 30 marks] Please answer each of the following questions.

Q4a[ 6 marks] Write a Fortran90 function module for the Fortran90 functions FUNCTION f(x) and FUNCTION fPrime(x) to define the functions

y = f ( x )= 9. 8 x^7 + 6. 5 x^4 + 3. 2 x + 1. 9

= f ' ( x )= 68. 6 x^6 + 26. 0 x^3 + 3. 2

dx

dy

Q4b[ 12 marks] Write a Fortran90 subroutine module to implement the NewtonRaphson Root Finding Algorithm, SUBROUTINE NewtonRaphson(f, fPrime, approx, epsilon, maxIter, root) given

  • f is the function f(x), fPrime is f’(x) its derivative
  • epsilon is the user-specified degree of accuracy(We’re happy we have the root at x if

abs ( f ( x ))≤ epsilon at x),

  • that we put a limit, maxIter , on the number of iterations the subroutine performs
  • an initial approximation is entered as approx ,
  • the approximation is returned by root

Q4c[ 12 marks] Write a Fortran90 driver program to use the above modules to search for and find the roots of f(x). This program will feature

  • a user option for a root search, a user-controlled loop where f(x) is evaluated for user nominated x. This allows the user to locate where f(x) value changes sign, thus giving the good estimates for root location,
  • a user option to repeat root search or to quit

Q5[ 30 marks]Please answer each of the following questions.

Q5a(15 marks) Write , in a single module form, the two subroutines Convert_to_Polar(X, Y, R, Theta) to return the polar coordinates (R, Theta) equivalent to the rectangular coordinates (x, y), and Convert_to_Rectangular(R, Theta, X, Y) to return the the rectangular coordinates (x, y), equivalent to polar coordinates (R, Theta).

NOTE: The Fortran90 function a tan 2 ( x , y )= tan−^1 ( x / y )in radians should be useful here.

Q5b(15 marks) Write , in a single module form, the two LOGICAL functions LinesAreParallel(a, b, c, d, e, f)

to return whether the lines ax + by = c and dx + ey = f are parallel or not

LinesArePerpendicular(a, b, c, d, e, f)

to return whether the lines ax + by = c and dx + ey = f are perpendicular or not