lab 8 (1)
TRANSCRIPT
ENG1060 – Computing for Engineers
Laboratory No.8 Page 1 of 4
This laboratory comprises 2% of your final grade. During your lab session, you will be assessed on your programming style as well as the results produced by your programs. Save your work in M-Files called lab8t1.m, lab8t2.m etc The questions are designed to test your recollection of the lecture material up to and including week 9. Important Note:
1. Task 1 is a lengthy pen and paper exercise which is relevant to your exam preparation where a similar question in exam can be worth a lot more. You SHOULD complete Task 1 in your own time prior to the labs.
Task 1 – 1 mark
Consider the following function:
dxxxxxf ∫−
+−−=
4
2
52341)(
Evaluate f(x) for the following cases using pen and paper:
(a) analytically (b) single application of the trapezoidal rule (c) composite trapezoidal rule using 12 segments (d) single application of the Simpson’s 1/3 rule (e) composite application of the Simpson’s 1/3 rule using 12 segments (f) Simpson’s 3/8 rule
Faculty of Engineering
Semester 1 - 2014
ENG1060 Computing for Engineers
Laboratory No. 8
ENG1060 – Computing for Engineers
Laboratory No.8 Page 2 of 4
Task 2 – 2 marks Consider the following function:
∫−
=
5.1
5.1
)(334)( dxxCosxexxh
Using the following parameters in your function:
func: the function that you are required to integrate a, b: the integration limits n: the number of segments to be used for the integration I: Integral estimate
(a) Write a function capable of performing Numerical integration of h(x) using
composite trapezoidal rule (Do not use inbuilt ‘trapz’ function).
(b) Write a function capable of performing Numerical integration of h(x) using composite Simpson’s 1/3 rule.
Task 3 – 2 marks
Write an M-file capable of performing Numerical integration of h(x) using either the composite trapezoid rule or the Simpson’s 1/3 rule, written in Task 2.
- The program should ask the user to input which rule to use (e.g ‘1’ for
composite Trapezoid and ‘2’ for composite Simpson’s 1/3) - The program should then ask the user to enter the number of
segments, ‘n’ to be used for the integration and identify if the user has entered a wrong number of segments.
- The program should be interactive. That is, once user selects which rule to use and enters the number of segments ‘n’ (prompt user to enter number of segments again if ever a wrong value of ‘n was entered), the program should output the Integral and prompt the user to decide if they want to try again for different rule or number of segments. If yes, program should prompt the user again for which rule to select and input number of segments and calculate integral. If no, program should terminate.
ENG1060 – Computing for Engineers
Laboratory No.8 Page 3 of 4
Task 4 – 2 marks
(a) Write an M-file that calculates the minimum number of segments, n,
required to numerically integrate the function in Task 1 within an accuracy of 1% of the analytical solution using composite trapezoidal rule. (You can re-use the function you wrote for composite trapezoidal rule in task 3a)
(b) Modify the M-file from part (a) to calculates the minimum number of
segments, n, required to numerically integrate the function in Task 1 within an accuracy of 1% of the analytical solution using composite Simpson’s 1/3 rule. (You can re-use the function you wrote for composite trapezoidal rule in task 3a)
Task 5 – 3 marks
You work for an environmental engineering company and as part of your
job, you are required to estimate the volume of water in a small natural lake that is approximately 15m long and 10m wide. Your colleague measures a series of depths across the lake at various locations using an echosounder and reports the average depth a various locations along the width for 5m sections of the length as shown in the figure below.
The average depths along the width (ranging from 0-10m wide) for the three 5m sections along the length (0-5m ; 5-10m ; 10-15m) are given in the table below:
w (m) 0 1.0 3.5 5.0 6.0 7.0 8.0 8.5 9.3 10
0 – 5m 1 1.2 1.9 2.9 3.3 3.3 2.9 2.1 1.7 1.1
5 – 10m 0.9 1.3 1.9 2.5 2.6 2.9 2.4 1.5 1.4 0.5
10 – 15m 0.8 0.9 2.1 2.3 2.9 3.2 3.2 2.8 2.5 1.7
ENG1060 – Computing for Engineers
Laboratory No.8 Page 4 of 4
Write an M-file that does the following:
(a) Fits 3rd order polynomials (cubic fits) to the data (1 fit for each section along the length)
(b) Analytically calculated the total of volume of water in the lake by integrating the cubic fits from part (a). Note that your program should do so automatically.
(c) Evaluates the total volume of water in the lake using the composite trapezoidal rule with 10 segments and the cubic fits from part (a)
Hint: Once you get your cubit fit, you might want to generate a new set of
data to create 10 segments to be used for numerical integration part
Hint: If you have a cubic equation with constants p1 for the x3 part, then the
integral of that will be (p1 / 4) * x4.
Hint: Volume = cross-sectional area * length