SlideShare a Scribd company logo
ENG1060 – Computing for Engineers
Laboratory 7 Page 1 of 9
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 lab7t1.m, lab7t2.m etc
The questions are designed to test your recollection of the lecture material
up to and including lecture 14.
Note: Some of the functions presented would be new to you. You can use
the MATLAB help system to learn more about them.
Task 1
Write an M-file that uses the false position method to determine the mass of the
bungee jumper with a drag coefficient (cd) of 0.25kg/m to have a velocity of 36m/s
after 4s of free fall. (Note: acceleration due to Earth’s gravity is 9.81m/s2). Solve
the equation given below for m.
)(tanh)( tvt
m
gc
c
gm
mf d
d









Your M-file should prompt the user to enter the lower limit and upper limit and
check if the initial guesses bracket a root. If not, your program should prompt the
user for new guesses until the user provides values that do bracket the root.
Your M-file should print the iteration number, xl, xu, xr and f(xr) for each iteration.
Test your M-file for a precision of 0.5% using various initial guesses.
HINT: Substitute your root back into f(m) to check your answer
HINT: You can use graphical method to obtain initial guesses
HINT: You can reuse code provided on Moodle
Faculty of Engineering
Semester 1 - 2016
ENG1060 Computing for Engineers
Laboratory 7
ENG1060 – Computing for Engineers
Laboratory 7 Page 2 of 9
Task 2
Consider the following function:
10002008)( 23
 xxxxf
Locate the maximum of f(x) for x [-10, 10]. Do this by finding the root of the
derivative of this function. Use the Newton Raphson method to perform root finding.
Select the initial guess yourself after looking at f(x) graphically. Your solution
should achieve a precision of 0.01%. Plot f’(x) and the root on the same figure
Task 3
In a chemical engineering process, water vapor (H2O) is heated to sufficiently high
temperatures that a significant portion of the water dissociates, or splits apart, to
form oxygen (O2) and hydrogen (H2):
H2O« H2 +
1
2
O2
If it is assumed that this is the only reaction involved, the mole fraction, x, of H2O
that dissociates can be represented by:
Where K is the reaction’s equilibrium constant and pt is the total pressure of the
mixture.
If pt =3.5 atm and K = 0.04, write two M-files that uses
a) Bisection method to determine the value of x that satisfies the reaction
equation.
Your M-file should prompt the user to enter the lower limit and upper limit.
If the initial guesses do not bracket a root, your program should keep
prompting the user for new guesses until the user provides values that do
bracket the root.
Your M-file should print the iteration number, xl, xu, xr and f (xr) for each
iteration.
Test your M-file for a precision of 0.1%.

HINT: You can modify the root finding codes provided on Moodle
HINT: You can use graphical method to obtain initial guesses.
ENG1060 – Computing for Engineers
Laboratory 7 Page 3 of 9
b) Modified Secant method to determine the value of x that satisfies the
reaction equation.
Your M-file should prompt the user to enter the initial guess and
perturbation factor and print the root to 4 decimal places.
Test your M-file for a precision of 0.1% using various initial guesses.
HINT: You can modify the root finding codes provided on Moodle.
Task 4
You are designing a spherical tank (see figure below) of radius R = 3m, to hold
water for a remote village.
The volume of liquid it can hold can be computer as
where R is the tank radius, h is the depth of water and V is the volume of water
(a) Write an M-file to plot the function and then prompt the user to enter the
initial guess.
(b) In the same M-file, use Modified Secant function file to determine the
depth that the tank must be filled to, so that it holds 30m3 of water. Use a
precision of 0.001% and a perturbation of 0.01.
(c) Modify the modified secant function so that it outputs both the root and the
number of iterations. In the same M-file, print the number of iterations,
approximated root and fzero() root in Command Window.
ENG1060 – Computing for Engineers
Laboratory 7 Page 4 of 9
Task 5
A four-bar linkage system is shown above. The first link, a, is an input link (crank) of
length 1. The second link, b, is a coupler link of length 3. The third link, c, is an output
link of length 4. The forth link, d, is the fixed link (ground) of length 5. All lengths are
provided in metres.
The angular position of the output link () of a four-bar linkage corresponding to the
angular position of the input link () can be computed using the Freudenstein’s
equation:

The following parameters must be used for root finding:
x1120°, xu 165°, xi 120°, xi-1 110°, 0.01, precision of 0.05%.
a = 1; b = 3; c = 4; d = 5;
(a) Write an M-file to find the value of for  30°using the Newton-Raphson
method, Secant method and the Modified Secant method.
(Note: You may use MATLAB’s built-in function fzero() to check your
answer.)
(b) Plot the number of iteration versus the absolute percentage error. Use different
data marker and color for different method. Make certain that proper legend is
used.
(c) Compare the efficiencies of the Newton-Raphson method, Secant method and
the Modified Secant method. Which method requires the least iterations to
reach the required precision? Print your explanation in the Command Window
using short sentences. Use a new line for each sentence.
ENG1060 – Computing for Engineers
Laboratory 7 Page 5 of 9
Task 6
Many fields of engineering require accurate population estimates. For example,
transport engineers might find it necessary to determine separately the population
growth trends of a city and an adjacent suburb. Given that the population of a city is
declining with time according to
while the population of an adjacent suburb is growing according to
Using the following parameters:
Pc,end=75,000; kc=0.045/yr; Pc,start=100,000; Ps,end=300,000; Ps,start=10,000;
ks=0.08/yr;
Write an M-file to perform the following tasks:
(a) In order to determine the time when the suburb is 20% larger than the city, write
an anonymous function that define the root finding problem in the form of f(x)=0.
Plot a graph of f(x) where x covers 100 years period from the 1st year to the
100th year.
(b) Prompt the user to input the initial guess based on the graph plotted in (a).
(c) Use the False Position method to determine how many years later the suburb
is 20% larger than the city. Use a precision of 0.001%
(d) Assuming that the starting population of the city and suburb (Pc,start & Ps,start)
were recorded in year 2010, calculate which year (round to the nearest year)
the suburb is 20% larger than the city. Print a short sentence to show your
answer.
(e) Calculate the population of the city, Pc(t), and the suburb, Ps(t), when the
suburb is 20% larger than the city based on the answer in (c). Print another
short sentence to show these results.
ENG1060 – Computing for Engineers
Laboratory 7 Page 6 of 9
Optional (Ungraded Questions)
Task 7
The figure below shows a uniform beam of length, L, subject to a linearly increasing
distributed load, wo.
The equation for the resulting elastic curve is
where y is the deflection, wo is the distributed load, E is the Modulus of Elasticity
the material, I is the moment of inertia and /L is the length of the beam.
(a) Write an M-file that prompts the user to choose between using the False
Position Method or Newton-Raphson method. Both methods should be
prepared as user defined functions. (Note: At the end of the program, there
is no need to ask user if they want to try again)
(b) In the same M-file, write MATLAB program to determine the point of
maximum deflection to a precision of 1e-10 and the value of the maximum
deflection by finding the root of the derivative of the function (i.e find x where
dy/dx 0 and substitute x in the equation above to calculate y) given L =
0.6m, E = 50,000 kN/cm2, I = 30,000cm4, wo = 2.5kN/cm.
(c) Which method is provides a better solution? Justify your answer in less than
30 words. In the same M-file, print your answer in the Command Window
using fprintf() regardless of the choice of the user input.
ENG1060 – Computing for Engineers
Laboratory 7 Page 7 of 9
Note: Be careful with units
Task 8
A colleague new to MATLAB gave you the M-File lab7t8_bugs.m. Correct the
bugs in the file so that it performs modified secant correctly. Answer the questions
in bold as comments in your M-File.
(a) When I attempt to run the M-file, I got the following message:
??? Error: File: lab6t2_bugs.m Line: 17 Column: 34
Unbalanced or unexpected parenthesis or bracket.
At which line does this error occur? How do you correct this error?
(b) After correcting the error in part (a), I attempt to run the M-file again. This time
MATLAB complains about something else:
??? Undefined function or variable 'fxpx'.
Error in ==> lab6t2_bugs at 28
xi = xi-pert*xi*fxi/(fxpx-fxi); % Calculate new estimate
At which line does the real error occur? Why does the error occur? How
do you eliminate this error?
(c) After correcting the errors in part (b), I make my third attempt at running this M-
file. It gives me no error and printed the answer. 
The root of the equation is -Inf
Wait! The answer is wrong!!! 
Which line in the M-file is incorrect? What changes are required to obtain
correct answer? What was the mistake?
ENG1060 – Computing for Engineers
Laboratory 7 Page 8 of 9
Task 9
Aerospace engineers sometimes compute the trajectories of projectiles such as
rockets. A related problem deals with the trajectory of a thrown ball. The trajectory
of a ball is defined by the (x, y) coordinates as shown in the figure below.
The trajectory can be modeled as:
where is the angle in degrees, vo is the initial velocity, x is the distance from the
thrower to the catcher, y0 is the thrower’s elevation and y is the catcher’s elevation,
g is gravity (g = 9.81ms-2)
(a) Write a function that uses the secant method to calculate the root and
number of iterations to get the root. Your function should accept the function,
f, initial guesses xi, xi_1 and the precision as inputs.
function [root, iter] = secant (f,xi,xi_1,precision)
(b) Write an m-file that uses the function from part (a) to find the appropriate
initial throw angle and the number of iterations it takes to find the angle
given that vo = 20m/s ; x = 35m ; y0 = 2m; y = 1m and precision = 0.1%
Note: Your M-file should plot the trajectory path for 0 ≤ ≤ 60 and then prompt
the user to enter the initial guesses (they should be able to guess the initial values
after seeing the graph)
ENG1060 – Computing for Engineers
Laboratory 7 Page 9 of 9
Useful Information
When you demonstrate your work in this laboratory session, we will be looking out for
the following:
a) Does the code work accurately and work without intervention?
b) Are there indentations and comments explaining the functionality of the
code/function?
Hint:
% A comment field/line in MATLAB is always preceded
% with a ‘%’ symbol, after which it will turn green –
% indicating it is not a comment.
c) Are you able to create function which takes/outputs variables?
d) Are you able to perform root finding methods?
e) Are you able to justify which root finding method is better?
f) Are your functions/ iterations/ Program control statements properly indented?
After you have completed the demo. Please log on to Moodle and upload your files
there. You will only receive your demo marks if the corresponding files have been
uploaded.

More Related Content

What's hot

Optimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data PerspectiveOptimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data Perspective
পল্লব রায়
 
Statistical Physics Assignment Help
Statistical Physics Assignment HelpStatistical Physics Assignment Help
Statistical Physics Assignment Help
Statistics Assignment Help
 
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notes
pawanss
 
Transportation and assignment_problem
Transportation and assignment_problemTransportation and assignment_problem
Transportation and assignment_problemAnkit Katiyar
 
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZEAPPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
m.kumarasamy college of engineering
 
GATE Computer Science Solved Paper 2004
GATE Computer Science Solved Paper 2004GATE Computer Science Solved Paper 2004
GATE Computer Science Solved Paper 2004
Rohit Garg
 
Application of interpolation and finite difference
Application of interpolation and finite differenceApplication of interpolation and finite difference
Application of interpolation and finite difference
Manthan Chavda
 
Cmb part3
Cmb part3Cmb part3
Automatic Synthesis of Combiners in the MapReduce Framework
Automatic Synthesis of Combiners in the MapReduce FrameworkAutomatic Synthesis of Combiners in the MapReduce Framework
Automatic Synthesis of Combiners in the MapReduce Framework
Kinoshita Minoru
 
Parallel algorithm in linear algebra
Parallel algorithm in linear algebraParallel algorithm in linear algebra
Parallel algorithm in linear algebra
Harshana Madusanka Jayamaha
 
Ijetr042170
Ijetr042170Ijetr042170
Numerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final ProjectNumerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final Project
Stasik Nemirovsky
 
Stratified sampling and resampling for approximate Bayesian computation
Stratified sampling and resampling for approximate Bayesian computationStratified sampling and resampling for approximate Bayesian computation
Stratified sampling and resampling for approximate Bayesian computation
Umberto Picchini
 
Lecture6 spatial filtering (neighborhood operations) examples
Lecture6 spatial filtering (neighborhood operations) examplesLecture6 spatial filtering (neighborhood operations) examples
Lecture6 spatial filtering (neighborhood operations) examples
Marwa Ahmeid
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
Ajay Bidyarthy
 
AP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paperAP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paper
Eneutron
 
Cia iii 17 18 qp
Cia iii 17 18 qpCia iii 17 18 qp
Cia iii 17 18 qp
Shivaji Sinha
 
A Novel Cosine Approximation for High-Speed Evaluation of DCT
A Novel Cosine Approximation for High-Speed Evaluation of DCTA Novel Cosine Approximation for High-Speed Evaluation of DCT
A Novel Cosine Approximation for High-Speed Evaluation of DCT
CSCJournals
 

What's hot (20)

Optimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data PerspectiveOptimal Chain Matrix Multiplication Big Data Perspective
Optimal Chain Matrix Multiplication Big Data Perspective
 
MATLAB
MATLABMATLAB
MATLAB
 
Statistical Physics Assignment Help
Statistical Physics Assignment HelpStatistical Physics Assignment Help
Statistical Physics Assignment Help
 
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notes
 
Transportation and assignment_problem
Transportation and assignment_problemTransportation and assignment_problem
Transportation and assignment_problem
 
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZEAPPLICATION OF NUMERICAL METHODS IN SMALL SIZE
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
 
GATE Computer Science Solved Paper 2004
GATE Computer Science Solved Paper 2004GATE Computer Science Solved Paper 2004
GATE Computer Science Solved Paper 2004
 
Application of interpolation and finite difference
Application of interpolation and finite differenceApplication of interpolation and finite difference
Application of interpolation and finite difference
 
Cmb part3
Cmb part3Cmb part3
Cmb part3
 
Automatic Synthesis of Combiners in the MapReduce Framework
Automatic Synthesis of Combiners in the MapReduce FrameworkAutomatic Synthesis of Combiners in the MapReduce Framework
Automatic Synthesis of Combiners in the MapReduce Framework
 
Secante
SecanteSecante
Secante
 
Parallel algorithm in linear algebra
Parallel algorithm in linear algebraParallel algorithm in linear algebra
Parallel algorithm in linear algebra
 
Ijetr042170
Ijetr042170Ijetr042170
Ijetr042170
 
Numerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final ProjectNumerical Methods in Mechanical Engineering - Final Project
Numerical Methods in Mechanical Engineering - Final Project
 
Stratified sampling and resampling for approximate Bayesian computation
Stratified sampling and resampling for approximate Bayesian computationStratified sampling and resampling for approximate Bayesian computation
Stratified sampling and resampling for approximate Bayesian computation
 
Lecture6 spatial filtering (neighborhood operations) examples
Lecture6 spatial filtering (neighborhood operations) examplesLecture6 spatial filtering (neighborhood operations) examples
Lecture6 spatial filtering (neighborhood operations) examples
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
 
AP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paperAP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paper
 
Cia iii 17 18 qp
Cia iii 17 18 qpCia iii 17 18 qp
Cia iii 17 18 qp
 
A Novel Cosine Approximation for High-Speed Evaluation of DCT
A Novel Cosine Approximation for High-Speed Evaluation of DCTA Novel Cosine Approximation for High-Speed Evaluation of DCT
A Novel Cosine Approximation for High-Speed Evaluation of DCT
 

Similar to Laboratory 7

M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
infantsuk
 
Matlab solved tutorials 2017 june.
Matlab solved tutorials  2017 june.Matlab solved tutorials  2017 june.
Matlab solved tutorials 2017 june.
musadoto
 
FurtherInvestegationOnProbabilisticErrorBounds_final
FurtherInvestegationOnProbabilisticErrorBounds_finalFurtherInvestegationOnProbabilisticErrorBounds_final
FurtherInvestegationOnProbabilisticErrorBounds_finalMohammad Abdo
 
Further investegationonprobabilisticerrorbounds final
Further investegationonprobabilisticerrorbounds finalFurther investegationonprobabilisticerrorbounds final
Further investegationonprobabilisticerrorbounds final
Mohammad
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
anhlodge
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
Programming Homework Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
Programming Homework Help
 
International journal of applied sciences and innovation vol 2015 - no 1 - ...
International journal of applied sciences and innovation   vol 2015 - no 1 - ...International journal of applied sciences and innovation   vol 2015 - no 1 - ...
International journal of applied sciences and innovation vol 2015 - no 1 - ...
sophiabelthome
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Hoang Nguyen Phong
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
Amairullah Khan Lodhi
 
2nd Semester M Tech: Structural Engineering (June-2015) Question Papers
2nd  Semester M Tech: Structural Engineering  (June-2015) Question Papers2nd  Semester M Tech: Structural Engineering  (June-2015) Question Papers
2nd Semester M Tech: Structural Engineering (June-2015) Question Papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
MTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docxMTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docx
gilpinleeanna
 
DSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docxDSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docx
ParthDoshi66
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
rosemarybdodson23141
 
DSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdfDSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdf
ParthDoshi66
 
Application of thermal error in machine tools based on Dynamic Bayesian Network
Application of thermal error in machine tools based on Dynamic Bayesian NetworkApplication of thermal error in machine tools based on Dynamic Bayesian Network
Application of thermal error in machine tools based on Dynamic Bayesian Network
IJRES Journal
 
Propagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace ReductionPropagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace Reduction
Mohammad
 
ProbErrorBoundROM_MC2015
ProbErrorBoundROM_MC2015ProbErrorBoundROM_MC2015
ProbErrorBoundROM_MC2015Mohammad Abdo
 

Similar to Laboratory 7 (20)

M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
 
Matlab solved tutorials 2017 june.
Matlab solved tutorials  2017 june.Matlab solved tutorials  2017 june.
Matlab solved tutorials 2017 june.
 
FurtherInvestegationOnProbabilisticErrorBounds_final
FurtherInvestegationOnProbabilisticErrorBounds_finalFurtherInvestegationOnProbabilisticErrorBounds_final
FurtherInvestegationOnProbabilisticErrorBounds_final
 
Further investegationonprobabilisticerrorbounds final
Further investegationonprobabilisticerrorbounds finalFurther investegationonprobabilisticerrorbounds final
Further investegationonprobabilisticerrorbounds final
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
 
International journal of applied sciences and innovation vol 2015 - no 1 - ...
International journal of applied sciences and innovation   vol 2015 - no 1 - ...International journal of applied sciences and innovation   vol 2015 - no 1 - ...
International journal of applied sciences and innovation vol 2015 - no 1 - ...
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer SheetPerspective in Informatics 3 - Assignment 2 - Answer Sheet
Perspective in Informatics 3 - Assignment 2 - Answer Sheet
 
Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual Digital Signal Processing Lab Manual
Digital Signal Processing Lab Manual
 
2nd Semester M Tech: Structural Engineering (June-2015) Question Papers
2nd  Semester M Tech: Structural Engineering  (June-2015) Question Papers2nd  Semester M Tech: Structural Engineering  (June-2015) Question Papers
2nd Semester M Tech: Structural Engineering (June-2015) Question Papers
 
Report
ReportReport
Report
 
MTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docxMTH 2001 Project 2Instructions• Each group must choos.docx
MTH 2001 Project 2Instructions• Each group must choos.docx
 
DSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docxDSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docx
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
DSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdfDSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdf
 
Application of thermal error in machine tools based on Dynamic Bayesian Network
Application of thermal error in machine tools based on Dynamic Bayesian NetworkApplication of thermal error in machine tools based on Dynamic Bayesian Network
Application of thermal error in machine tools based on Dynamic Bayesian Network
 
Propagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace ReductionPropagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace Reduction
 
ProbErrorBoundROM_MC2015
ProbErrorBoundROM_MC2015ProbErrorBoundROM_MC2015
ProbErrorBoundROM_MC2015
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Laboratory 7

  • 1. ENG1060 – Computing for Engineers Laboratory 7 Page 1 of 9 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 lab7t1.m, lab7t2.m etc The questions are designed to test your recollection of the lecture material up to and including lecture 14. Note: Some of the functions presented would be new to you. You can use the MATLAB help system to learn more about them. Task 1 Write an M-file that uses the false position method to determine the mass of the bungee jumper with a drag coefficient (cd) of 0.25kg/m to have a velocity of 36m/s after 4s of free fall. (Note: acceleration due to Earth’s gravity is 9.81m/s2). Solve the equation given below for m. )(tanh)( tvt m gc c gm mf d d          Your M-file should prompt the user to enter the lower limit and upper limit and check if the initial guesses bracket a root. If not, your program should prompt the user for new guesses until the user provides values that do bracket the root. Your M-file should print the iteration number, xl, xu, xr and f(xr) for each iteration. Test your M-file for a precision of 0.5% using various initial guesses. HINT: Substitute your root back into f(m) to check your answer HINT: You can use graphical method to obtain initial guesses HINT: You can reuse code provided on Moodle Faculty of Engineering Semester 1 - 2016 ENG1060 Computing for Engineers Laboratory 7
  • 2. ENG1060 – Computing for Engineers Laboratory 7 Page 2 of 9 Task 2 Consider the following function: 10002008)( 23  xxxxf Locate the maximum of f(x) for x [-10, 10]. Do this by finding the root of the derivative of this function. Use the Newton Raphson method to perform root finding. Select the initial guess yourself after looking at f(x) graphically. Your solution should achieve a precision of 0.01%. Plot f’(x) and the root on the same figure Task 3 In a chemical engineering process, water vapor (H2O) is heated to sufficiently high temperatures that a significant portion of the water dissociates, or splits apart, to form oxygen (O2) and hydrogen (H2): H2O« H2 + 1 2 O2 If it is assumed that this is the only reaction involved, the mole fraction, x, of H2O that dissociates can be represented by: Where K is the reaction’s equilibrium constant and pt is the total pressure of the mixture. If pt =3.5 atm and K = 0.04, write two M-files that uses a) Bisection method to determine the value of x that satisfies the reaction equation. Your M-file should prompt the user to enter the lower limit and upper limit. If the initial guesses do not bracket a root, your program should keep prompting the user for new guesses until the user provides values that do bracket the root. Your M-file should print the iteration number, xl, xu, xr and f (xr) for each iteration. Test your M-file for a precision of 0.1%.
 HINT: You can modify the root finding codes provided on Moodle HINT: You can use graphical method to obtain initial guesses.
  • 3. ENG1060 – Computing for Engineers Laboratory 7 Page 3 of 9 b) Modified Secant method to determine the value of x that satisfies the reaction equation. Your M-file should prompt the user to enter the initial guess and perturbation factor and print the root to 4 decimal places. Test your M-file for a precision of 0.1% using various initial guesses. HINT: You can modify the root finding codes provided on Moodle. Task 4 You are designing a spherical tank (see figure below) of radius R = 3m, to hold water for a remote village. The volume of liquid it can hold can be computer as where R is the tank radius, h is the depth of water and V is the volume of water (a) Write an M-file to plot the function and then prompt the user to enter the initial guess. (b) In the same M-file, use Modified Secant function file to determine the depth that the tank must be filled to, so that it holds 30m3 of water. Use a precision of 0.001% and a perturbation of 0.01. (c) Modify the modified secant function so that it outputs both the root and the number of iterations. In the same M-file, print the number of iterations, approximated root and fzero() root in Command Window.
  • 4. ENG1060 – Computing for Engineers Laboratory 7 Page 4 of 9 Task 5 A four-bar linkage system is shown above. The first link, a, is an input link (crank) of length 1. The second link, b, is a coupler link of length 3. The third link, c, is an output link of length 4. The forth link, d, is the fixed link (ground) of length 5. All lengths are provided in metres. The angular position of the output link () of a four-bar linkage corresponding to the angular position of the input link () can be computed using the Freudenstein’s equation:  The following parameters must be used for root finding: x1120°, xu 165°, xi 120°, xi-1 110°, 0.01, precision of 0.05%. a = 1; b = 3; c = 4; d = 5; (a) Write an M-file to find the value of for  30°using the Newton-Raphson method, Secant method and the Modified Secant method. (Note: You may use MATLAB’s built-in function fzero() to check your answer.) (b) Plot the number of iteration versus the absolute percentage error. Use different data marker and color for different method. Make certain that proper legend is used. (c) Compare the efficiencies of the Newton-Raphson method, Secant method and the Modified Secant method. Which method requires the least iterations to reach the required precision? Print your explanation in the Command Window using short sentences. Use a new line for each sentence.
  • 5. ENG1060 – Computing for Engineers Laboratory 7 Page 5 of 9 Task 6 Many fields of engineering require accurate population estimates. For example, transport engineers might find it necessary to determine separately the population growth trends of a city and an adjacent suburb. Given that the population of a city is declining with time according to while the population of an adjacent suburb is growing according to Using the following parameters: Pc,end=75,000; kc=0.045/yr; Pc,start=100,000; Ps,end=300,000; Ps,start=10,000; ks=0.08/yr; Write an M-file to perform the following tasks: (a) In order to determine the time when the suburb is 20% larger than the city, write an anonymous function that define the root finding problem in the form of f(x)=0. Plot a graph of f(x) where x covers 100 years period from the 1st year to the 100th year. (b) Prompt the user to input the initial guess based on the graph plotted in (a). (c) Use the False Position method to determine how many years later the suburb is 20% larger than the city. Use a precision of 0.001% (d) Assuming that the starting population of the city and suburb (Pc,start & Ps,start) were recorded in year 2010, calculate which year (round to the nearest year) the suburb is 20% larger than the city. Print a short sentence to show your answer. (e) Calculate the population of the city, Pc(t), and the suburb, Ps(t), when the suburb is 20% larger than the city based on the answer in (c). Print another short sentence to show these results.
  • 6. ENG1060 – Computing for Engineers Laboratory 7 Page 6 of 9 Optional (Ungraded Questions) Task 7 The figure below shows a uniform beam of length, L, subject to a linearly increasing distributed load, wo. The equation for the resulting elastic curve is where y is the deflection, wo is the distributed load, E is the Modulus of Elasticity the material, I is the moment of inertia and /L is the length of the beam. (a) Write an M-file that prompts the user to choose between using the False Position Method or Newton-Raphson method. Both methods should be prepared as user defined functions. (Note: At the end of the program, there is no need to ask user if they want to try again) (b) In the same M-file, write MATLAB program to determine the point of maximum deflection to a precision of 1e-10 and the value of the maximum deflection by finding the root of the derivative of the function (i.e find x where dy/dx 0 and substitute x in the equation above to calculate y) given L = 0.6m, E = 50,000 kN/cm2, I = 30,000cm4, wo = 2.5kN/cm. (c) Which method is provides a better solution? Justify your answer in less than 30 words. In the same M-file, print your answer in the Command Window using fprintf() regardless of the choice of the user input.
  • 7. ENG1060 – Computing for Engineers Laboratory 7 Page 7 of 9 Note: Be careful with units Task 8 A colleague new to MATLAB gave you the M-File lab7t8_bugs.m. Correct the bugs in the file so that it performs modified secant correctly. Answer the questions in bold as comments in your M-File. (a) When I attempt to run the M-file, I got the following message: ??? Error: File: lab6t2_bugs.m Line: 17 Column: 34 Unbalanced or unexpected parenthesis or bracket. At which line does this error occur? How do you correct this error? (b) After correcting the error in part (a), I attempt to run the M-file again. This time MATLAB complains about something else: ??? Undefined function or variable 'fxpx'. Error in ==> lab6t2_bugs at 28 xi = xi-pert*xi*fxi/(fxpx-fxi); % Calculate new estimate At which line does the real error occur? Why does the error occur? How do you eliminate this error? (c) After correcting the errors in part (b), I make my third attempt at running this M- file. It gives me no error and printed the answer.  The root of the equation is -Inf Wait! The answer is wrong!!!  Which line in the M-file is incorrect? What changes are required to obtain correct answer? What was the mistake?
  • 8. ENG1060 – Computing for Engineers Laboratory 7 Page 8 of 9 Task 9 Aerospace engineers sometimes compute the trajectories of projectiles such as rockets. A related problem deals with the trajectory of a thrown ball. The trajectory of a ball is defined by the (x, y) coordinates as shown in the figure below. The trajectory can be modeled as: where is the angle in degrees, vo is the initial velocity, x is the distance from the thrower to the catcher, y0 is the thrower’s elevation and y is the catcher’s elevation, g is gravity (g = 9.81ms-2) (a) Write a function that uses the secant method to calculate the root and number of iterations to get the root. Your function should accept the function, f, initial guesses xi, xi_1 and the precision as inputs. function [root, iter] = secant (f,xi,xi_1,precision) (b) Write an m-file that uses the function from part (a) to find the appropriate initial throw angle and the number of iterations it takes to find the angle given that vo = 20m/s ; x = 35m ; y0 = 2m; y = 1m and precision = 0.1% Note: Your M-file should plot the trajectory path for 0 ≤ ≤ 60 and then prompt the user to enter the initial guesses (they should be able to guess the initial values after seeing the graph)
  • 9. ENG1060 – Computing for Engineers Laboratory 7 Page 9 of 9 Useful Information When you demonstrate your work in this laboratory session, we will be looking out for the following: a) Does the code work accurately and work without intervention? b) Are there indentations and comments explaining the functionality of the code/function? Hint: % A comment field/line in MATLAB is always preceded % with a ‘%’ symbol, after which it will turn green – % indicating it is not a comment. c) Are you able to create function which takes/outputs variables? d) Are you able to perform root finding methods? e) Are you able to justify which root finding method is better? f) Are your functions/ iterations/ Program control statements properly indented? After you have completed the demo. Please log on to Moodle and upload your files there. You will only receive your demo marks if the corresponding files have been uploaded.