User:Eml5526.s11.team6.joglekar/hwk4

=Problem 9=

Given
Solving a differential equation using Weight Residual Form. The partial differential equation is:


 * {| style="width:100%" border="0"

$$ \frac{\partial}{\partial x}\left(2\frac{\partial u}{\partial x}\right) + 3 = 0 $$
 * $$\displaystyle (Eq.9.1) $$
 * }
 * }

The boundary conditions are:

$$ u\left(1\right) = 0$$

$$\frac{du}{dx}\left(0\right) = -4 $$

Weighting funtion to be used:


 * {| style="width:100%" border="0"

$$ b_{i} = \left \{ 1, \sin\left ( x \right ),\sin\left (  2x \right )... \right \} $$


 * $$\displaystyle (Eq.9.2) $$
 * }
 * }

Which is correction function when $$\phi = \frac{\pi}{2}$$

Find

 * 1 Find an approximate solution of the form $$U^{h}=\sum_{i=0}^{n}d_{i}b_{i}$$ for n=2
 * 2 Find two equations that enforce the boundary conditions
 * 3 Project the weight residues
 * 4 Display the equations in matrix form
 * 5 Solve for $$\displaystyle d $$
 * 6 Construct $$U^{h}$$ and plot $$U^{h}$$ and $$u $$
 * 7 Repeat 9.1 to 9.6 for n = 4 and n = 6

9.1 Find an approximate solution with n=2
For n = 2:
 * {| style="width:100%" border="0"

$$ d_{i}=\begin{bmatrix} d0 & d1 & d2 \end{bmatrix} $$
 * $$\displaystyle (Eq.9.3) $$
 * }
 * }

and


 * {| style="width:100%" border="0"

$$ b_{i}=\begin{bmatrix} 1 & \sin  \left ( x\right ) & \sin  \left ( 2x\right ) \end{bmatrix} $$
 * $$\displaystyle (Eq.9.4) $$
 * }
 * }

Therefore:

9.2 Find two equations that enforce the boundary conditions
The boundary conditions are:

And

9.3 Project the weight residues
In this case changing the function u(x) by the approximated function $$U^{h}$$ in the PDE (Eq.9.1), we found that P(u) is:


 * {| style="width:100%" border="0"

$$ P\left ( U^{h} \right )=2\frac{\partial^2 U^{h}}{\partial x^2}+3=-2\left ( d1\sin \left (x \right ) +4d2\sin \left (2x \right )\right )+3 $$
 * $$\displaystyle (Eq.9.8) $$
 * }
 * }

The equation 9.8 can be written as:


 * {| style="width:100%" border="0"

$$ P\left ( U^{h} \right )= -2\begin{bmatrix}0 & \sin \left (x\right ) & 4\sin \left (2x \right ) \end{bmatrix}\begin{bmatrix} d0\\ d1\\

d2\end{bmatrix}+3 $$
 * $$\displaystyle (Eq.9.9) $$
 * }
 * }

Projecting the residue we have:


 * {| style="width:100%" border="0"

$$ \int_{a}^{b}b(x)P\left ( U^{h} \right )= 0 $$ After substitution of (Eq.9.4) and (Eq.9.9) in (Eq.9.10) the following equation is obtained
 * $$\displaystyle (Eq. 9.10) $$
 * }
 * }

9.4 Display the equations in matrix form
Performing the product and then the integration indicated in (Eq.9.11) we have:

The latter equation is clearly of the form $$\displaystyle Kd=F$$. We can observe that K is not symmetric.

9.5 Solve for $$ d $$
In (Eq.9.12) we have three equations; but, as we need to enforce the boundary conditions we take the only one of them and solve it together with (Eq.9.6) and (Eq.9.7). From these equations we now have the system:


 * {| style="width:100%" border="0"

$$ \begin{bmatrix} 1 &\sin\left (1 \right )   & \sin\left (2  \right ) \\ 0 &\cos \left (0 \right ) &2\cos \left (0  \right ) \\ 0 & 2\frac{\sin^3\left(1\right)}{3} & 2-\frac{\sin\left(4\right)}{2} \end{bmatrix}\begin{bmatrix} d0\\ d1\\

d2\end{bmatrix}=\begin{bmatrix} 0\\ 4\\

2.12\end{bmatrix}$$
 * $$\displaystyle (Eq.9.13) $$
 * }
 * }

After solving the system in (Eq.9.13) we obtain d:

9.6 Construct $$U^{h}$$ and plot $$U^{h}$$ and $$u$$
Replacing d in (Eq.9.5) we obtain the approximated solution:


 * {| style="width:100%" border="0"

$$ U^{h}=-3.11+3.33\sin \left (x \right )+0.33\sin \left ( 2x \right ) $$
 * $$\displaystyle (Eq.9.14) $$
 * }
 * }

On the other hand, the exact solution of the PDE (Eq.9.1) with the given boundary condition is:


 * {| style="width:100%" border="0"

$$ u\left ( x \right )=-\frac{3}{4}x^{2}-4x+\frac{19}{4} $$
 * $$\displaystyle (Eq.9.15) $$
 * }
 * }

In Fig.9.1 we show the exact and the approximated solution.



9.7 Plot the graph for $$ u\left(x\right)$$ and $$u^h\left(x\right)$$
Using following generalized code for any value of n, we get plots for n=4 and n=6



The error at x=0.5 is plotted for different values of n