Science:Math Exam Resources/Courses/MATH307/December 2012/Question 01 (e)
Work in progress: this question page is incomplete, there might be mistakes in the material you are seeing here.
• Q1 (a) • Q1 (b) • Q1 (c) • Q1 (d) • Q1 (e) • Q2 (a) • Q2 (b) • Q3 (a) • Q3 (b) • Q3 (c) • Q3 (d) • Q3 (e) • Q4 (a) • Q4 (b) • Q4 (c) • Q4 (d) • Q4 (e) • Q5 (a) • Q5 (b) • Q5 (c) • Q5 (d) • Q6 (a) • Q6 (b) • Q6 (c) • Q6 (d) • Q6 (e) • Q6 (f) •
Question 01 (e) |
---|
In this question we will work with polynomials of degree 3 written (e) Write down the MATLAB/OCTAVE code that plots the points (0,1), (1,2) and (2,2) and the polynomial p(x) that (i) has zero slopes at x = 0 and x = 2, (ii) comes closest in the least square sense to passing through the points (0,1), (1,2) and (2,2). |
Make sure you understand the problem fully: What is the question asking you to do? Are there specific conditions or constraints that you should take note of? How will you know if your answer is correct from your work only? Can you rephrase the question in your own words in a way that makes sense to you? |
If you are stuck, check the hints below. Read the first one and consider it for a while. Does it give you a new idea on how to approach the problem? If so, try it! If after a while you are still stuck, go for the next hint. |
Hint 1 |
---|
In part (d) we found that, in order for p(x) to have zero slope at x = 0 and x = 2 and pass through the given points, the coefficients would need to satisfy How can we find the least square solution of the system Cs = c above? |
Hint 2 |
---|
The least square solution s satisfies |
Checking a solution serves two purposes: helping you if, after having used all the hints, you still are stuck on the problem; or if you have solved the problem and would like to check your work.
|
Solution |
---|
Found a typo? Is this solution unclear? Let us know here.
Please rate my easiness! It's quick and helps everyone guide their studies. First, define the matrix C and the vector c C=[-4, -2; -2, 1; 0, 1]; c=[2; 2; 1]; Then solve the least squares equation Cs = c for s s=(C'*C)\(C'*c); % or s=inv(C'*C)*C'*c; Finally, from s we retrieve the coefficient vector a a_1 = [1; -3; 0; 0]; a_2 = [0; 0; 0; 1]; a = s(1)*a_1 + s(2)*a_2; This determines the function p(x) p = @(x) a(1)*x^3 + a(2)*x^2 + a(3)*x + a(4); All that is left now is to plot the points (0, 1), (1, 2) and (2,2) as well as the polynomial p(x) on the interval [0, 2]: hold on plot(0, 1, 'o') plot(1, 2, 'o') plot(2, 2, 'o') fplot(p, [0, 2]) % or eg plot(linspace(0, 2), p(linspace(0, 2))) |