Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HEY NEED URGENT HELP IN THIS MATLAB ASSIGNMENT with all codes and full details (qns 3 and 4) 3. 4. Lagrange Interpolation Errors Recall, if
HEY NEED URGENT HELP IN THIS MATLAB ASSIGNMENT with all codes and full details (qns 3 and 4)
3.
4.
Lagrange Interpolation Errors Recall, if polynomial interpolation of order p is used to approximate a function f : [a, b] R, with nodal points (xo, ... , Xp], then for sufficiently smooth f , we have fP+1)(E) max, Pp() f(a)| s max max IT;(2 2;). EE[a,b] | (P + 1)! | @E[a,b] 3 Write a function m-file called lagrangeErrors that when run will compute (an approximation to) the error maxxe[a,b] \Pp;(x) = f(x)] for a range of polynomial degrees P {P;}}=1. Hint: In order to find an approximation to the error, eval- uate the error |Pp(2) f(x) for 2000 equally spaced points over [a, b] and take the maximum of those. = 0 The function should return a vector E of length 1, filled with the errors so that E; = max.ce[a,b] \Pp;(x) f(x)]. The function should make use of polyInterpolation.m from Q2 to compute the interpolant. i.e. equally spaced nodal points should be used to construct the interpolant. The function should also plot the errors {E}}}= against {P;}}=1, using semilogy. This plot should have all appropriate labels and legends. Add a description at the top of your lagrangeErrors.m that when 'help la- grangeErrors' is typed will comment on the results when P. {1, 2, 3, ..., 10} and (a) f(x) = 22, [a, b] = [0, 1]; (b) f(x) = 1+2572, [a, b] = (-5,5). The function should have the following prototype function E = lagrangeErrors (a,b,P, f) Test your function (for example) by typing the following into the command win- dow. P = 1:5; = -1; b = 1; E = lagrangeErrors (a,b,P,Q(x)1./(x+2)) a In this case you should obtain E= 0.1786 0.0463 0.0137 0.0043 0.0014. Marks can be obtained for your lagrangeErrors m-file for generating the re- quired output, for certain set(s) of inputs, as well as the plots and comments. The correctness of the following will be checked: The size and values of E; The error plots produced; The output of "help lagrangeErrors and in particular the quality of explanation for the outputs seen. (Run the file GenerateYourOutputsCw3.m to see these outputs generated for a particular set of inputs. Note that in marking your work, different input(s) may be Piecewise Polynomial Interpolation Recall, given a function f : [a, b] + R, we can construct its piecewise polynomial interpolant of order p by splitting [a, b] up into uniform subintervals of width h and applying the Lagrange interpolant of order p on each subinterval. Hence, using n subintervals { [Li1, X]}}=-1, the piecewise interpolant Sy(x) satisfies: Sp (x)|(1:-1,7i] = p)(x), i ?, 7 where p(x) is the polynomial interpolant of f(x) on [Xi1, Xi]. 4 Write a function m-file called piecewiseInterpolation that given an interval [a, b] will compute the piecewise polynomial approximation of order p of a function f(x) with n uniformly spaced subintervals of width h. Your function should make use of polyInterpolation from Q2 on each subinterval. Also add a brief description at the top of your piecewiseInterpolation m-file. This description should become visible whenever one types: help piecewiseInterpolation. The function must have the following prototype: function p_interp piecewiseInterpolation(a,b,p,n,xhat, f) Here xhat is a vector of points (assumed in the interval [a, b]) at which the piece- wise interpolant should be evaluated. On return, p_interp should hold these interpolant values. Test your function (for example) by typing the following into the command win- dow. P = 2; -1; b = 1; n 5; xhat = linspace (-0.9,0.9,7); P-interp piecewiseInterpolation(a,b,p,n,xhat , Q(x) 1./(x+2)) In this case you should obtain p-interp = 0.9107 0.7143 0.5878 0.5000 0.4349 0.3846 0.3448 Marks can be obtained for your piecewiseInterpolation m-file for gener- ating the required output, for certain set(s) of inputs. The correctness of the following will be checked: The size and values p-interp. The output of "help piecewiselnterpolation". (Run the file GenerateYourOutputsCW3.m to see these outputs generated for a particular set of inputs. Note that in marking your work, different input(s) may be used.) Lagrange Interpolation Errors Recall, if polynomial interpolation of order p is used to approximate a function f : [a, b] R, with nodal points (xo, ... , Xp], then for sufficiently smooth f , we have fP+1)(E) max, Pp() f(a)| s max max IT;(2 2;). EE[a,b] | (P + 1)! | @E[a,b] 3 Write a function m-file called lagrangeErrors that when run will compute (an approximation to) the error maxxe[a,b] \Pp;(x) = f(x)] for a range of polynomial degrees P {P;}}=1. Hint: In order to find an approximation to the error, eval- uate the error |Pp(2) f(x) for 2000 equally spaced points over [a, b] and take the maximum of those. = 0 The function should return a vector E of length 1, filled with the errors so that E; = max.ce[a,b] \Pp;(x) f(x)]. The function should make use of polyInterpolation.m from Q2 to compute the interpolant. i.e. equally spaced nodal points should be used to construct the interpolant. The function should also plot the errors {E}}}= against {P;}}=1, using semilogy. This plot should have all appropriate labels and legends. Add a description at the top of your lagrangeErrors.m that when 'help la- grangeErrors' is typed will comment on the results when P. {1, 2, 3, ..., 10} and (a) f(x) = 22, [a, b] = [0, 1]; (b) f(x) = 1+2572, [a, b] = (-5,5). The function should have the following prototype function E = lagrangeErrors (a,b,P, f) Test your function (for example) by typing the following into the command win- dow. P = 1:5; = -1; b = 1; E = lagrangeErrors (a,b,P,Q(x)1./(x+2)) a In this case you should obtain E= 0.1786 0.0463 0.0137 0.0043 0.0014. Marks can be obtained for your lagrangeErrors m-file for generating the re- quired output, for certain set(s) of inputs, as well as the plots and comments. The correctness of the following will be checked: The size and values of E; The error plots produced; The output of "help lagrangeErrors and in particular the quality of explanation for the outputs seen. (Run the file GenerateYourOutputsCw3.m to see these outputs generated for a particular set of inputs. Note that in marking your work, different input(s) may be Piecewise Polynomial Interpolation Recall, given a function f : [a, b] + R, we can construct its piecewise polynomial interpolant of order p by splitting [a, b] up into uniform subintervals of width h and applying the Lagrange interpolant of order p on each subinterval. Hence, using n subintervals { [Li1, X]}}=-1, the piecewise interpolant Sy(x) satisfies: Sp (x)|(1:-1,7i] = p)(x), i ?, 7 where p(x) is the polynomial interpolant of f(x) on [Xi1, Xi]. 4 Write a function m-file called piecewiseInterpolation that given an interval [a, b] will compute the piecewise polynomial approximation of order p of a function f(x) with n uniformly spaced subintervals of width h. Your function should make use of polyInterpolation from Q2 on each subinterval. Also add a brief description at the top of your piecewiseInterpolation m-file. This description should become visible whenever one types: help piecewiseInterpolation. The function must have the following prototype: function p_interp piecewiseInterpolation(a,b,p,n,xhat, f) Here xhat is a vector of points (assumed in the interval [a, b]) at which the piece- wise interpolant should be evaluated. On return, p_interp should hold these interpolant values. Test your function (for example) by typing the following into the command win- dow. P = 2; -1; b = 1; n 5; xhat = linspace (-0.9,0.9,7); P-interp piecewiseInterpolation(a,b,p,n,xhat , Q(x) 1./(x+2)) In this case you should obtain p-interp = 0.9107 0.7143 0.5878 0.5000 0.4349 0.3846 0.3448 Marks can be obtained for your piecewiseInterpolation m-file for gener- ating the required output, for certain set(s) of inputs. The correctness of the following will be checked: The size and values p-interp. The output of "help piecewiselnterpolation". (Run the file GenerateYourOutputsCW3.m to see these outputs generated for a particular set of inputs. Note that in marking your work, different input(s) may be used.)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started