User:Eml5526.s11.team3.akj/Homework 3

Problem Statement 3.1
(Do Problem 2.9 with polynomial basis functions with $$k=1$$: $$\{{{(x+k)}^{j}},j=0,1,2,\cdots \}$$. 1.)	Find two equations that enforce boundary conditions for $${{u}^{h}}(x)$$ 2.)	Find one more equation to solve for $$d=\{{{d}_{j}}\}$$ by projecting the residue $$P({{u}^{h}})$$ on a basis function $${{b}_{k}}(x)$$ with k = 0, 1, 2 such that the additional equation is linearly independent from the above two equations in 1.) 3.)	Display the three equations in matrix form: $$Kd=F$$ and comment on the symmetric properties of $$K$$. 4.)	Solve for $$d$$. 5.)	Construct $${{u}^{h}}(x)$$ and plot $${{u}^{h}}(x)$$ vs $$u(x)$$ which is the exact solution. 6.)	Repeat 1-5 for n = 4 and n = 6. 7.)	Computer $$u_{n}^{h}(x=0.5)$$ for n = 2, 4, 6 Error $${{e}_{n}}(0.5)=u(0.5)-{{u}^{h}}(0.5)$$ Plot $${{e}_{n}}(0.5)$$ vs n (convergence)

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

$$\displaystyle
 * style="width:95%" |
 * style="width:95%" |

u(1)=0 and \frac{du}{dx}(0)=-4

$$
 * }

Solution
1) For $$n=2$$  :

for $$n=2$$  the basis function is

$$\displaystyle

\left\{ {{b}_{i}}\left( x \right)={{(x+1)}^{i}},i=0,1,2 \right\}

$$ then, $$b_{0}(x)=1,b_{1}(x)=(x+1),b_{2}(x)=(x+1)^{2}$$

the main aim of this problem is to solve the PDE given by Eq(1) by discrete Weighted Residual form method, in the method we assume the solution $$u(x)$$  as  $$u^{h}(x)= \sum_{j=0}^{n}d_{j}b_{j}(x)$$

for $$n=2$$ ,  $$u^{h}(x)= \sum_{j=0}^{2}d_{j}b_{j}(x)$$

i.e.

given essential boundary condition as $$u(1)=0$$

hence the first equation which enforces boundary condition is $$ d_{0}1+d_{1}(1+1)+d_{2}(1+1)^{2}=0 $$

Essential boundary condition is

given natural boundary condition as $$\frac{du}{dx}(0)=-4$$

natual boundary condition written as $$d_{0}\frac{db_{0}}{dx}+d_{1}\frac{db_{1}}{dx}+d_{2}\frac{db_{2}}{dx}=-4$$ at $$x=0$$

i.e  $$ d_{0}0+d_{1}(1)+d_{2}2(0+1)^{2}=0 $$

Natural boundary condition is

2) We have to find one more equation to solve for $$d=\{{{d}_{j}}\}$$  by projecting the residue  $$P({{u}^{h}})$$  on a basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2 such that the additional equation is linearly independent from the above two equations in 1.)

hence we project the residue $$P({{u}^{h}})$$  on a basis function  $${{b}_{1}}(x)$$  to obtain the third equation which is linearly independent to the two boundary conditions obtained.

we get,

given $$a_{2}=2$$,  $$f(x)=3$$  and since we are projecting on first basis function  $$b_{0}(x)=1$$

hence Eq (3.4) becomes $$2d_{0}\int_{0}^{1}\frac{\mathrm{d}^{2} (1)}{\mathrm{d} x^{2}}dx+2d_{1}\int_{0}^{1}\frac{\mathrm{d}^{2} (x+1)}{\mathrm{d} x^{2}}dx+2d_{2}\int_{0}^{1}\frac{\mathrm{d}^{2} (x+1)^{2}}{\mathrm{d} x^{2}}dx=-3\int_{0}^{1}dx$$

the third equation is

3) Eq.(3.2), (3.3) and (3.5) can be written in Matrix form as

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence  $$u^{h}(x)=8-\frac{5}{2}(x+1)-\frac{3}{4}(x+1)^{2}$$

which on simplification gives

the solution of PDE Eq(3.1) gives the exact solution $$u(x)$$

Eq(3.1)is $$\frac{\mathrm{d}^{2}u }{\mathrm{d} x^{2}}=\frac{-3}{2}$$

integrating the above equation once we get

but from essential BC, $$c=-4$$

hence integrating again Eq(3.8) and applying Natural B.C we get exact solution

Matlab Code:

6) To compute $$u^{h}(x=0.5)$$   for n = 2 Substituting   $$x=0.5$$  in Eq(3.7)

we get,

$$u(0.5)=2.5625$$

Hence error $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

Plot $${{e}_{n}}(0.5)$$ vs n (convergence)

For $$n=4$$  :

For $$n=4$$  and  $$n=6$$  the computation becomes difficult hence Matlab is used fro computational purpose.

1) for $$n=4$$  the basis function is

$$\displaystyle \left\{ {{b}_{i}}\left( x \right)={{(x+1)}^{i}},i=0,1,2,3,4 \right\} $$ then, $$b_{0}(x)=1,b_{1}(x)=(x+1),b_{2}(x)=(x+1)^{2},b_{3}(x)=(x+1)^{3},b_{4}(x)=(x+1)^{4}$$

Two equations that enforce boundary conditions are

Essential boundary condition

and Natural boundary condition is

2)

Additional equations to solve for $$d=\{{{d}_{j}}\}$$  by projecting the residue  $$P({{u}^{h}})$$  on the basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2 such that the additional equations are linearly independent from the above two equations in 1.)

3) Equations in matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence  $$u^{h}(x)=8-\frac{5}{2}(x+1)-\frac{3}{4}(x+1)^{2}$$

which on simplification gives

and exact solution

Matlab Code:

Note: It is observed that on solving for $$n=4$$  we got  $$d_{3}=0$$  and  $$d_{4}=0$$  hence the plot for  $$n=2$$  and  $$n=4$$  are same

6) Since  $$d_{3}=0$$  and  $$d_{4}=0$$  for  $$n=4$$  hence  $$u^{h}(x)$$  and  $$u(x)$$  will be same for  $$n=2$$  and  $$n=4$$  hence

and $$u(0.5)=2.5625$$

Hence error $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

For $$n=6$$  :

1) for $$n=6$$  the basis function is

$$\displaystyle \left\{ {{b}_{i}}\left( x \right)={{(x+1)}^{i}},i=0,1,2,3,4,5,6 \right\} $$

then, $$b_{0}(x)=1,b_{1}(x)=(x+1),b_{2}(x)=(x+1)^{2},b_{3}(x)=(x+1)^{3},b_{4}(x)=(x+1)^{4},b_{5}(x)=(x+1)^{5},b_{6}(x)=(x+1)^{6}$$

Two equations that enforce boundary conditions are

Essential boundary condition

and Natural boundary condition is

2)

Additional equations to solve for $$d=\{{{d}_{j}}\}$$  by projecting the residue  $$P({{u}^{h}})$$  on the basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2,3,4 such that the additional equations are linearly independent from the above two equations in 1.)

3) Equations in matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence  $$u^{h}(x)=8-\frac{5}{2}(x+1)-\frac{3}{4}(x+1)^{2}$$

which on simplification gives

and exact solution

Plot of $$u^{h}(x)vs u(x) for n=2,n=4,n=6$$

the approximate $$u^{h}(x)$$  and exact solution  $$ u(x) $$  for n=2 ,n=4 and n=6 are found to be same, which is also evident from the plot where all the plots overlap on one another

Matlab Code:

Note: It is observed that on solving for $$n=6$$  we got  $$d_{3}=0$$ ,  $$d_{4}=0$$  ,  $$d_{5}=0$$  and  $$d_{6}=0$$  hence the plot for  $$n=4$$  and  $$n=6$$  are same

6) Since  $$d_{3}=0$$ ,  $$d_{4}=0$$  ,  $$d_{5}=0$$  and  $$d_{6}=0$$  for  $$n=6$$  hence  $$u^{h}(x)$$  and  $$u(x)$$  will be same for  $$n=4$$  and  $$n=6$$  hence

and $$u(0.5)=2.5625$$

Hence error $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

Plot showing error between approximate and actual solution at x=0.5

since we got both approximate and actual solution to be the same hence the error is zero through out

Solution
This is the special case of Problem 3.1 where k=0 hence the basis functions will be $$\displaystyle

\left\{ {{b}_{i}}\left( x \right)={{x}^{i}},i=0,1,2 \right\}

$$

1) For $$n=2$$  : for $$n=2$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=x,b_{2}(x)=x^{2}$$

applying the boundary conditions as mentioned in Problem 3.1 the two equations satisfying boundary conditions will be

Essential boundary condition is

and

Natural boundary condition is

2) One more equation which is independent to the BC's and which is obtained by projecting the residue $$P({{u}^{h}})$$  on a basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2

hence the third equation is

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution as solved in Problem 3.1

The approximate solution happens to match completely with the exact solution

Matlab Code:

6)  $$u^{h}(x)$$  obtained in part 5 is same as the one in Problem 3.1 hence  $$u^{h}(x=0.5)$$  will be same as one found in Problem 3.1

and error is $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

For $$n=4$$  : 1)

for $$n=4$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=x,b_{2}(x)=x^{2},b_{3}(x)=x^{3},b_{4}(x)=x^{4}$$

Two equations that enforce boundary conditions are Essential boundary condition is

and

Natural boundary condition is

2) Additional equations to solve for $$d=\{{{d}_{j}}\}$$  by projecting the residue  $$P({{u}^{h}})$$  on the basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2 such that the additional equations are linearly independent from the above two equations in 1.)

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution

The approximate solution happens to match completely with the exact solution

Matlab Code:

6)

and error is $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

For $$n=6$$  : 1)

for $$n=6$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=x,b_{2}(x)=x^{2},b_{3}(x)=x^{3},b_{4}(x)=x^{4},b_{5}(x)=x^{5},b_{6}(x)=x^{6}$$

Two equations that enforce boundary conditions are Essential boundary condition is

and

Natural boundary condition is

2) Additional equations to solve for $$d=\{{{d}_{j}}\}$$  by projecting the residue  $$P({{u}^{h}})$$  on the basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2,3,4 such that the additional equations are linearly independent from the above two equations in 1.)

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution

The approximate solution happens to match completely with the exact solution

Plot of $$u^{h}(x)vs u(x) for n=2,n=4,n=6$$



the approximate $$u^{h}(x)$$  and exact solution  $$ u(x) $$  for n=2 ,n=4 and n=6 are found to be same, which is also evident from the plot where all the plots overlap on one another Matlab Code:

6)

and error is $${{e}_{n}}(0.5)=2.5625-2.5625=0$$

Plot showing error between approximate and actual solution at x=0.5

since we got both approximate and actual solution to be the same hence the error is zero through out

Solution
For $$n=2$$  : the basis functions will be $$\displaystyle

\left\{ {{b}_{i}}\left( x \right)={1,cos(ix+\frac{pi}{4})},i=0,1,2 \right\}

$$

1)

for $$n=2$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=cos(x+\frac{pi}{4}),b_{2}(x)=sin(x+\frac{pi}{4})$$

applying the boundary conditions as mentioned in Problem 3.1 the two equations satisfying boundary conditions will be

Essential boundary condition is

and

Natural boundary condition is

2) One more equation which is independent to the BC's and which is obtained by projecting the residue $$P({{u}^{h}})$$  on a basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2

hence the third equation is

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution as solved in Problem 3.1

6)

and error is $${{e}_{n}}(0.5)=2.3394-2.5625=-0.2231$$

For $$n=4$$  : the basis functions will be $$\displaystyle

\left\{ {{b}_{i}}\left( x \right)={1,cos(ix+\frac{pi}{4})},i=0,1,2,3,4 \right\}

$$

1)

for $$n=4$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=cos(x+\frac{pi}{4}),b_{2}(x)=sin(x+\frac{pi}{4}),b_{3}(x)=cos(2x+\frac{pi}{4}),b_{4}(x)=sin(2x+\frac{pi}{4})$$

applying the boundary conditions as mentioned in Problem 3.1 the two equations satisfying boundary conditions will be

Essential boundary condition is

and

Natural boundary condition is

2) Additional equations which are independent to the BC's and which are obtained by projecting the residue $$P({{u}^{h}})$$  on a basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2

hence the third equation is

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution as solved in Problem 3.1

6)

and error is $${{e}_{n}}(0.5)=2.5629-2.5625=0.0004$$

For $$n=6$$  : the basis functions will be $$\displaystyle

\left\{ {{b}_{i}}\left( x \right)={1,cos(ix+\frac{pi}{4})},i=0,1,2,3,4,5,6 \right\}

$$

1)

for $$n=6$$  the basis function is  $$b_{0}(x)=1,b_{1}(x)=cos(x+\frac{pi}{4}),b_{2}(x)=sin(x+\frac{pi}{4}),b_{3}(x)=cos(2x+\frac{pi}{4}),b_{4}(x)=sin(2x+\frac{pi}{4}),b_{5}(x)=cos(3x+\frac{pi}{4}),b_{6}(x)=sin(3x+\frac{pi}{4})$$

applying the boundary conditions as mentioned in Problem 3.1 the two equations satisfying boundary conditions will be

Essential boundary condition is

and

Natural boundary condition is

2) Additional equations which are independent to the BC's and which are obtained by projecting the residue $$P({{u}^{h}})$$  on a basis function  $${{b}_{k}}(x)$$  with k = 0, 1, 2

hence the third equation is

3) Matrix form

Hence

Clearly $$\mathbf{K}$$  is non-Symmetric matrix

4) Using Matlab, we can easily get

5) Hence

exact solution as solved in Problem 3.1

6)

and error is $${{e}_{n}}(0.5)=2.5625-2.5625=0$$