# User:Eml5526.s11.team01/Hwk2

Jump to: navigation, search

# Problem 1

## Given

An elastic bar with a cross section A(x)

## Find

Derive heat problem equation from Lecture Slide Mtg.6

 $\frac{\partial}{\partial x}\left(A \left(x\right) k\left(x\right) \frac{\partial u}{\partial x}\right) + f \left(x,t \right) = A \left(x \right) \rho c \frac{\partial u}{\partial t}$ $\displaystyle (Eq. 1.1)$

## Solution

Fig. 1 Shows a bar of cross section A(x), with conductivity k(x), density ρ, specific heat c, with an internal heat source (or sink) f(x,t). In the bar the heat is transferred only by conduction in x direction. The temperature has been called u(x,t)

Fig 1.1 Bar of Arbitrary Cross Section
Fig. 1.2 Forces acting on an element of the bar

The partial differential equation for this problem can be obtained doing an energy balance in an infinitesimal element of the bar. Fig. 2 shows an infinitesimal element of length dx; heat entering the body on the left hand side is $q\left(x \right)$ and heat going out the body on the right hand side is $q \left(x + dx \right)$

Doing the energy balance we obtain:

 $q \left(x \right) A \left(x \right) - q \left(x + dx \right) A \left(x+dx \right) + fdx = \frac{dE}{dt}$ $\displaystyle (Eq. 1.2)$

Where $\frac{dE}{dt}$ is the change of energy with respect to time which can be calculated in terms of the temperature as:

 $\frac{dE}{dt} = A d x \rho c \frac{\partial u}{\partial t}$ $\displaystyle (Eq. 1.3)$

The heat flow and the cross area at the right hand side of the element can be approximated by:

 $q \left(x + dx \right) = q \left(x \right) + \frac{\partial q}{\partial x} dx$ $\displaystyle (Eq. 1.4)$
 $A \left(x + dx \right) = A \left(x \right) + \frac{\partial A}{\partial x} dx$ $\displaystyle (Eq. 1.5)$

Replacing on Eq.1.2 we obtain:

 $qA - \left(q + \frac{\partial q}{\partial x}dx \right)\left(A + \frac{\partial A}{\partial x} dx \right) + fdx = A d x \rho c \frac{\partial u}{\partial x}$ $\displaystyle (Eq. 1.6)$

Doing the product we get:

 $qA - qA - q \frac{\partial A}{\partial x} dx - A \frac{\partial q}{\partial x} dx - \frac{\partial A}{\partial x} dx \frac{\partial q}{\partial x} dx + fdx = A d x \rho c \frac{\partial u}{\partial x}$ $\displaystyle (Eq. 1.7)$

Neglecting the second order term we have:

 $-q \frac{\partial A}{\partial x} dx - A \frac{\partial q}{\partial x} dx + fdx =Adx \rho c \frac{\partial u}{\partial x}$ $\displaystyle (Eq. 1.8)$

The first two terms in the latter equation are the derivative of a product; therefore:

 $- \frac{\partial}{\partial x} \left(Aq \right) dx + fdx = Adx \rho c \frac{\partial u}{\partial x}$ $\displaystyle (Eq. 1.9)$

Using the Fourier’s law, the heat flow can be expressed as function of temperature. For an unidirectional case we have:

 $q\left (x \right) = -k \left(x \right) \frac{\partial u}{\partial x}$ $\displaystyle (Eq. 1.10)$

Where k(x) is the conductivity of the material. Replacing equation Eq.1.9 in Eq.1.10 we have:

 $\frac{\partial}{\partial x} \left( Ak \frac{\partial u}{\partial x} \right) + f \left(x,t \right) = A \rho c \frac{\partial u}{\partial t}$ $\displaystyle ( Eq. 1.11)$

# Problem 2

## Given

$\left [B _{jk} \right ]=\begin{bmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{bmatrix}$

 $\overset{v}{\rightarrow}=5\overset{a_{1}}{\rightarrow}-7\overset{a_{2}}{\rightarrow}-4\overset{a_{3}}{\rightarrow}$ $\displaystyle (Eq. 2.1)$

## Find

2.1 $Det\left [B _{jk} \right ]$.

2.2 Find $\displaystyle \Gamma (b_{1},b_{3},b_{3})=K$.

2.3 Find $\overset{F}{\rightarrow}=\left \{ F_{i} \right \}=\left \{ b_{i}.v \right \}$.

2.4 Solve $\displaystyle (Eq. 5)$on 7-2 for $\overset{d}{\rightarrow}=\left \{v _{j} \right \}$

2.5 Use equation 1 on 7-4 to find $\vec{\overset{k}{\rightarrow}}\overset{d}{\rightarrow}=\vec{\overset{F}{\rightarrow}}$ What is $\vec{K}$ & $\vec{F}$?

2.6 Solve for $\overset{d}{\rightarrow}_{i}$ compare to $\overset{d}{\rightarrow}$ in 4).

2.7 Observe the symmetric properties of $\overset{K}{\rightarrow}$ & $\overset{\vec{K}}{\rightarrow}$. Further Discuss the Pros & Cons of Bubnov-Galerkin & Petrov-Galerkin Methods.

## Solution

### 2.1

$Det\left [B _{jk} \right ]$=

 $\begin{vmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{vmatrix}=-8.$.

### 2.2

Find $\Gamma (b_{1},b_{3},b_{3})=\overset{K}{\rightarrow}$.

According to the $\displaystyle Eq.4$on 7-1, $b_{1},b_{3},b_{3}$ given before we have,

$\overset{b_{j}}{\rightarrow}.d_{j}=\overset{V}{\rightarrow}$

Successively performing multiplication by $b_{1},b_{3},b_{3}$ we get,

 $d_{1}\overset{b_{1}}{\rightarrow}+d_{2}\overset{b_{2}}{\rightarrow}+d_{3}\overset{b_{3}}{\rightarrow}=\overset{V}{\rightarrow}$ $\displaystyle (Eq. 2.2)$

Substituting the given values we get,

$d_{1}\begin{bmatrix} 1\\ 1\\ 1 \end{bmatrix}+d_{2}\begin{bmatrix} 2\\ -1\\ 3 \end{bmatrix}+d_{3}\begin{bmatrix} 3\\ 2\\ 6 \end{bmatrix}=\begin{bmatrix} 5\\ -7\\ -4 \end{bmatrix}$

This equation can also be written in the following format,

$\begin{bmatrix} 1 &2 &3 \\ 1 &-1 &2 \\ 1 & 3 & 6 \end{bmatrix}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{pmatrix} 5\\ -7\\ 4 \end{pmatrix}$

$\displaystyle Eq.3$ on 7-2 is obtained by multiplying $\displaystyle Eq.2.2$ by each $\overset{b}{\rightarrow}$, so we can write,

$\overset{b_{1}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{b_{1}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{b_{1}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{b_{1}}{\rightarrow}.\overset{V}{\rightarrow}==F_{1}$

$\overset{b_{2}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{b_{2}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{b_{2}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{b_{2}}{\rightarrow}.\overset{V}{\rightarrow}==F_{2}$

$\overset{b_{3}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{b_{3}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{b_{3}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{b_{2}}{\rightarrow}.\overset{V}{\rightarrow}==F_{3}$

These 3 equations can be further presented as below in the matrix form,

$\begin{bmatrix} \overset{b_{1}}{\rightarrow}.\overset{b_{1}}{\rightarrow} & \overset{b_{1}}{\rightarrow}.\overset{b_{2}}{\rightarrow} & \overset{b_{1}}{\rightarrow}.\overset{b_{3}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}.\overset{b_{1}}{\rightarrow} & \overset{b_{2}}{\rightarrow}.\overset{b_{2}}{\rightarrow} & \overset{b_{2}}{\rightarrow}.\overset{b_{3}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow}.\overset{b_{1}}{\rightarrow} & \overset{b_{3}}{\rightarrow}.\overset{b_{2}}{\rightarrow} & \overset{b_{3}}{\rightarrow}.\overset{b_{3}}{\rightarrow} \end{bmatrix}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} b_{1}\\ b_{2}\\ b_{3} \end{bmatrix}\begin{pmatrix} V_{1}\\ V_{2}\\ V_{3} \end{pmatrix}$

Which also can be written as

$\begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix} \begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix}^{T}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix}\begin{pmatrix} V_{1}\\ V_{2}\\ V_{3} \end{pmatrix}=\overset{F}{\rightarrow}$

Substituting the numerical values we get,

$\begin{bmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{bmatrix}\begin{bmatrix} 1 &2 &3 \\ 1 &-1 &2\\ 1 &3 &6 \end{bmatrix}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{bmatrix}\begin{bmatrix} 5\\ -7\\ -4 \end{bmatrix}$

Performing the product, we get:

 $\begin{bmatrix} 3 &4 &11\\ 4 &14 &22\\ 11 &22 &49 \end{bmatrix}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{bmatrix}\begin{bmatrix} 5\\ -7\\ -4 \end{bmatrix}=\overset{F}{\rightarrow}$ $\displaystyle (Eq. 2.3 )$

$\displaystyle Eq. 2.3$ is equivalent to $\displaystyle Kd=F$ where

 $K=\begin{bmatrix} 3 &4 &11 \\ 4 &14 &22 \\ 11&22 &49 \end{bmatrix}=Stiffness Matrix$

Furthermore,

 $Det[K]=\begin{vmatrix} 3 &4 &11\\ 4 &14 &22 \\ 11 &22 &49 \end{vmatrix}= 64$

### 2.3

$\overset{F}{\rightarrow}=\left \{ F_{i} \right \}=\left \{ b_{i}.v \right \}$=

From $\displaystyle Eq. 2.3$

 $\overset{F}{\rightarrow}=\begin{bmatrix} 1 &1 &1 \\ 2 &-1 &3 \\ 3 &2 &6 \end{bmatrix}\begin{bmatrix} 5\\ -7\\ -4 \end{bmatrix}=\begin{pmatrix} -6\\ 5\\ -23 \end{pmatrix}$

### 2.4

Solve $\displaystyle Eq. 5$ on 7-2 for $\overset{d}{\rightarrow}=\left \{v _{j} \right \}$

Rearranging $\displaystyle Eq. 2.3$ We get

$\displaystyle d=K^{-1}F$

 $d=\begin{bmatrix} 3 &4 &11 \\ 4 &14 &22 \\ 11 &22 &49 \end{bmatrix}^{-1}\begin{pmatrix} -6\\ 5\\ -23 \end{pmatrix}=\begin{pmatrix} 8.3750\\ 5.6250\\ -4.875 \end{pmatrix}$

### 2.5

Use equation 1 on 7-4 to find $\vec{\overset{k}{\rightarrow}}\overset{d}{\rightarrow}=\vec{\overset{F}{\rightarrow}}$. Further, What is $\vec{K}$ & $\vec{F}$?

In this case, $\displaystyle w_{i}=a_{i}$, where $\displaystyle a_{i}$ is the orthonormal basis.

Starting with Equation 1 on 7-2, we get:

$d_{1}\overset{b_{1}}{\rightarrow}+d_{2}\overset{b_{2}}{\rightarrow}+d_{3}\overset{b_{3}}{\rightarrow}=\overset{V}{\rightarrow}$

If we multiply successively by $\displaystyle a_{i}$, we get the following equations,

$\overset{a_{1}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{a_{1}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{a_{1}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{a_{1}}{\rightarrow}.\overset{V}{\rightarrow}=F_{1}$

$\overset{a_{2}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{a_{2}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{a_{2}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{a_{2}}{\rightarrow}.\overset{V}{\rightarrow}=F_{2}$

 $\overset{a_{3}}{\rightarrow}.\overset{b_{1}}{\rightarrow}d_{1}+\overset{a_{3}}{\rightarrow}.\overset{b_{2}}{\rightarrow}d_{2}+\overset{a_{3}}{\rightarrow}.\overset{b_{3}}{\rightarrow}d_{3}=\overset{a_{3}}{\rightarrow}.\overset{V}{\rightarrow}=F_{3}$ $\displaystyle (Eq. 2.4)$

Which can be further written as,

$\begin{bmatrix} \overset{a_{1}}{\rightarrow}\\ \overset{a_{2}}{\rightarrow}\\ \overset{a_{3}}{\rightarrow} \end{bmatrix}\begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix}^{T}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} \overset{a_{1}}{\rightarrow}\\ \overset{a_{2}}{\rightarrow}\\ \overset{a_{3}}{\rightarrow} \end{bmatrix}\begin{pmatrix} V_{1}\\ V_{2}\\ V_{3} \end{pmatrix}=\overset{\vec{F}}{\rightarrow}$

As $a_{i}$ is orthonormal basis, we can write the following,

$a_{1}=\begin{bmatrix} 1 & 0 &0 \end{bmatrix};a_{2}=\begin{bmatrix} 0&1&0 \end{bmatrix};a_{3}=\begin{bmatrix} 0& 0 &1 \end{bmatrix}$

Substituting the respective values we have,

$\begin{bmatrix} 1 &0 &0 \\ 0 &1 &0 \\ 0 &0 &1 \end{bmatrix}\begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix}^{T}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0& 1 \end{bmatrix}\begin{pmatrix} V_{1}\\ V_{2}\\ V_{3} \end{pmatrix}=\overset{\vec{F}}{\rightarrow}$

Simplifying we obtain that,

$\begin{bmatrix} \overset{b_{1}}{\rightarrow}\\ \overset{b_{2}}{\rightarrow}\\ \overset{b_{3}}{\rightarrow} \end{bmatrix}^{T}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{pmatrix} V_{1}\\ V_{2}\\ V_{3} \end{pmatrix}=\overset{\vec{F}}{\rightarrow}$

Replacing the numerical values we get,

 $\begin{bmatrix} 1 & 2 & 3\\ 1 &-1 &2 \\ 1 &3 & 6 \end{bmatrix}\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{pmatrix} 5\\ -7\\ -4 \end{pmatrix}$ $\displaystyle ( Eq. 2.5 )$

This equation is nothing but the system

$\overset{\vec{K}}{\rightarrow}\overset{d}{\rightarrow}=\overset{\vec{F}}{\rightarrow}$

From where we can conclude that $\overset{\vec{K}}{\rightarrow}$ is a matrix whose columns are the vectors $\overset{b_{j}}{\rightarrow}$ and $\overset{\vec{F}}{\rightarrow}= V$.

### 2.6

Solve for $\overset{d}{\rightarrow}_{i}$ compare to $\overset{d}{\rightarrow}$ in problem 2.4

 $\begin{pmatrix} d_{1}\\ d_{2}\\ d_{3} \end{pmatrix}=\begin{bmatrix} 1 & 2 & 3\\ 1 &-1 &2 \\ 1 &3 & 6 \end{bmatrix}^{-1}\begin{pmatrix} 5\\ -7\\ -4 \end{pmatrix}=\begin{pmatrix} 8.3750\\ 5.6250\\ -4.875 \end{pmatrix}$

We can see that this result is identical to the result we obtained in problem 2.4

### 2.7

Observe the symmetric properties of $\overset{K}{\rightarrow}$ & $\overset{\vec{K}}{\rightarrow}$. Further Discuss the Pros & Cons of Bubnov-Galerkin & Petrov-Galerkin Methods.

We can explicitely see that $\overset{K}{\rightarrow}$ is always symmetric because it is obtained from the product of $\overset{b_{j}}{\rightarrow}.\overset{b_{i}}{\rightarrow}$; where as $\overset{\vec{K}}{\rightarrow}$ is not always symmetric. It will be symmetric only when the vector b is a Orthonormal basis.

The pros of Bubnov-Galerkin method is the symmetry of the stiffness matrix which is generally easy to solve, however more calculations are necessary to get the stiffness matrix. Whereas, in the Petrov-Galerking method, obtaining the stiffness matrix is easier but solving the system on other hand can be more difficult owing to its non-symmetry.

# Problem 3

## Given

Given Equation 1 on 8-1 which states $\overset{w}{\rightarrow}.\overset{P(v)}{\rightarrow}=0$

 $\forall w\in R^{n}$ $\displaystyle (Eq. 3.1)$

and $\overset{w}{\rightarrow}.\overset{P(v)}{\rightarrow}=0$ where $\overset{w}{\rightarrow}=\sum \beta _{i}.a_{i}$

 $\forall (\beta _{1},\beta _{2}..\beta _{n})\in R^{n}$ $\displaystyle (Eq. 3.2)$

## Find

Show that

$\displaystyle (Eq. 3.1)$

is equivalent to

$\displaystyle (Eq. 3.2)$

## Solution

For avoiding confusion we are designating the weight function as $\overset{W}{\rightarrow}$ in $\displaystyle (Eq. 3.1)$ and the weight function as $\overset{w}{\rightarrow}$ in $\displaystyle (Eq. 3.2)$.

Considering $\displaystyle (Eq. 3.2)$ and Substituting for $\overset{W}{\rightarrow}$

$\sum \beta _{i}a_{i}.\overset{P(v)}{\rightarrow}=0$

 $\forall (\beta _{1},\beta _{2}..\beta _{n})\in R^{n}$ $\displaystyle (Eq. 3.3)$

As $a_{i}$ is an orthonormal basis, performing a successive product by $a_{i}$ in the $\displaystyle (Eq. 3.3)$, we get

$\begin{bmatrix} 1 &0 &0 &....0 \end{bmatrix}\beta _{1}.\overset{P(v)}{\rightarrow}=0$

In the similar way

$\begin{bmatrix} 0 &1 &0 &....0 \end{bmatrix}\beta _{2}.\overset{P(v)}{\rightarrow}=0$

.

.

.

$\begin{bmatrix} 0 &0 &0 &....1 \end{bmatrix}\beta _{n}.\overset{P(v)}{\rightarrow}=0$;

Furthermore all the equations can be combined and written as

 $\begin{bmatrix} 1 &0 &...0 \\ 0 &1 &...0 \\ 0 &0 &...1 \end{bmatrix}\bigl(\begin{smallmatrix} \beta_{1}\\ .\\ .\\ \beta_{n} \end{smallmatrix}\bigr).\overset{P(v)}{\rightarrow}=\bigl(\begin{smallmatrix} 0\\ .\\ .\\ 0 \end{smallmatrix}\bigr) ... \forall (\beta _{1},\beta _{2}..\beta _{n})\in R^{n}$ $\displaystyle (Eq. 3.4)$

We can cleraly observe that the Matrix on the left hand side is the identity matrix $\begin{bmatrix} I \end{bmatrix}$; Moreover we have also written $(\beta _{1},\beta _{2}..\beta _{n})$ as a vector which further can be called as $\overset{\beta}{\rightarrow}$. and $\displaystyle (Eq. 3.4)$ becomes

 $\overset{\beta}{\rightarrow}.\overset{P(v)}{\rightarrow}=0; \forall \overset{\beta}{\rightarrow} \in R^{n}$ $\displaystyle (Eq. 3.5)$

Which is identical to $\displaystyle Eq. 3.1$.

# Problem 4

Show that

 $\int \frac{x^2}{1+x} dx = \frac{x^2}{2} - x + ln \left(1+x \right) + k$ $\displaystyle (Eq. 4.1)$

## Find

From Lecture 9

4.1$\int lnxdx = xlnx -x$

4.2$\int xlnxdx = \frac{1}{2} x^2 \left[lnx - \frac{1}{2} \right]$

4.3$\int \frac{x^2}{1+cx} dx$

4.4$\int \frac{x^2}{a+bx} dx$

From Lecture 10

4.5 Find the exact solution $u \left(x \right)$ for the problem (3) on 9-2

4.6 Plot $u \left(x \right)$

## Solution

### 4.1

Prove that

 $\int lnxdx = xlnx -x$ $\displaystyle (Eq. 4.2)$

In order to integrate by parts we choose $f \left(x \right) = lnx$ and $g' \left(x \right) = 1$

Now we apply the formulae for integration by parts which is:

 $\int f \left( x \right) g' \left( x \right)dx = f \left(x \right) g \left(x \right) - \int g \left(x \right) f' \left(x \right)dx$ $\displaystyle (Eq. 4.3)$

Where $f' \left(x \right) = \frac{1}{x}, g \left(x \right) = x$

Substituting these values into Eq.4.3 we get:

 $\int lnxdx = xlnx - \int \frac{x}{x} dx = xlnx -x$ $\displaystyle (Eq. 4.4)$

### 4.2

Prove that

 $\int xlnxdx = \frac{1}{2} x^2 \left[lnx - \frac{1}{2} \right]$ $\displaystyle (Eq. 4.5)$

In order to integrate by parts we choose: $f \left(x \right) = lnx$ and $g' \left(x \right) = x$

Where $f' \left(x \right) = \frac{1}{x}, g \left(x \right) = \frac{x^2}{2}$

Substituting these values into Eq.4.3 we get:

 $\int xlnxdx = \frac{x^2}{2} lnx - \int \frac{x^2}{2} \frac{1}{x} dx = \frac{x^2}{2} lnx - \int \frac{x}{2}dx = \frac{x^2}{2} lnx - \frac{x^2}{4}$ $\displaystyle (Eq. 4.6)$

Factoring out $\frac{1}{2} x^2$ we get:

 $\int xlnxdx = \frac{1}{2} x^2 \left[lnx - \frac{1}{2} \right]$ $\displaystyle (Eq. 4.5)$

### 4.3

Find

 $\int \frac{x^2}{1+cx} dx$ $\displaystyle (Eq. 4.7)$

The integral can also be written as follows:

 $\int \frac{x^2}{1+cx} dx = \frac{1}{c} \int \left[x - \frac{x}{1+cx} \right]dx = \frac{1}{c} \left[\int xdx - \int \frac{x}{1+cx} dx \right]$ $\displaystyle (Eq. 4.8)$

To solve this integral, we made the next change of variables:

 $y = 1+cx ~~ \Rightarrow ~~ x = \frac{y-1}{c} ~~ \Rightarrow ~~ dy = cdx$ $\displaystyle (Eq. 4.9)$

Substituting these values into Eq.4.8 we get:

 $\int \frac{ \left(y -1 \right)^2}{c^2 y} \frac{dy}{c}$ $\displaystyle (Eq. 4.10)$

Which can be expanded to:

 $\frac{1}{c^3} \int \frac{y^2 - 2y +1}{y} dy = \frac{1}{c^3} \int \left(y -2+ \frac{1}{y} \right) dy = \frac{1}{c^3} \left( \frac{y^2}{2} -2y+lny \right)$ $\displaystyle (Eq. 4.11)$

Finally, replacing y as a function of x we have:

 $\frac{1}{c^3} \left[ \frac{ \left(1+cx \right)^2}{2} - 2 \left(1+cx \right) + ln \left(1+cx \right) \right]$ $\displaystyle (Eq. 4.12)$

Choosing $c = 1$

 $\int \frac{x^2}{1+x} dx = \frac{x^2}{2} - x - \frac{3}{2} + ln \left(1+x \right)$ $\displaystyle (Eq. 4.13)$

Wolfram Alpha Proof for Part 3

### 4.4

Find

 $\int \frac{x^2}{a+bx} dx$ $\displaystyle (Eq. 4.14)$

We start by changing the variables with:

 $y = a +bx ~~ \Rightarrow ~~ x = \frac{y - a}{b} ~~ \Rightarrow ~~ dx = \frac{dy}{b}$ $\displaystyle (Eq. 4.15)$

Replacing these values into Eq.4.14 we get:

 $\int \frac{ \left( y-a \right)^2}{b^2 y} \frac{dy}{b} = \frac{1}{b^3} \int \left(y -2a+ \frac{a^2}{y} \right) dy = \frac{1}{b^3} \left( \frac{y^2}{2} - 2ay+ a^2 ln y \right)$ $\displaystyle (Eq. 4.16)$

Changing the variables we get:

 $\frac{1}{b^3} \left( \frac{ \left(a+bx \right)^2}{2} - 2a \left( a+bx \right) + a^2 ln \left(a+bx \right) \right)$ $\displaystyle (Eq. 4.17)$

Choosing $a = b =1$ we have:

 $\int \frac{x^2}{1+x} dx = \frac{ \left(1+x \right)^2}{2} - 2 \left(1+x \right) + ln \left(1+x \right)$ $\displaystyle (Eq. 4.18)$

The result is the same as Eq.4.13

Wolfram Alpha Proof for Part 4

### 4.5

The problem is solving the differential equation:

 $\frac{d}{dx} \left[ \left( 2+3x \right) \frac{du}{dx} \right] +5x = 0 ~~~ \forall x \in \left]0,1 \right[$ $\displaystyle (Eq. 4.19)$

With the boundary conditions:

 $u \left(1 \right) = 4 ~,~ - \frac{du}{dx} \left(x = 0 \right) = 6$ $\displaystyle (Eq. 4.20)$

The differential equation can be written:

 $\frac{d}{dx} \left[ \left( 2+3x \right) \frac{du}{dx} \right] = -5x$ $\displaystyle (Eq. 4.21)$

Now integrate:

 $\left[ \left( 2+3x \right) \frac{du}{dx} \right] = -5 \frac{x^2}{2} + k$ $\displaystyle (Eq. 4.22)$
 $\frac{du}{dx}= -2.5 \frac{x^2}{\left(2 +3x \right)} + \frac{k}{\left( 2+3x \right)}$ $\displaystyle (Eq. 4.23)$

Now the solution of $u \left( x \right)$ is:

 $u \left( x \right) = -2.5 \int \frac{x^2}{ \left(2+3x \right)} dx + k \int \frac{dx}{ \left(2+3x \right)}$ $\displaystyle (Eq. 4.24)$

The first integral can be solved using Eq.4.17 with $a = 2 ~,~ b=3$ and the second integral can be solved

 $\int \frac{dx}{ \left(2+3x \right)} = \frac{1}{3} ln \left(2+3x \right) + q$ $\displaystyle (Eq. 4.25)$

Therefore the total solution is:

 $u \left(x \right) = -2.5 \frac{1}{3^3} \left[ \frac{ \left(2+ 3x \right)^2}{2} - 2 \times 2 \left(2+3x \right) + 2^2 ln \left( 2+3x \right) \right] + \frac{k}{3} ln \left(2+3x \right) +q$ $\displaystyle (Eq. 4.26)$

After simplifying everything we obtain:

 $u \left(x \right) = \frac{-5}{12}x^2 + \frac{30}{54}x + pln \left(2+3x \right) + r$ $\displaystyle (Eq. 4.27)$

Where $p$ and $r$ are constants and can be solved using the boundary conditions (Eq.4.20)

 $u \left(1 \right) = 4 = \frac{-5}{12} + \frac{30}{54} + pln \left(5 \right) + r$ $\displaystyle (Eq. 4.28)$

The derivative of u is:

 $\frac{du}{dx} = \frac{-10}{12}x + \frac{30}{54} + \frac{3p}{\left(2+3x \right)}$ $\displaystyle (Eq. 4.29)$

Therefore:

 $\frac{du}{dx} \left(x=0 \right) = \frac{30}{54} + \frac{3p}{2} = -6$ $\displaystyle (Eq. 4.30)$

Solving for $p$ then gives:

 $p = - \frac{118}{27}$ $\displaystyle (Eq. 4.31)$

Replacing $p$ into Eq.4.28 gives:

 $\displaystyle r = 10.895$ $\displaystyle (Eq. 4.32)$

The complete solution is:

 $u \left(x \right) = \frac{-5}{12}x^2 + \frac{30}{54}x - \frac{118}{27} ln \left(2+3x \right) + 10.895$ $\displaystyle (Eq. 4.33)$

### 4.6

Plot $u \left( x \right)$

Fig 4.1 Plot of u(x)

# Problem 5

## Given

 $\overset{b _{i}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0 , i=1,2,...,n$ $\displaystyle (Eq. 5.1)$

## Find

Show that

 $\overset{w}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$ $\displaystyle (Eq. 5.2)$

where $\overset{w}{\rightarrow} = \sum_{i=1}^{n}\alpha_{i} \overset{b _{i}}{\rightarrow}$ ,

with $\forall (\alpha _{1},\alpha _{2},...,\alpha _{n})\in R^{n}$

## Solution

We have $\overset{b _{i}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$

which means

$\overset{b _{1}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$ , $\overset{b _{2}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$ ,..., $\overset{b _{n}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$ .

So there exist arbitrary numbers $( \alpha _{1} , \alpha _{2} ,..., \alpha _{n} )$ that

$\alpha _{1} \overset{b _{1}}{\rightarrow} .\overset{P(v)}{\rightarrow}+$ $\alpha _{2} \overset{b _{2}}{\rightarrow} .\overset{P(v)}{\rightarrow}+...+$ $\alpha _{n} \overset{b _{n}}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$

which is equivalent to the following:

 $\overset{w}{\rightarrow} .\overset{P(v)}{\rightarrow}=0$ $\displaystyle (Eq. 5.3)$

# Problem 6

## Given

Consider $F= \left\{ 1, cos \left(iwx \right), sin \left(iwx \right)\right\}$, where $i=1,2$ on interval $\left[0,T \right]$,

i.e. $\left\{1, cos \left(wx \right), cos \left(2wx \right), sin \left(wx \right), sin \left( 2wx\right) \right\}$

## Find

6.1 Construct $\overset{\Gamma}{\rightarrow}$ (F); Observe the properties of $\overset{\Gamma}{\rightarrow}$

6.2 Find det $\overset{\Gamma}{\rightarrow}$ (F)

6.3 Conclude that F is orthogonal

## Solution

### 6.1

Construct $\overset{\Gamma}{\rightarrow} (F) = \int _{0}^{T} b_i b_j dx , i,j = 1,2,3,4,5$

So

 $\overset{\Gamma}{\rightarrow} (F) = \int _{0}^{T} \begin{bmatrix} 1 &coswx &cos2wx &sinwx &sin2wx \\ coswx &coswxcoswx &coswxcos2wx &coswxsinwx &coswxsin2wx \\ cos2wx &cos2wxcoswx &cos2wxcos2wx &cos2wxsinwx &cos2wxsin2wx \\ sinwx &sinwxcoswx &sinwxcos2wx &sinwxsinwx &sinwxsin2wx \\ sin2wx &sin2wxcoswx &sin2wxcos2wx &sin2wxsinwx &sin2wxsin2wx \end{bmatrix} dx$ $\displaystyle (Eq 6.1)$

First we solve the integral:

 $I = \int _{0}^{T} cos(\frac{2m\pi}{T}x) cos(\frac{2n\pi}{T}x) dx$ $\displaystyle (Eq. 6.2)$
with $\displaystyle m,n=0,1,2$

Then we can write:

 $I= \frac{1}{2} (I+b+I-b)$ $\displaystyle (Eq. 6.3)$

where we add and subtract the quantity

 $b= \int_0^T sin(\frac{2m\pi}{T}x) sin(\frac{2n\pi}{T}x) dx$ $\displaystyle (Eq. 6.4)$

So

 $I= \frac{1}{2} \int_0^T (cos(\frac{2m\pi}{T}x) cos(\frac{2n\pi}{T}x) + sin(\frac{2m\pi}{T}x) sin(\frac{2n\pi}{T}x) + cos(\frac{2m\pi}{T}x) cos(\frac{2n\pi}{T}x) - sin(\frac{2m\pi}{T}x) sin(\frac{2n\pi}{T}x))dx$ $\displaystyle (Eq. 6.5)$

And the identity: $cos(A \pm B)=cosAcosB \mp sinAsinB$ , can be used to have the following result:

 $I= \frac{1}{2} \int_0^T (cos(\frac{2(m-n)\pi}{T} x)+cos(\frac{2(m+n)\pi}{T} x) )dx$ $\displaystyle (Eq. 6.6)$

Performing the integration we have:

 $I=\frac{1}{2} [ \frac{T}{2(m-n)\pi} sin(\frac{2(m-n)\pi}{T} x) + \frac{T}{2(m+n)\pi} sin(\frac{2(m+n)\pi}{T} x) ] \mid_0^T$ $\displaystyle (Eq. 6.7)$

The parameters 2(m-n) and 2(m+n) are integers because n and m are integers; therefore, when the sine is evaluated at T it becomes $sink\pi$ where k is integer and therefore $sink\pi=0$ . When the function is evaluated at 0, clearly the sine is 0 too. However when m=n, the parameter 2(m-n) becomes 0 and the first term of the last equation is indeterminate. But when m=n the integral can be calculated as:

$\int_0^T (cos(\frac{2m\pi}{T}x ))^2 dx$

$=\frac{1}{2} \int_0^T (1+cos(\frac{4m\pi}{T}x )) dx$

$=\frac{1}{2} [x+ \frac{T}{4m\pi} sin(\frac{4m\pi}{T}x )]\mid_0^T$

$=\frac{T}{2}$

We conclude that the integral is $\displaystyle T/2$ when $\displaystyle m=n$ and 0 otherwise.

Following identical procedure, the other integrals can be calculated to obtain:

 $\overset{\Gamma}{\rightarrow} (F) = \frac{T}{2} \begin{bmatrix} 2 &0 &0 &0 &0 \\ 0 &1 &0 &0 &0 \\ 0 &0 &1 &0 &0 \\ 0 &0 &0 &1 &0 \\ 0 &0 &0 &0 &1 \end{bmatrix}$ $\displaystyle (Eq. 6.8)$

and it can be seen that $\overset{\Gamma}{\rightarrow} (F)$ is diagonal.

### 6.2

Because $\overset{\Gamma}{\rightarrow} (F)$ is diagonal, the determinant can be easily calculated as the following:

 $Det(\overset{\Gamma}{\rightarrow} (F)) = T \frac{T}{2}\frac{T}{2}\frac{T}{2}\frac{T}{2} = \frac{T^5}{16}$ $\displaystyle (Eq. 6.9)$

### 6.3

Conclude that $\overset{\Gamma}{\rightarrow} (F)$ is orthogonal.

Although $\overset{\Gamma}{\rightarrow} (F)$ is diagonal, and orthogonal, it is not equal to the identity matrix, therefore it is not equal to $\delta_ij$.

# Problem 7

Consider the family $F=\begin{bmatrix}x,x^2,x^3,x^4 \end{bmatrix}$

Is $F$ an othogonal family evaluated at $\Omega=\begin{bmatrix}0,1 \end{bmatrix}$?

From Lecture 10

## Given

 $F=\begin{bmatrix}x,x^2,x^3,x^4 \end{bmatrix}$ $\displaystyle (Eq. 7.1)$

## Find

Is $F$ an othogonal family evaluated at $\Omega=\begin{bmatrix}0,1 \end{bmatrix}$?

## Solution

Let's start by calculating $\Gamma (F)$

$\Gamma(F)=\int_{0}^{1} \begin{bmatrix} 1,x,x^2,x^3,x^4\\ x,x^2,x^3,x^4,x^5\\ x^2,x^3,x^4,x^5,x^6\\ x^3,x^4,x^5,x^6,x^7\\ x^4,x^5,x^6,x^7,x^8\\ \end{bmatrix}dx$

Performing the integration we obtain:

 $\Gamma(F)= \begin{bmatrix} x,\frac{x^2}{2},\frac{x^3}{3},\frac{x^4}{4},\frac{x^5}{5}\\ \frac{x^2}{2},\frac{x^3}{3},\frac{x^4}{4},\frac{x^5}{5},\frac{x^6}{6}\\ \frac{x^3}{3},\frac{x^4}{4},\frac{x^5}{5},\frac{x^6}{6},\frac{x^7}{7}\\ \frac{x^4}{4},\frac{x^5}{5},\frac{x^6}{6},\frac{x^7}{7},\frac{x^8}{8}\\ \frac{x^5}{5},\frac{x^6}{6},\frac{x^7}{7},\frac{x^8}{8},\frac{x^9}{9}\\ \end{bmatrix}$ $\displaystyle (Eq. 7.2)$

When equation 7.2 is evaluated at (0,1) we obtain:

 $\Gamma(F)= \begin{bmatrix} 1,\frac{1}{2},\frac{1}{3},\frac{1}{4},\frac{1}{5}\\ \frac{1}{2},\frac{1}{3},\frac{1}{4},\frac{1}{5},\frac{1}{6}\\ \frac{1}{3},\frac{1}{4},\frac{1}{5},\frac{1}{6},\frac{1}{7}\\ \frac{1}{4},\frac{1}{5},\frac{1}{6},\frac{1}{7},\frac{1}{8}\\ \frac{1}{5},\frac{1}{6},\frac{1}{7},\frac{1}{8},\frac{1}{9}\\ \end{bmatrix}$ $\displaystyle (Eq. 7.3)$

Where it can clearly be observed that $\Gamma(F)$ is not orthogonal

# Problem 8

Show that equation 1 and equation 2 on 10-4 are equivalent.

From Lecture 11

## Given

Let's define our equations:

Equation 1 on 10-4

 $\int_{\Omega }{}w^{h}(x)P(U^{h}(x))dx=0;\forall w^{h}(x)$ $\displaystyle (Eq.8.1)$

and Equation 2 on 10-4

 ${\int}_{\Omega}{} b_{i}(x)P(U^{h}(x))dx=0$ $\displaystyle (Eq.8.2)$

With

 $w^{h}(x)=\sum_{i=1}^{n}c_{i}b_{i}(x)$ $\displaystyle (Eq.8.3)$

## Find

Show that $eq.8.1$ and $eq.8.2$ are equivalent.

## Solution

If we chose $c_{i}$ to be orthogonal, we have:

$c_{1}=\begin{bmatrix}1,0,...,0 \end{bmatrix}$

$c_{2}=\begin{bmatrix}0,1,...,0 \end{bmatrix}$

$c_{3}=\begin{bmatrix}0,0,...,1 \end{bmatrix}$

When we multiply $c_{i}$ times $b_{i}$ we observe that multiply by $c$ is equivalent to multiplying by the identity matrix, therefore replacing $w^{f}(x)$ in $\displaystyle Eq. 8.1$ we have:

 $\int_{\Omega}^{ }w^{h}(x)P(U^{h}(x))dx=\int_{\Omega}^{ }\sum_{i=1}^{n}c_{i}b_{i}(x)P(U^{h}(x))dx=\int_{\Omega}^{ }I.b.P(U^{h}(x))dx=\int_{\Omega}^{ }b_{i}P(U^{h}(x))dx$ $\displaystyle (Eq. 8.4)$

# Problem 9

## Given

Solving a differential equation using Weight Residual Form. From lecture 12

The partial differential equation is:

 $\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$

As weighting funtion should be used:

 $b_{i} = \cos\left ( ix+\phi \right )$ $\displaystyle (Eq.9.2)$

We will use $\phi = \frac{\pi}{4}$

## Find

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

## Solution

### 9.1 Find an approximate solution with n=2

When n = 2 we have:

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

and

 $b_{i}=\begin{bmatrix} \cos \left ( \frac{\pi}{4}\right )& \cos \left ( x+ \frac{\pi}{4}\right ) & \cos \left ( 2x+ \frac{\pi}{4}\right ) \end{bmatrix}$ $\displaystyle (Eq.9.4)$

Therefore:

 $U^{h}=d0\cos \left (\frac{\pi }{4} \right )+d1\cos \left ( x+\frac{\pi }{4} \right )+d2\cos \left ( 2x+\frac{\pi }{4} \right )$ $\displaystyle (Eq. 9.5)$

### 9.2 Find two equations that enforce the boundary conditions

The boundary conditions are:

 $u(1)= 0 =d0\cos \left (\frac{\pi }{4} \right )+d1\cos \left ( 1+\frac{\pi }{4} \right )+d2\cos \left ( 2+\frac{\pi }{4} \right )$ $\displaystyle (Eq. 9.6)$

And

 $\frac{du}{dx}(0)=-4 = -d1\sin \left ( \frac{\pi }{4} \right )-2d2\sin \left ( \frac{\pi }{4} \right )$ $\displaystyle (Eq. 9.7)$

### 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:

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

The equation 9.8 can be written as:

 $P\left ( U^{h} \right )= -2\begin{bmatrix}0 & \cos \left (x+ \frac{\pi }{4} \right ) & 4\cos \left (2x+ \frac{\pi }{4} \right ) \end{bmatrix}\begin{bmatrix} d0\\ d1\\ d2\end{bmatrix}+3$ $\displaystyle (Eq.9.9)$

Projecting the residue we have:

 $\int_{a}^{b}b(x)P\left ( U^{h} \right )= 0$ $\displaystyle (Eq. 9.10)$

After substitution of (Eq.9.4) and (Eq.9.9) in (Eq.9.10) the following equation is obtained

 $2\int_{0}^{1}\begin{bmatrix} \cos\left ( \frac{\pi }{4} \right ) \\\cos \left (x+ \frac{\pi }{4} \right ) \\ \cos \left ( 2x+\frac{\pi }{4} \right ) \end{bmatrix}\begin{bmatrix} 0 &\cos \left ( x+\frac{\pi }{4}\right ) & 4\cos \left ( 2x+\frac{\pi }{4} \right )\end{bmatrix}dx\begin{bmatrix} d0\\ d1\\ d2\end{bmatrix}=3\int_{0}^{1} \begin{bmatrix} \cos \left ( \frac{\pi }{4} \right )\\ \cos\left ( x+\frac{\pi }{4} \right ) \\ \cos \left ( 2x+\frac{\pi }{4} \right )\end{bmatrix}dx$ $\displaystyle (Eq. 9.11)$

### 9.4 Display the equations in matrix form

Performing the product and then the integration indicated in (Eq.9.11) we have:

 $\begin{bmatrix} 0 & \cos\left ( 1 \right )+\sin\left (1 \right ) -1 & 2\cos\left (2 \right )+2\sin \left (2 \right )-2 \\ 0 & -\frac{1}{2} -\frac{1}{2}\sin \left (1 \right )^{2} +\frac{1}{2}\cos \left (1 \right )^{2}& -\frac{4}{3}+4\sin \left ( 1 \right )+\frac{4}{3}\cos\left ( 3 \right ) \\ 0 & -\frac{1}{3}+\sin \left ( 1\right ) +\frac{1}{3}\cos\left ( 3 \right )& 3-\sin \left ( 2 \right )^{2}+\cos \left ( 2 \right )^{2} \end{bmatrix}\begin{bmatrix} d0\\ d1\\ d2\end{bmatrix}=\begin{bmatrix} 2.121\\ 0.809\\ -0.537\end{bmatrix}$ $\displaystyle (Eq. 9.12)$

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:

 $\begin{bmatrix} \cos\left (\frac{\pi }{4} \right ) &\cos\left (1+\frac{\pi }{4} \right ) & \cos\left (2+\frac{\pi}{4} \right ) \\ 0 &\sin \left (\frac{\pi}{4} \right ) &2\sin \left (\frac{\pi}{4} \right ) \\ 0 & 0.3818 & -1.0137 \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:

 $\begin{bmatrix} d0\\ d1\\ d2\end{bmatrix}=\begin{bmatrix} 1.71\\ 5.61\\ 0.02 \end{bmatrix}$

### 9.6 Construct $U^{h}$ and plot $U^{h}$ and $u$

Replacing d in (Eq.9.5) we obtain the approximated solution:

 $U^{h}=1.71\cos \left (\frac{\pi }{4} \right )+5.61\cos \left ( x+\frac{\pi }{4} \right )+0.02\cos \left ( 2x+\frac{\pi }{4} \right )$ $\displaystyle (Eq.9.14)$

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

 $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.

Fig.9.1 Analytical and numerical solution with n=2

### 9.7 Repeat 9.1 to 9.6) for i = 4 and i = 6

Now we repeat the procedure using i = 4 and i=6 in Eq.9.4

As the procedure is the same shown before, we develop a routine using Matlab to perform the products, the integration and to solve the system of equations. The routine is show in the appendix.

Fig.9.2 and Fig.9.3 shown the numerical solution for i = 4 and i = 6 respectively. It can be clearly seen that as the number of terms used in (Eq.9.4) the agreement between the analytical and numerical solution is better.

Fig.9.4 Show the error at x = 0.5 as funtion of the number of terms used in Eq.9.4. Clearly the error tends to be 0 as the number of terms increases. The error shown in Fig.9.4 was calculated as the absolute value of the difference between the analytical and the numerical solution at x = 0.5

Plots:

Fig.9.2 Analytical and numerical solution with i=4
Fig.9.3 Analytical and numerical solution with i=6
Fig.9.4 Error as a function of the number of functions i

# Appendix

Matlab Code:

clear all;
syms x
b = [cos(pi/4); cos(x+pi/4); cos(2*x+pi/4)]; %this is the bi funtion
d2b = [0 cos(x+pi/4) 4*cos(2*x+pi/4)]; %This is the second derivative of b. The negative
k = b*d2b; %perfoms the product between b and the second derivative
K = 2*int(k,0,1) %performs the integration
F = 3*int(b,0,1)
z = [0:0.1:1];

K3 = [cos(pi/4) cos(1+pi/4) cos(2+pi/4);
0 sin(pi/4) 2*sin(pi/4);
0 -1+cos(1)+sin(1)  -2+2*cos(2)+2*sin(2)];
F3 = [0; 4; 3/2*2^(1/2)];
d3 = inv(K3)*F3; %Calculates di
for i = 1:11

f3(i) = d3(1)*cos(pi/4)+d3(2)*cos(z(i)+pi/4)+ d3(3)*cos(2*z(i)+pi/4);
%calculates Uh
fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution
end
figure, plot(z,f3,'ko') %plots both solution
hold on
plot(z,fnal,'k')
xlabel('x')
ylabel('U(x)')
legend('Numerical solution','Analytical solution')
title('Numerical and analytical solution with i = 2')
err(1) = abs(fnal(6)-f3(6));
%NOW WITH n = 4
syms x
b = [cos(pi/4); cos(x+pi/4); cos(2*x+pi/4); cos(3*x+pi/4); cos(4*x+pi/4) ];
%this is the bi funtion
d2b = [0 cos(x+pi/4) 4*cos(2*x+pi/4) 9*cos(3*x+pi/4) 16*cos(4*x+pi/4)];
%This is the second derivative of b. The negative
k = b*d2b; %perfoms the product between b and the second derivative
K = 2*int(k,0,1) %performs the integration
F = 3*int(b,0,1)
z = [0:0.1:1];

K3 = [cos(pi/4) cos(1+pi/4) cos(2+pi/4) cos(3+pi/4) cos(4+pi/4);
0 sin(pi/4) 2*sin(pi/4) 3*sin(pi/4) 4*sin(pi/4);
0 -1+cos(1)+sin(1)  -2+2*cos(2)+2*sin(2) -3+3*cos(3)+3*sin(3)  ...
-4+4*cos(4)+4*sin(4);
0 1/2-1/2*sin(1)^2+1/2*cos(1)^2  -4/3+4*sin(1)+4/3*cos(3)  ...
-9/4+9/2*sin(2)+9/4*cos(4) -16/5+16/3*sin(3)+16/5*cos(5);
0 -1/3+sin(1)+1/3*cos(3)  3-sin(2)^2+cos(2)^2    -9/5+9*sin(1)+9/5*cos(5)    ...
-8/3+8*sin(2)+8/3*cos(6)];
F3 = [0; 4; 3/2*2^(1/2); -3/2*2^(1/2)+3/2*cos(1)*2^(1/2)+3/2*sin(1)*2^(1/2);
-3/4*2^(1/2)+3/4*cos(2)*2^(1/2)+3/4*sin(2)*2^(1/2)];
d3 = inv(K3)*F3; %Calculates di
for i = 1:11

f3(i) = d3(1)*cos(pi/4)+d3(2)*cos(z(i)+pi/4)+ d3(3)*cos(2*z(i)+pi/4) ...
+d3(4)*cos(3*z(i)+pi/4)+ d3(5)*cos(4*z(i)+pi/4); %calculates Uh
fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution
end
figure, plot(z,f3,'ko') %plots both solution
hold on
plot(z,fnal,'k')
xlabel('x')
ylabel('U(x)')
legend('Numerical solution','Analytical solution')
title('Numerical and analytical solution with i = 4')
err(2) = abs(fnal(6)-f3(6));

%NOW WITH n = 6
syms x
b = [cos(pi/4); cos(x+pi/4); cos(2*x+pi/4); cos(3*x+pi/4); cos(4*x+pi/4); ...
cos(5*x+pi/4); cos(6*x+pi/4)]; %this is the bi funtion
d2b = [0 cos(x+pi/4) 4*cos(2*x+pi/4) 9*cos(3*x+pi/4) 16*cos(4*x+pi/4) ...
25*cos(5*x+pi/4) 36*cos(6*x+pi/4)]; %This is the second derivative of b.
k = b*d2b; %perfoms the product between b and the second derivative
K = 2*int(k,0,1) %performs the integration
F = 3*int(b,0,1)
z = [0:0.1:1];

K3 = [cos(pi/4) cos(1+pi/4) cos(2+pi/4) cos(3+pi/4) cos(4+pi/4) cos(5+pi/4)   ...
cos(6+pi/4);
0 sin(pi/4) 2*sin(pi/4)  3*sin(pi/4)  4*sin(pi/4)  5*sin(pi/4)  6*sin(pi/4);
0 -1+cos(1)+sin(1)  -2+2*cos(2)+2*sin(2) -3+3*cos(3)+3*sin(3)      ...
-4+4*cos(4)+4*sin(4) -5+5*cos(5)+5*sin(5)  -6+6*cos(6)+6*sin(6);
0  1/2-1/2*sin(1)^2+1/2*cos(1)^2  -4/3+4*sin(1)+4/3*cos(3)      ...
-9/4+9/2*sin(2)+9/4*cos(4) -16/5+16/3*sin(3)+16/5*cos(5)     ...
-25/6+25/4*sin(4)+25/6*cos(6)  -36/7+36/5*sin(5)+36/7*cos(7);
0 -1/3+sin(1)+1/3*cos(3)  3-sin(2)^2+cos(2)^2    -9/5+9*sin(1)+9/5*cos(5)        ...
-8/3+8*sin(2)+8/3*cos(6) -25/7+25/3*sin(3)+25/7*cos(7)   -9/2+9*sin(4)+9/2*cos(8);
0 -1/4+1/2*sin(2)+1/4*cos(4)   -4/5+4*sin(1)+4/5*cos(5)     ...
15/2-3/2*sin(3)^2+3/2*cos(3)^2   -16/7+16*sin(1)+16/7*cos(7)      ...
-25/8+25/2*sin(2)+25/8*cos(8)       -4+12*sin(3)+4*cos(9);
0  -1/5+1/3*sin(3)+1/5*cos(5)  -2/3+2*sin(2)+2/3*cos(6)         ...
-9/7+9*sin(1)+9/7*cos(7)     14-2*sin(4)^2+2*cos(4)^2       ...
-25/9+25*sin(1)+25/9*cos(9)  -18/5+18*sin(2)+18/5*cos(10)];

F3 = [0; 4; 3/2*2^(1/2); -3/2*2^(1/2)+3/2*cos(1)*2^(1/2)+3/2*sin(1)*2^(1/2);
-3/4*2^(1/2)+3/4*cos(2)*2^(1/2)+3/4*sin(2)*2^(1/2);
-1/2*2^(1/2)+1/2*cos(3)*2^(1/2)+1/2*sin(3)*2^(1/2);
-3/8*2^(1/2)+3/8*cos(4)*2^(1/2)+3/8*sin(4)*2^(1/2)];
d3 = inv(K3)*F3; %Calculates di
for i = 1:11

f3(i) = d3(1)*cos(pi/4)+d3(2)*cos(z(i)+pi/4)+ d3(3)*cos(2*z(i)+pi/4) ...
+d3(4)*cos(3*z(i)+pi/4)+ d3(5)*cos(4*z(i)+pi/4)+d3(6)*cos(5*z(i)+pi/4)+ ...
d3(7)*cos(6*z(i)+pi/4); %calculates Uh
fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution
end
figure, plot(z,f3,'ko') %plots both solution
hold on
plot(z,fnal,'k')
xlabel('x')
ylabel('U(x)')
legend('Numerical solution','Analytical solution')
title('Numerical and analytical solution with i = 2')
err(3) = abs(fnal(6)-f3(6));
n = [3 5 7]
figure, plot(n,err)
xlabel('n=number of functions')
ylabel('Error')
title('Difference between nalytical and numerical solution as function of i, at x = 0.5')


# Team Member's Contributions

Abhijeet Bhalerao
James Roark
Cedric Adam
Harrison Sheffield
Yu Hao
Fernando Casanova