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 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)

74 documents

1 / 6

Toggle sidebar

Related documents


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, -1 do j = k, -k, -1 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 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 3 2( ) 3.5 2.4 3.8 2.1y f x x x x= = − + − | 2( ) 10.5 4.8 3.8dy f x x x 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: 1 2 33 ,3 ,3 ,.....,3N 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.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved