Fortran90 Programming for Mech Eng Students - Computing & Numerical Methods, Exams of Mathematical Methods for Numerical Analysis and Optimization

Information about a bachelor of engineering (honours) in mechanical engineering exam from cork institute of technology, autumn 2006. The exam focuses on computing and numerical methods and includes three hours of questions based on fortran90 programming. The instructions for the exam, including the examiners' names, and includes several fortran90 programs that need to be analyzed or written. The programs cover topics such as logical statements, triangle classification, and statistical analysis.

Typology: Exams

2012/2013

Uploaded on 04/13/2013

pannaaaa
pannaaaa 🇮🇳

4.8

(6)

68 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cork Institute of Technology
Bachelor of Engineering (Honours) in Mechanical Engineering- Stage 1
(NFQ Level 8)
Autumn 2006
Computing and Numerical Methods
Time: 3 Hours
Instructions:
Answer Question 1 and two others Examiners: Ms. J.English
Prof. M. Gilchrist
Mr. J. E. Hegarty
Q1 (40 marks) Please answer each of the following questions:
Q1 (a) (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 q1a
implicit none
integer :: a = 12, b = 9, c= 8
if ( (b /= 10) .and. (b /= 20) )then
if ( 0 /= a)then
print*, "*A"
else
print*, "*B"
end if
end if
a = a + 1
if( (a == b) .and. (b > c) )then
print*, "*C"
end if
if( (a <= b) .and. (b <= c) )then
print*, "*D"
end if
if(( a < b).or.(b < c )) then
print *, "*E"
end if
stop ’q1a is ending …’
end program q1a
pf3
pf4
pf5

Partial preview of the text

Download Fortran90 Programming for Mech Eng Students - Computing & Numerical Methods and more Exams Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Cork Institute of Technology

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

(NFQ Level 8)

Autumn 2006

Computing and Numerical Methods

Time: 3 Hours

Instructions: Answer Question 1 and two others Examiners: Ms. J.English Prof. M. Gilchrist Mr. J. E. Hegarty

Q1 (40 marks) Please answer each of the following questions:

Q1 (a) (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 q1a implicit none integer :: a = 12, b = 9, c= 8

if ( (b /= 10) .and. (b /= 20) )then if ( 0 /= a)then print, "A" else print, "B" end if end if

a = a + 1 if( (a == b) .and. (b > c) )then print, "C" end if

if( (a <= b) .and. (b <= c) )then print, "D" end if

if(( a < b).or.(b < c )) then print , "E" end if

stop ’q1a is ending …’ end program q1a

Q1 (b) (8 marks)

What is the output of the following Fortran90 program? Test it with the following inputs 6,4,2 0. NOTE: Trace your working so that partial credit may be given for incomplete or incorrect work.

Q1 (c) ( 8 marks)

Write a program that reads triples of real numbers and assigns the appropriate value of true or false to
the following logical variables:
Triangle: True if the real numbers can represent lengths of the sides of a triangle and false
otherwise (the sum of any two of the numbers must be greater than the third)
Equilateral: True if Triangle is true and the triangle is equilateral (the three sides are equal)
Isosceles: True if Triangle is true and the triangle is isosceles (at least two sides are equal)
Scalene: True if Triangle is true and the triangle is scalene (no two sides are equal)

program q1b implicit none integer value, k, j logical result

do write(*, '(a)', advance='no')'gimmee a starting value --->' read *, value write( *,15, advance='no') value

if( 0 == value)exit result = (value >= 0) value = abs(value)

do k = value -2, 0, - do j = k, -k, - if (result) then write( *,10, advance='no') j else write( *,10, advance='no') -j end if end do result = .not.(result) end do

print* end do

print*

10 format( i3 ) stop 'q1b ends --->' end program q1b

Q2 (30 marks) Please answer each of the following questions:

Q2.(a) (10 marks)

Write a function that receives a positive integer n and returns true if n is a prime, and false if n is not a prime number. A prime number is a number that is divisible only by itself and 1. For example , if 15 is received, the function returns false; if 13 is received, the function returns true.

Q2. (b) (20 marks)

The data for this statistical analysis are stored in the file C:\StatsExperiment\myData.dat.The data is raw (without any explanatory text or headings) and each line contains a single x value as shown in fig. 2b_ below. The end of the file is signalled by the number -99. You are required to write a program to connect to this file and perform the following analysis on the data it contains. (i) Count the number of values in the file. (ii) Calculate the mean of the data in the file. (iii) Count the number of values less than the mean value and the number of values greater than the mean value Your program should then output the relevant results to the screen and also output the results to the file C:\StatsExperiment\myResults.dat.

23 27 15 56 48 21 10 18 78 34 89 56 20 17 67 31

fig. 2b_

The mean of numbers x 1 , x 2 ,..., xn can be calculated using the following formulas:

mean =

1

n

i i

x

n =

Q3(30 marks) Please answer each of the following questions.

Q3(a) (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 = 3.5 x^3 − 2.4 x^2 + 3.8 x −2.

dy (^) f | (^) ( ) x 10.5 x (^2) 4.8 x 3. dx

Q3(b) (12 marks)

Write a Fortran90 subroutine module to implement the NewtonRaphson Root Finding Algorithm,

SUBROUTINE NewtonRaphson(MaIter,root)

Note:

  • The Newton_Raphson method uses both the function f(x) and the function fPrime (i.e. the derivative of f)
  • tol is the user-specified degree of accuracy(We’re happy with the root at x if abs root ( − x ) ≤ tol ),
  • that we put a limit , maxIter , on the number of iterations the subroutine performs
  • an initial approximation is assigned to the variable x at the beginning of the program.
  • the approximation of the root is returned by root
Q3(c) (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

Q4 (30 marks) Please answer each of the following questions:

Q4. (a) (10 marks)

Write a Fortran90 program that accepts a positive integer N and outputs to the screen the first N powers of 3:

3 ,3 ,3 ,.....,3^1 2 3 N

Q4. (b) (10 marks)

The sequence of Fibonacci numbers begins with the integers

1,1,2,3,5,8,13,21,……..

where each number after the first two is the sum of the two preceding numbers. Write a Fortran90 program that reads a positive integer n and then displays the first n Fibonacci numbers to the screen.

Q4. (c) (10 marks)

Write a Fortran90 program that will input n integers (the number of values to be entered is to be specified by the user). The program can use –999 as the end-of-input marker. The program should then sort the list of integers in ascending order and output the sorted list to the screen.