Assignment 4 - 2010
Due date(s): | 08 November 2010 |
![]() |
Assignment questions |
![]() |
Solutions, prepared by Ali and Kevin |
Other instructions | Hand-in at class. |
<rst> <rst-options: 'toc' = False/> <rst-options: 'reset-figures' = False/> .. |m3| replace:: m\ :sup:`3`
.. rubric:: Questions 1, 2 and 3 will be posted at the end of the semester in assignment 4(a).
.. rubric:: Solutions by Kevin and Ali
Question 4 [2]
==
.. Similar to Tutorial 8, 2009
The viscosity of sulphuric acid, :math:`\nu`, varies with purity, :math:`p` in the following manner:
======================== ===== =====
- math:`p` [%] 20 60 80
----- ----- -----
- math:`\nu` [millipascal] 1.40 5.37 17.4
======================== ===== =====
- . Express :math:`\nu(p)` as a quadratic function using Lagrange interpolating polynomials. Do not simplify the polynomial.
- . Express :math:`\nu(p)` as a quadratic function using Newton interpolating polynomials. Do not simplify the polynomial.
- . Fit a cubic spline through the data points: clearly show your :math:`{\bf Xa = y}` linear system of equations, then solve them using computer software; finally report your spline coefficients.
- . Use computer software to plot:
* the Newton interpolating polynomial
* the cubic spline, * and the 3 data points on the same graph.
- . What is the estimated viscosity at :math:`p = 40\%` purity using linear interpolation?
- . Which of the estimation procedures that you used above has the closest estimate to the true value of 2.51 millipascal?
Solution
Redo the solution with these new values. The solution below is for old values.
- . Recall that an :math:`n-1` order Lagrange interpolating polynomial, for a set of :math:`n` data points, is given by the following relation:
.. math::
P_{n-1}(x) = y_{1}\ell_{1}(x) + y_{2}\ell_{2}(x) + \ldots + y_{n}\ell_{n}(x) = \sum_{i=1}^{n}y_{i}\ell_{i}(x) \qquad \text{where} \qquad \ell_{i}(x) = \prod_{j=1, j\neq i}^{n} \frac{x - x_{i}}{x_{i} - x_{j}}
For our system the quadratic Lagrange interpolating polynomial is the following:
.. math::
P_{2}(x) &= y_{1}\ell_{1}(x) + y_{2}\ell_{2}(x) + \ldots + y_{n}\ell_{n}(x) \ &= 1.40 \cdot \frac{(x-60)(x-80)}{(20-60)(20-80)} + 5.37 \cdot \frac{(x-20)(x-80)}{(60-20)(60-80)} + 17.4 \cdot \frac{(x-20)(x-60)}{(80-20)(80-60)}\
- . Recall that an :math:`n-1` order Newton interpolating polynomial, for a set of :math:`n` data points, is given by the following relation:
.. math::
P_{n-1}(x) = b_{0}+b_{1}(x-x_{1})+b_{2}(x-x_{1})(x-x_{2})+ \ldots +b_{n-1}(x-x_{1})\cdots(x-x_{n-1})
The coefficients, :math:`b_i` are best calculated in table form, known as "Newton's divided differences":
.. math::
So the Newton interpolating polynomial is:
.. math::
P_{2}(x) = 1.40 + 0.09925(x-x_{1}) + 0.008371(x-x_{1})(x-x_{2})
- . The cubic spline through 3 data points consists of two cubic polynomials -- one connecting points 1 and 2, and another connecting points 2 and 3.
.. math::
s_3(x) = \left\{
So we have 8 unknown coefficients in these 2 polynomials. The 8 linear equations that can be used to solve for the coefficients are:
.. math::
Expressing this as a linear system of equations, :math:`{\bf Xa = y}` (see the lecture notes for the matrix pattern):
.. math::
{\bf Xa} &= {\bf y} \
\left(
Solving this system of equations with computer software gives:
.. math::
s_3(x) = \left\{
Now we can estimate the number of cells at time 3, 5, and 7 hours. All we need is to see which of the above cubic polynomials are appropriate for each point:
- math:`2\leq x=3\leq 4\rightarrow` :math:`C(3)\approx 0.5809 -0.6537(3) + 0.4778(3)^2 -0.0103(3)^3=2.6411`
- math:`4\leq x=5\leq 6\rightarrow` :math:`C(5)\approx 3.6951 + -2.9895(5) + 1.0617(5)^2 + -0.0590(5)^3=7.9180`
The last point 7 is not within the domain of interpolation for any of the intervals. So, we need to extrapolate the last polynomial (which is the closet to :math:`x=7`):
- math:`C(7)\approx 3.6951 + -2.9895(7) + 1.0617(7)^2 + -0.0590(7)^3=14.5620`
The cubic spline is plotted below, followed by the code used to generate the estimate values.
.. figure:: ../che3e4/Assignments/Assignment-4/images/spline_q5.png :scale: 45 :align: center
- Note**: Polynomial coefficients in MATLAB and Python are sorted from the highest order to the lowest one, which is in the reverse direction we wrote the above polynomials. So, make sure you flip the coefficients (in the decreasing order) when using these polynomials in software.
.. twocolumncode:: :code1: ../che3e4/Assignments/Assignment-4/code/cubic_spline_5pts.m :language1: matlab :header1: MATLAB code :code2: ../che3e4/Assignments/Assignment-4/code/cubic_spline_5pts_python.py :language2: python :header2: Python code
Bonus question [0.5]
========
Use the cubic spline from the previous question and find the time where the cell count was approximately 10.0 g/L. Do not solve the equation by hand, but investigate `MATLAB's <http://www.mathworks.com/help/techdoc/ref/roots.html>`_ or `Python's <http://docs.scipy.org/doc/numpy/reference/generated/numpy.roots.html>`_ polynomial root finding function: ``roots(...)``
Solution
The value of :math:`C=10` falls between 4.95 (at :math:`t=4`) and 11.24 (at :math:`t=6`) in the table of experimental data . So, we use the last spline polynomial that represents the points in this range:
- math:`C(t)\approx 3.6951 + -2.9895(t) + 1.0617(t)^2 + -0.0590(t)^3=10.0 \rightarrow`
- math:`C(t)\approx -6.3049 + -2.9895(t) + 1.0617(t)^2 + -0.0590(t)^3=0`
This is a simple polynomial root finding problem which can be solved using either
- MATLAB: ``roots([-0.0590, 1.0617, -2.9895, -6.3049])``
- Python: ``np.roots([-0.0590, 1.0617, -2.9895, -6.3049])``
Since it is a cubic function, three roots are returned: :math:`t_1 = 13.7417, t_2 = 5.6336, t_3 = -1.3804`.
In order to decide which one is the desired solution, we again look at the tabulated data. Since the :math:`C` value falls between 4.95 and 11.24, the corresponding :math:`t` value must also fall between 4.0 and 6.0. So, the desired root is :math:`t_2 = 5.6336`.
.. raw:: latex
\vspace{0.5cm}
\hrule
</rst>