Fortran90 Program for Engineering Exam - Structural Engineering: Computation, Exams of Mathematical Methods for Numerical Analysis and Optimization

A set of fortran90 programs and instructions for answering various engineering-related questions. The programs cover topics such as calculating the output of fortran90 codes, reading data from a file, and performing quadrature integrations using the mid-point rule. Students of structural engineering at cork institute of technology, or anyone interested in learning fortran90 programming, may find this document useful.

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
(NFQ – Level 8)
Autumn 2007
COMPUTING & NUMERICAL METHODS
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 q1a
implicit none
!-------------------------------------------------------------------
integer::eeny = 4, meeny = 3, myny = 5, moh = 6
eeny = eeny + 1
if(eeny == meeny + moh / meeny)then
print *, 'Jelly'
end if
eeny = eeny + 1
if(eeny == meeny)then
print *, 'Sherbert'
endif
if( (moh >= 6) .and. (myny + moh > 5) .and. &
( (5 + moh) <= (6 + myny) ) )then
if(moh == 7)then
print *, 'Carrott Cake'
else
print *, 'Ice Scream'
end if
end if
if((moh - myny - 1) /= 1)then
print *, 'Corn Flakes'
else
print *, 'Angel Food Cake'
end if
!-------------------------------------------------------------------stop
'q1a.f90 ends'
END PROGRAM q1a
pf3
pf4
pf5
pf8

Partial preview of the text

Download Fortran90 Program for Engineering Exam - Structural Engineering: Computation 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

(NFQ – Level 8)

Autumn 2007

COMPUTING & NUMERICAL METHODS

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 q1a implicit none !------------------------------------------------------------------- integer::eeny = 4, meeny = 3, myny = 5, moh = 6

eeny = eeny + 1 if(eeny == meeny + moh / meeny)then print *, 'Jelly' end if

eeny = eeny + 1 if(eeny == meeny)then print *, 'Sherbert' endif

if( (moh >= 6) .and. (myny + moh > 5) .and. & ( (5 + moh) <= (6 + myny) ) )then if(moh == 7)then print *, 'Carrott Cake' else print *, 'Ice Scream' end if end if

if((moh - myny - 1) /= 1)then print *, 'Corn Flakes' else print *, 'Angel Food Cake' end if !-------------------------------------------------------------------stop 'q1a.f90 ends' END PROGRAM q1a

Q1 continues

Q1b[ 8 marks] What is the output of the following Fortran90 program for each of the following cases: m Í 45, n Í 15; m Í 36, n Í 24; m Í 15, n Í 28? Can you deduce what IT is in this program? NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM q1b implicit none

integer::m, n, r, q !------------------------------------------------------------------- write(*,'(A)',advance='no')'gimmee an integer m --->' read , m write(,'(A)',advance='no')'gimmee an integer n --->' read *, n

do q = m / n r = mod(m, n) if(r == 0)then print*, 'so there it is --->', n, ' is IT' exit end if m = n n = r end do !------------------------------------------------------------------- stop'q1b.f90 ends ...' END PROGRAM q1b

Q1c[ 8 marks] What is the purpose of the following programming? Test it with the values 12, 15, 17, 35 and others if necessary. Find what is IT in each case. Deduce from your findings what the code does. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM q1c implicit none

integer::m, k logical::gotIT = .false. !------------------------------------------------------------------- write(*,'(A)',advance='no')'gimmee an integer m --->' read *, m

k = m / 2 do if(k <= 1)exit if(mod(m, k) == 0)then gotIT = .true. exit end if k = k - 1 end do print* if(gotIT)then print, 'so there it is --->', k, ' is IT' else print, 'so there is NO IT at all' end if print* !------------------------------------------------------------------- stop'q1c.f90 ends ...' END PROGRAM q1c

Q1 ends

Q1e[ 8 marks] What is the purpose of the following Fortran90 program? Test it with the values 12, 123, 12345, 1234567 and others if necessary. Find what is WhatIsThis in each case. Deduce from your findings what the code does. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

PROGRAM q1_e implicit none integer::theInteger, whatIsThis, aHolder, bHolder !------------------------------------------------------------------- do write(, '(a)', advance='no')'gimmee an integer (0 to end)---> ' read, theInteger if(theInteger == 0)exit aHolder = theInteger bHolder = 0 do bHolder = bHolder * 10 + mod(aHolder, 10) aHolder = aHolder / 10 if(aHolder == 0)exit end do whatIsThis = bHolder

write(*,10) theInteger, ' ---> ', whatIsThis end do

10 format(1x, i15, a, i15) !------------------------------------------------------------------- stop'q1_e.f90 ends ...' END PROGRAM q1_e

Q2 ends

Q2[ 30 marks]

The exam data for an important class are stored in the file f:\myExperiment\dse1Data.dat. The data is raw(without any explanatory text or headings) and each line contains the following data: surname, firstname, homework, exam_1, exam_2, final_exam as shown in fig 2.1 below where

  • homework is the total mark(max 540)gained from homework assignments,.
  • exam_1, exam_2 are the marks earned(max 100) in two exams held Christmas and Eastert
  • final_exam is the mark(max 150) for the final exam

Please write a Fortran90 program to connect to this file, to read the data for each student, calculate for that student a final grade based on 45% for homework, 30% for Christmas and Easter exams and 25% for the final exam

final_grade Í 25

_

_ 1 _ 2

 homework exam exam final exam

and to transfer all the data to the screen in the tabular form with headings as shown if fig. 2.2 below and append below the table detail of the mean and standard deviation( definitions given in fig 2.3 , the maximum and minimum of the final grades awarded.

Cooper Dave 535 90 95 145 Murphy Mary 500 65 89 135 Kelleher John 250 88 89 110 O'Sullivan Fred 400 66 73 100

Fig 2.

Enter name of data file: e:\q2.dat

name homework exam 1 exam 2 final exam final score ============================ ======== ====== ====== ========== =========== Cooper Dave 535 90 95 145 72. Murphy Mary 500 65 89 135 76. Kelleher John 250 88 89 110 60. O'Sullivan Fred 400 66 73 100 64.

average FinalGrade: 68. standard deviation FinalGrade: 6. maximum FinalGrade: 76. minimum FinalGrade: 60.

Press any key to continue

Fig 2.

For data

the mean x and the standard deviation s are given by

x (^) 1 , x 2 , x 3 ,..., x n

n

x

x

n

i

i = =^1

( ) ( ) 1 2

2

1

2

(^2) x n

x

n

x x s

n

i

i

n

i

i = −

∑ ∑ = =

Fig 2.

Q5 ends

Q5[ 30 marks]

Please answer each of the following questions.

Q5a(15 marks) Write , in module form, a function theDistance() to compute the distance between two points on a plane together with a driver to test it. The function will have four real numbers as parameters(the x and y coordinates of the two points) and it will return a real value (the distance between the two points. Thus getTheResult = theDistance (0.0, 0.0, 3.0, 4.0) will result in the variable getting the value 5.0. Note: (though I hardly need to?) The distance between the two points ( x 1 (^) , y 1 )and ( x (^) 2 , y 2 )is given by

( ) ( 2 1 )

2

x 2 − x 1 − y − y

and the sqrt() function returns the square root of a real.

Q5b(15 marks) Write, in module form, a function coolingState(yourTemperature) which will return the result of applying Cooper’s Social Rules(detailed below) to your temperature in °C. Include with it a driver to test it. e.g. coolingState( 65.43) Î ‘Gleaming’ coolingState(123.45) Î ‘Dripping

Doug Cooper once quoted the following ‘Genius, according to Thomas Edison, is 2% inspiration and 98% perspiration. Nowadays, of course, perspiration is usually socially inappropriate, except for men and horses. Alternative terms - sweating, glowing, dripping - exist, and it is important to know when to use them, regardless of the consequences to genius.’ Accordingly Cooper’s social secretary formulated the following rules for all students’ guidance:

Temperature ° C Cooling Mechanism

over 100o^ Dripping

o

to 100

o

Sweating

81 o^ to 90o^ Perspiring

71 o^ to 80o^ Glowing

61 o^ to 70o^ Gleaming

51 o^ to 60o^ Cool

under 60 ° Cold

appendix

QUADRATURE: approximating Definite Integrals

Let the interval (a, b) be divided into n intervals of width h by the points

x 1 , x 2 , x 3 ,..., xn − 1

Let

x 0 = a , xn = b

Let

m 1 , m 2 , m 3 ,..., m n

be the mid-points of the intervals ending at

x 1 , x 2 , x 3 ,..., x n

Three simple quadratures that approximate

b

x a

f ( x ) dx

are

Mid-Point Rule:

∫ =^ ∑

n

k

k

b

x a

f x dx h f m

Trapezoidal Rule

∫ =^ ∑

= =

1

1

n

k

k

b

x a

f x

f a f b

f x dx h

Simpson’s Rule

∫ =^ + + ∑ ∑

=

=

=

1

1 ( 2 )

2

2 ( 2 )

n

k

k

n

k

k

b

x a

f a f b f x f x

h

f x dx

None of these can hold a candle to Gaussian Quadrature but they are useful to play

with

a= x 0 x 1 x 2 x 3 x 4 b= xn

m 1 m 2 m 3 m 4 m 5 mn

xn-