User:Egm6341.s11.team5.shin/HW3

= Problem 3 - Plotting $$e_n^L(f,x), f_n^L(x), l_{i,n}(x), q_{n+1}(x)$$ = From (meeting 15 page 1)

Given
1. $$\displaystyle f(x)=\frac{e^x-1}{x} $$ on $$\displaystyle [-1,+1] $$, $$\displaystyle n=4 $$
 * $$\displaystyle t=5 $$, $$\displaystyle x=0.75 $$

2. $$\displaystyle f(x)=\frac{1}{1+4x^2} $$ on $$\displaystyle [-5,+5] $$, $$\displaystyle n=8 $$
 * $$\displaystyle t=4.5 $$, $$\displaystyle x=3 $$

Find
1.
 * Plot $$\displaystyle x \mbox{ vs. } f(x)$$, $$\displaystyle f_n^L(x)$$, $$\displaystyle e_n^L(x)$$, $$\displaystyle l_{i,n}(x)$$, $$\displaystyle q_{n+1}(x), n=4$$.
 * Plot $$\displaystyle l_{2,4}(\cdot)$$

2.
 * Plot $$\displaystyle x \mbox{ vs. } f(x)$$, $$\displaystyle f_n^L(x)$$, $$\displaystyle e_n^L(x)$$, $$\displaystyle l_{i,n}(x)$$, $$\displaystyle q_{n+1}(x), n=8$$.
 * Plot $$\displaystyle l_{3,8}(\cdot)$$

Addition
 * Find $$\displaystyle e_4^L(f,t)$$ and $$\displaystyle e_4^L(f,x)$$
 * Find $$\displaystyle e_8^L(f,t)$$ and $$\displaystyle e_8^L(f,x)$$

Solution
1. $$\displaystyle f(x)=\frac{e^x-1}{x}, x \in [-1,+1] $$
 * From the class notes (p.11-3), the Lagrangian interpolation error is defined as
 * {| style="width:100%" border="0" align="left"

e_4^L(f;x)=f(x)-f_4^L(x) $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-1)
 * }
 * ,where
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

f_4^L(x) = \sum_{i=0}^4 l_{i,4}(x)f(x_i) $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-2)
 * }
 * Also, the Lagrangian interpolation functions are defined as
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{i,4}(x)=\prod_{j=0}^4 \frac{x-x_j}{x_i-x_j} $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-3)
 * }
 * From the class notes (p.11-3), $$\displaystyle q_{5} $$ can be computed using the equation below.
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

q_{5}(x)=\prod_{i=0}^{4}(x-x_i) $$ $$ Plot:
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-4)
 * }
 * }
 * Nm1.s11.team5.HW3.fig3a.png]
 * Nm1.s11.team5.HW3.fig3b.png]
 * Nm1.s11.team5.HW3.fig3c.png]
 * Nm1.s11.team5.HW3.fig3d.png]

Matlab code:
 * {| style="width:100%" border="0" align="left"

Addition: Find $$\displaystyle e_4^L(f,t)$$ and $$\displaystyle e_4^L(f,x)$$, $$\displaystyle t=5, x=0.75 $$
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * Using Eq (3-1),(3-2) and (3-3), $$\displaystyle e_4^L(f,t)$$ and $$\displaystyle e_4^L(f,x)$$ can be computed.
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \begin{align} e_4^L(f,t)&=11.0239 \\ e_4^L(f,x)&=-1.6274 \times 10^{-4} \end{align} $$ Matlab code:
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"


 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }

2. $$\displaystyle f(x)=\frac{1}{1+4x^2}, x \in [-5,+5] $$
 * From the class notes (p.11-3), the Lagrangian interpolation error is defined as
 * {| style="width:100%" border="0" align="left"

e_8^L(f;x)=f(x)-f_8^L(x) $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-5)
 * }
 * ,where
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

f_8^L(x) = \sum_{i=0}^8 l_{i,8}(x)f(x_i) $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-6)
 * }
 * Also, the Lagrangian interpolation functions are defined as
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

l_{i,8}(x)=\prod_{j=0}^8 \frac{x-x_j}{x_i-x_j} $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-7)
 * }
 * From the class notes (p.11-3), $$\displaystyle q_{9} $$ can be computed using the equation below.
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

q_{9}(x)=\prod_{i=0}^{8}(x-x_i) $$ $$ Plot:
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (3-8)
 * }
 * }
 * Nm1.s11.team5.HW3.fig3e.png]
 * Nm1.s11.team5.HW3.fig3f.png]
 * Nm1.s11.team5.HW3.fig3g.png]
 * Nm1.s11.team5.HW3.fig3h.png]

Matlab code:
 * {| style="width:100%" border="0" align="left"

Addition: Find $$\displaystyle e_8^L(f,t)$$ and $$\displaystyle e_8^L(f,x)$$, $$\displaystyle t=4.5, x=3 $$
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * Using Eq (3-5),(3-6) and (3-7), $$\displaystyle e_8^L(f,t)$$ and $$\displaystyle e_8^L(f,x)$$ can be computed.
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \begin{align} e_8^L(f,t)&=1.784 \\ e_8^L(f,x)&=-0.3786 \end{align} $$ Matlab code:
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"


 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }

= Problem 4 - Area of a Bifolium = From (meeting 15 page 2)

Given
The bifolium: $$\displaystyle r(\theta)=2sin(\theta)cos^{2}(\theta)$$, where $$\displaystyle \theta=[0,\pi]$$.

Find
1. Do literature search to find history and application, if any, of this classic curve. 2. Find the area of one folium,with an accuracy of $$10^{-6}$$ by:
 * 2.1 Composite trapezoidal
 * 2.2 Composite Simpson
 * 2.3 Area of triangles

Solution
The bifolium has the following mathematical equation.
 * {| style="width:100%" border="0" align="left"

r(t)=2\sin(t)\cos^2(t) \mbox{, } t \in [0, \pi] $$ $$ In this problem, we're only interested in computing the area in one leaf, so $$\displaystyle t $$ will have the different range.
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-1)
 * }
 * }
 * $$\displaystyle t \in [0, \frac{\pi}{2}]$$

In order to apply composite Trapezoidal rule and composite Simpson's rule, we need to have the equation expressed in the Cartesian coordinate system. We have the following properties to obtain the equation defined in the Cartesian coordinate system.
 * {| style="width:100%" border="0" align="left"

\begin{align} \sin(t)&=\frac{y}{r} \\ \cos(t)&=\frac{x}{r} \\ r&=\sqrt{x^2+y^2} \end{align} $$ $$ Substitute Eq(4-2) to Eq(4-1) then, we have the following equation expressed in terms of $$\displaystyle x,y $$.
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-2)
 * }
 * }
 * {| style="width:100%" border="0" align="left"

(x^2+y^2)^2=2x^2y $$ $$ Before jumping into the calculation of area, it should be noted that the values that $$\displaystyle x $$ can take on are different from $$\displaystyle t \in [0,\frac{\pi}{2}]$$. But, it can be found out simply by running the following code. Matlab code:
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-3)
 * }
 * }
 * {| style="width:100%" border="0" align="left"

As a result, $$\displaystyle x $$ is in the range of the following.
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * $$\displaystyle x \in [0.0, 0.6495] $$

In order to obtain $$\displaystyle y $$ corresponding to $$\displaystyle x $$ in the range mentioned above, the following equation needs to be solved. The equation below is derived from Eq(4-3) by expanding out Eq(4-3) and expressing in terms of $$\displaystyle y $$.
 * {| style="width:100%" border="0" align="left"

y^4+2x^2y^2-2x^2y+x^4=0 $$ $$ Eq(4-4) is the 4th-order polynomial equation expressed in terms of $$\displaystyle y $$. In this equation, the terms expressed in $$\displaystyle x $$ will be considered as coefficients. Eq(4-4) can be solved using MATLAB command 'roots'. Area computed using Wolfram Alpha The area of one leaf in bifolium is $$\displaystyle \frac{\pi}{16} $$. (Refer to Wolfram Alpha) 1. Composite Trapezoidal rule
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-4)
 * }
 * }
 * From the class notes (p.7-4), the composite Trapezoidal rule is defined as below.
 * {| style="width:100%" border="0" align="left"

I_n=h(\dfrac{1}{2}f(x_0)+f(x_1)+f(x_2)+...+f(x_{n-1})+\dfrac{1}{2}f(x_{n})) \mbox{, }h=\dfrac{b-a}{n} $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-5)
 * }
 * The area can be computed by subtracting the integration on the upper curve by the integration on the lower curve on one leaf.
 * {| style="width:100%" border="0" align="left"
 * {| style="width:100%" border="0" align="left"

AREA=I_{upper}-I_{lower} $$ $$ Matlab code:
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-6)
 * }
 * }
 * {| style="width:100%" border="0" align="left"

Result:
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \begin{align} n&=10000 \\ Area&=0.196349420478339 \\ Accuracy&=1.203710234265465 \times 10^{-7} \end{align} $$ 2. Composite Simpson's rule
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * }
 * }
 * }
 * From the class notes (p.7-4), the composite Simpson's rule is defined as below.
 * {| style="width:100%" border="0" align="left"

I_n=\dfrac{h}{3}(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+...+2f(x_{n-2})+4f(x_{n-1})+f(x_n))\mbox{, }h=\frac{b-a}{n} $$ $$
 * $$\displaystyle
 * $$\displaystyle
 * $$\displaystyle (4-7)
 * }
 * The area can be computed in the same way as in Eq(4-6).
 * The area can be computed in the same way as in Eq(4-6).

Matlab code:
 * {| style="width:100%" border="0" align="left"

Result:
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \begin{align} n&=10000 \\ Area&=0.196349471145946 \\ Accuracy&=6.9703415817024 \times 10^{-8} \end{align} $$
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * }
 * }
 * }

3. Sum of Triangles The area on the bifolium can be computed by summing all areas of triangle divided in uniform angle. Matlab code:
 * {| style="width:100%" border="0" align="left"

Result:
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * style="width:50%; padding:10px; border:1px solid #888888" align="center" |
 * }
 * }
 * }
 * {| style="width:100%" border="0" align="left"

$$\displaystyle \begin{align} n&=10000 \\ Area&=0.196349527930081 \\ Accuracy&=1.291928136692988 \times 10^{-8} \end{align} $$
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * style="width:50%; padding:10px; border:2px solid #8888aa" align="center" |
 * }
 * }
 * }