Week 5 MATH2089 Numerical Methods
Week 5 (T 1, 2021) This problem set is to be completed and submitted before 9am on the day of your next tutorial (e.g. Wednesday classes should submit this laboratory problems by 9am on Wednesday in week 6). Late submission penalty will apply. Submit all files (*.m file & scan or electronic note) through Week 5 Laboratory problems submission on Moodle. Question 1 The amplitude of vibration in the vertical direction of an automobile, after passing over a road bump, is found to be as follows:
Time, ti (sec)
0 0.64 1.28 1.92
Amplitude, ai (mm)
5 2 0.75 0.3
You are required to find an approximate value of the amplitude at specified values of time
using (a) hand calculations and (b) Matlab programming.
To do hand calculations you are required to perform the following tasks: 1. You are required to develop a Lagrange interpolation polynomial that passes through the
data (4 points) given in the table above. An example is given in Lecture Notes. 2. Use this polynomial to calculate the value of the amplitude at t=0.7 sec.
To find solution using Matlab you are required to perform the following tasks: 1. Write a function (m-file) in which you define your data for the time and amplitude. In
the same function calculate the amplitude at t=0.7 using Matlab function interp1(x,Y,x0) (description of this function can be found after Question 2). Use interpolation options in the interp1 function to specify linear (default) and spline interpolation (see an example in motor.m).
2. Create vector of data xi in the range from 0 to 2 with the step of 0.1. Calculate two sets of the values for the amplitude at specified values xi using linear and spline interpolation options in the interp1 function.
3. Plot original data (from the table) and two sets of the values for the amplitude calculated at specified values xi. Explain the differences between linear and spline interpolation. Which is more accurate?
Compare solutions obtained using Matlab with you hand calculations. Why do your hand calculations agree with spline interpolation result?
Question 2 A wind tunnel test conducted on an airfoil section yielded the following data between the lift coefficient (CL) and the angle of attack (?):
?, degrees 0 4 8 12 16 20 CL 0.11 0.55 0.95 1.40 1.71 1.38
You are required to develop a suitable polynomial relationship between ? and CL and fit a curve to the data points by the least-squares method using (a) hand calculations and (b) Matlab programming Hint: A quadratic equation (parabola) 20 1 2( )y x a a x a x= + + can be used in this case for curve fitting. The procedure of solution should be as follows: (a) Write a Matlab function to fit a quadratic equation to the data points. Create [A] and [b] according to your hand calculation, and use backslash operator x =
Ab to find a vector of unknowns 0
1
2
a a a
? ? ? ? ? ? ? ? ? ?
(b) Use Matlab functions polyfit( ) and polyval( ). Plot original data (from the table), function 20 1 2( )y x a a x a x= + + with coefficients obtained in (a); and values obtained using polyfit () at the same graph. (Dont forget to create a vector for the range [0 20]!). Explain the results.
MATLAB FUNCTIONS: yy=interp1(x, y, xx,linear) uses the data of x (values of the independent variable) and y (values of the dependent variable), fits a linear equation using least-squares technique, and gives the interpolated values of y(yy) at the specified values of x(xx). The word linear can be replaced by cubic, spline, or nearest to achieve interpolation based on cubic equation, cubic spline, or nearest value, respectively. If nothing is specified, linear interpolation is implied. p=polyfit(x, y, n) fits a least-squares polynomial of degree n for the specified set of data x and y. The coefficients of the polynomial are returned through the vector p. The elements of p denote the coefficients of the polynomial starting from that of the highest power of x.
y = polyval(p,x) returns the value of a polynomial of degree n evaluated at x. The input argument p is a vector of length n+1 whose elements are the coefficients in descending powers of the polynomial to be evaluated.
Recent Comments