User:Eml5526.s11.team01/Hwk3
Problem 1: Solving using WRF[edit]
Solving a differential equation using Weight Residual Form. From lecture 13
Given[edit]
The partial differential equation is:
The boundary conditions are:


A weighting funtion should be used:
Find[edit]
- 1.1 Find an approximate solution of the form
for n=2 - 1.2 Find two equations that enforce the boundary conditions
- 1.3 Project the weight residues
- 1.4 Display the equations in matrix form
- 1.5 Solve for

- 1.6 Construct
and plot
and 
- 1.7 Repeat 1.1 to 1.6 for n = 4 and n = 6
Solution[edit]
1.1 Find an approximate solution with n=2[edit]
When n = 2 we have:
and
Therefore:
1.2 Find two equations that enforce the boundary conditions[edit]
The boundary conditions are:
And
1.3 Project the weight residues[edit]
In this case changing the function u(x) by the approximated function
in the PDE (Eq.1.1), we found that P(u) is:
The (Eq.1.8) can be written as:
Projecting the residue we have:
After substitution of (Eq.1.4) and (Eq.1.9) in (Eq.1.10) the following equation is obtained
1.4 Display the equations in matrix form[edit]
Performing the product and then the integration indicated in (Eq.1.11) we have:
The latter equation is clearly of the form
. We can observe that K is not symmetric.
1.5 Solve for
[edit]
In (Eq.1.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.1.6) and (Eq.1.7). From these equations we now have the system:
After solving the system in (Eq.1.13) by using a calculator, we obtain d:
1.6 Construct
and plot
and
[edit]
Replacing d in (Eq.1.5) we obtain the approximated solution:
On the other hand, the exact solution of the PDE (Eq.1.1) with the given boundary condition is:
We observe that the aproximated and the exact solution are the same; therefore, increasing the number of terms in b(x) will not improve the solution
In Fig.1.1 we show the exact and the approximated solution.
1.7 Repeat 1.1 to 1.6) for i = 4 and i = 6[edit]
Now we repeat the procedure using i = 4 and i=6 in Eq.1.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. The error was also Zero for i = 4, and i = 6.
Appendix[edit]
Matlab Code:
clear all; x = sym('x'); b = [1 x+1 (x+1)^2]; db = [0 0 2]; k = b'*db; K = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 2 4; 0 1 2; 0 0 4]; f1 = [0 -4 -3]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)+1) + d(3)*(z(i)+1)^2; %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end figure, plot(z,f2,'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)-f2(6)); %Now for n = 4 x = sym('x'); b = [1 x+1 (x+1)^2 (x+1)^3 (x+1)^4]; db = [0 0 2 6*(x+1) 12*(x+1)^2]; k = b'*db; K2 = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 2 4 8 16; 0 1 2 3 4; 0 0 4 18 56; 0 0 6 28 90; 0 0 28/3 45 744/5]; f1 = [0 -4 -3 -9/2 -7]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)+1) + d(3)*(z(i)+1)^2+d(4)*(z(i)+1)^3+d(5)*(z(i)+1)^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,f2,'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(2) = abs(fnal(6)-f2(6)); %Now for n = 6 x = sym('x'); b = [1 x+1 (x+1)^2 (x+1)^3 (x+1)^4 (x+1)^5 (x+1)^6]; db = [0 0 2 6*(x+1) 12*(x+1)^2 20*(x+1)^3 30*(x+1)^4]; k = b'*db; K2 = 2*int(k,0,1) f = -3*int(b',0,1) K1 = [1 2 4 8 16 36 64; 0 1 2 3 4 5 6; 0 0 4 18 56 150 372; 0 0 6 28 90 248 630; 0 0 28/3 45 744/5 420 7620/7; 0 0 15 372/5 252 5080/7 3825/2; 0 0 124/5 126 3048/7 1275 10220/3]; f1 = [0 -4 -3 -9/2 -7 -45/4 -93/5]'; d = inv(K1)*f1 z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)+1) + d(3)*(z(i)+1)^2+d(4)*(z(i)+1)^3+d(5)*(z(i)+1)^4 +d(6)*(z(i)+1)^5+d(7)*(z(i)+1)^6; %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end figure, plot(z,f2,'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)-f2(6));
Problem 2: Spring System[edit]
Given[edit]
Spring System with closed ends.
Find[edit]
- 2.1 Number the Element and Nodes.
- 2.2 Assemble the Global Stiffness and Force Matrix.
- 2.3 Partition the system and solve for the Nodal Displacements.
- 2.4 Compute the Reaction Forces.
Solution[edit]
2.1 Number the Element and Nodes.[edit]
The Spring Systems is shown in the figure.
Superscripts to each of the stiffness values denotes the element number. Furthermore, Node Numbers are also shown in the figure. As shown in the figure, there are 4 nodes.
2.2 Assemble the Global Stiffness and Force Matrix.[edit]
For Element Number 1,
and
,

For Element Number 2,
and
,

For Element Number 3,
and
,

For Element Number 4,
and
,

Assembled Global Systems Matrix will be given by,
Where Superscript
denotes the Element Number.
The Displacement and Global Force Matrices for this system are given by,
|
|
2.3 Partition the system and solve for the Nodal Displacements.[edit]
Eventually, The Global System of Equations is Given by,


As the first two displacements are prescribed, We can Partition the system after 2 Rows and 2 Columns,
And Can form the Matrix System of Equivalent to,

Where,

Solving the Following Reduced System of Equations,

Using
we can form the Following Simultaneous Equations,




Solving These 2 Simultaneous Equations, We get,
|
|
2.4 Compute the Reaction Forces.[edit]
Now, Utilizing the First row of the math>\displaystyle (Eq.2.1) </math> we can get
![]() |
And Further, Utilizing the Second row of the math>\displaystyle (Eq.2.1) </math> we can get,
|
|
Problem 3: Truss Structure[edit]
Given[edit]
The truss Structure Shown in the Figure. Nodes A & B are fixed. A Force of 10N Acts in the Positive x-Direction at node C. Young's Modulus is
and the Cross Sectional Area for all bars are 
Find[edit]
- 3.1 Number the Element and Nodes
- 3.2 Assemble the Global Stiffness and Force Matrix
- 3.3 Partition the system and solve for the Nodal Displacements
- 3.4 Compute the Stresses & Reactions
Solution[edit]
3.1 Number the Element and Nodes[edit]
The Truss System Along with the Element Numbers and the Node Numbers Written on it, is Shown in the figure.
3.2 Assemble the Global Stiffness and Force Matrix[edit]
For Element Number 1,
and
, Also Element 1 is inclined at 90 deg to the Positive X-direction,
,
,
,
Using the Following formula for obtaining the Elemental Stiffness Matrix for all the elements,


Utilizing above equation for Element 1,

For Element Number 2,
and
, Also Element 2 is inclined at 90 deg to the Positive X-direction,
,
,
, Therefore,

For Element Number 3,
and
, Also Element 3 is inclined at 135 deg to the Positive X-direction,
,
,
, Therefore,

For Element Number 4,
and
, Also Element 4 is inclined at 90 deg to the Positive X-direction,
,
,
, Therefore,

Making the Assembly of all these 4 Elemental Matrices, we get the following Global Stiffness Mtria for the given Truss System,
|
|

Now, Only force is acting in positive X-Direction at C, and there will be Reactions at A & B.
Therefore, The Force Matrix Can be Assembled as,
|
|

3.3 Partition the system and solve for the Nodal Displacements[edit]
From
&
The Global System os Equation will be,

As the Displacements are prescribed untill second node, Partitioning the systems after second row and column and further comparing with the following equation,

we get, 
Eventually, we can obtain,

But
is a Zero Matrix, which will yield,
Solving this system in MATLAB, Using the following code, we get,
Matlab Code:
kf=[1+1/(2*sqrt(2)) -1/(2*sqrt(2)) -1 0;-1/(2*sqrt(2)) 1+1/(2*sqrt(2)) 0 0;-1 0 1 0;0 0 0 1] f=[0;0;10;0] %force matrix A=inv(kf)*f
|
|

These are the Unknown Nodal Displacements.
3.4 Compute the Stresses & Reactions[edit]
Now the Reactions can be calculated as,

But again
is a Zero Matrix, Which will give,
.
Using the Following MATLAB Code to obtain the Reaction Matrix,
Matlab Code:
kef=[0 0 0 0;0 -1 0 0;-1/(2*sqrt(2)) 1/(2*sqrt(2)) 0 0;1/(2*sqrt(2)) -1/(2*sqrt(2)) 0 -1] df=[38.2843;10;48.2843;0] re=kef*df %Reaction Matrix
|
|

These are the Unknown Reactions. Now We can calculate the Stress in each element using the following formula,


Now we can utilize the above equation to calculate the Stresses for all the elements,
For element 1,
&

Using the Following MATLAB code, Matlab Code:
%For element e=1 to 4 calculation of Stress x=[0 -1e11 0 1e11] y=5e-10*[0;0;38.2843;10] z=x*y
Therefore,
|
|
In the similar fashion, For Element 2, Utilizing
we get,
|
|
For Element 3, Utilizing
we get,
|
|
Finally, For Element 4, Utilizing
we get,
|
|
Problem 4 : Show that
does not equal
[edit]
Given[edit]
Given
And
Find[edit]
Show that 
Solution[edit]
Let
And
Assume that
and
. Therefore, equations 3.3 and 3.4 become:
Differentiating:
Plugging in values and re-arranging
By inspection of terms
and
it can be shown that
Problem 5: Equivalent Stiffness of a Spring[edit]
Given[edit]
A spring is given in Figure 5.1 as follows:
Find[edit]
Show that the equivalent stiffness of a spring aligned in the x direction for the bar of thickness t with a centered square hole shown in Figure 5.1 is can be described by
Solution[edit]
The left end is constrained, i.e., prescribed displacement is zero at the left end.
Assume there is a force F acting on the right end, and the nodes are numbered in (Fig.5.2) .
The Element stiffness matrices are the following:
By direct assembly, the global stiffness matrix is:
The displacements and force matrices for the system are:
The global system of equations is given by:
Solve the matrix equation above; we can have the following four equations
Because we have the following relationship:
Then we can get the following results:
Substitute (Eq.5.8) into (Eq.5.6), we can have the following result:
where
is the displacement of node 4.
And then,
which yields:
Problem 6: Three Bar Structure[edit]
Given[edit]
Given a three bar structure subjected to the prescribed load at point C equal to
as shown in Figure 2.19 of the book. The Young's modulus is
, the cross-sectional area of the bar BC is
and that of BD and BF is
. Note that point D is free to move in the x-direction. Coordinates of joints are given in meters.
Find[edit]
- 6.1 Construct the global stiffness matrix and load matrix.
- 6.2 Partition the matrices and solve for the unknown displacements at Point B and displacement in the x-direction at point D.
- 6.3 Find stresses in the three bars.
- 6.4 Find the reactions at nodes C,D,F.
Solution[edit]
6.1 Construct the global stiffness matrix and load matrix[edit]
For Element 3, 

For Element 2, 

For Element 1, 

Global Stiffness Matrix


Therefore

6.2 Partition the matrices and solve[edit]
Global system of equations:

Partitions


Unknown displacement at B is solved by

Subtracting the first term from both sides of the above equation and premultiply by
, we obtain

Solving for the displacements we get: 
6.3 Find stresses in the three bars[edit]
Element 3 Stress

Element 2 Stress

Element 1 Stress

6.4 Find the reactions at nodes C,D,F.[edit]
Reactions can be solved using this equation and the global matrix


Problem 7: Solving using WRF[edit]
Solving a differential equation using Weight Residual Form. From lecture 17
Given[edit]
The partial differential equation is:
The boundary conditions are:


As weighting function should be used:
Find[edit]
- 7.1 Find an approximate solution of the form
for n=2 - 7.2 Find two equations that enforce the boundary conditions
- 7.3 Project the weight residues
- 7.4 Display the equations in matrix form
- 7.5 Solve for

- 7.6 Construct
and plot
and 
- 7.7 Repeat 7.1 to 7.6 for n = 4 and n = 6
Solution[edit]
7.1 Find an approximate solution with n=2[edit]
When n = 2 we have:
and
Therefore:
7.2 Find two equations that enforce the boundary conditions[edit]
The boundary conditions are:
Differentiating
And evaluating
7.3 Project the weight residues[edit]
In this case changing the function
by the approximated function
in the PDE (Eq.7.1), we found that
is:
The (Eq.7.8) can be written as:
Projecting the residue we have:
After substitution of equations 7.4 and 7.9) in 7.10, the following equation is obtained
7.4 Display the equations in matrix form[edit]
Performing the product and then the integration indicated in equation 7.11, we have
The latter equation is clearly of the form
. We can observe that matrix K is not symmetric.
7.5 Solve for
[edit]
In equation 7.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 equations 7.6 and 7.7. From these equations we now have the system:
The latter is a linear system and can be solved by using any calculator. After solving the system in (Eq.7.13) we obtain d:
7.6 Construct
and plot
and
[edit]
Replacing
in equation 7.5 we obtain the approximated solution:
On the other hand, the exact solution of the PDE (Eq.7.1) with the given boundary condition is:
We observe that the approximated and the exact solution are not the same. Perhaps they would be closer if we increased the number of terms. Figure 7.1 we show the exact and the approximated solution.
7.7 Repeat 7.1 to 7.6) for i = 4 and i = 6[edit]
Now we repeat the procedure using n = 4 and n=6 in Eq.7.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 shown below in the appendix. Figures 7.2 and 7.3 show the results of n=4 and n=6, respectively. Figure 7.4 shows the error versus the number of terms.
Appendix[edit]
Matlab Code:
clear all; x = sym('x'); b = [1 x (x)^2]; db = [0 0 2]; k = b'*db; K = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 1 1; 0 1 2; 0 0 2]; f1 = [0 -4 -3]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)) + d(3)*(z(i))^2; %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end figure, plot(z,f2,'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)-f2(6)); x = sym('x'); b = [1 x (x)^2 (x)^3 (x)^4]; db = [0 0 2 6*(x) 12*(x)^2]; k = b'*db; K2 = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 1 1 1 1; 0 1 2 3 4; 0 0 2 6 12; 0 0 0 6 24; 0 0 0 0 24]; f1 = [0 -4 -3 -9/2 -7]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)) + d(3)*(z(i))^2+d(4)*(z(i))^3+d(5)*(z(i))^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,f2,'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 n = 4') err(2) = abs(fnal(6)-f2(6)); %Now for n = 6 x = sym('x'); b = [1 x (x)^2 (x)^3 (x)^4 (x)^5 (x)^6]; db = [0 0 2 6*(x) 12*(x)^2 20*(x)^3 30*(x)^4]; k = b'*db; K2 = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 1 1 1 1 1 1; 0 1 2 3 4 5 6; 0 0 2 6 12 20 30; 0 0 0 6 24 60 120; 0 0 0 0 24 120 360; 0 0 0 0 0 120 720; 0 0 0 0 0 0 720]; f1 = [0 -4 -3 -9/2 -7 -45/4 -93/5]'; d = inv(K1)*f1 z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*(z(i)) + d(3)*(z(i))^2+d(4)*(z(i))^3+d(5)*(z(i))^4 +d(6)*(z(i))^5+d(7)*(z(i))^6; %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end figure, plot(z,f2,'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 n = 6') err(3) = abs(fnal(6)-f2(6)); n = [2 4 6] figure, plot(n,err) xlabel('n=number of functions') ylabel('Error') title('Difference between anlytical and numerical solution as function of i, at x = 0.5')
Problem 8: Weak Form Proof[edit]
Given[edit]
The Strong form is:
on 1<x<3,
Find[edit]
Show that the weak form is:
-
with 

Solution[edit]
Equation (8.1b) is a condition on the derivative of u(x), so it is a natural boundary conditon; (8.1c) is a condition on u(x), so it is an essential boundary condition. Therefore, as the weight function must vanish on the essential boundaries, we consider all smooth weight functions w(x) such that w(3)=0. The trial solutions must satisfy the essential boundary condition u(3) = 0.001.
We start by multiplying the governing equation and the natural boundary condition over the domains where they hold by an arbitrary weight function:
Next we integrate (Eq.8.3) by parts, then we get the following result:
We have constructed the weight functions so that w(3)=0; therefore, the first term on the RHS of (Eq.8.5) vanishes at x=3. Substituting (Eq.8.5) into (Eq.8.3) gives:
with w(3)=0. Substituting (Eq.8.4) into the first term of (Eq.8.6) gives:
with w(3)=0.
Problem 9: A solution to the weak form in Problem 3.1[edit]
Consider a trial (candidate) solution of the form
and a weight function of the same form. Obtain a solution to the weak form in Problem 3.1. Check the equilibrium equation in the strong form in Problem 3.1; is it satisfied?
Check the natural boundary condition; is it satisfied?
Solution[edit]


Using boundary conditions from Problem 3.9


Only one unknown parameter and one arbitrary parameter remain


Now substitute into Problem 3.1 weak form


Integrating and factoring out
we get:

The
goes to zero and
can be solved:

Therefore the solution to the weak form is

Checking for equilibrium in the strong form, values are substituted into

This yields
which does not satisfy.
Checking the natural boundary condition, this equation is used

Substituting in
we get

Thus, this boundary condition will satisfy only for large values of 
Problem 10: Fish and Belytschko Problem 3.4[edit]
Repeat Problem 3.3 with the trial solution
.
Find[edit]
Consider a trial (candidate) solution of the form
and a weight function of the same form. Obtain a solution to the weak form in Problem 3.1. Check the equilibrium equation in the strong form in Problem 3.1; is it satisfied?
Check the natural boundary condition; is it satisfied?
Given[edit]
The weak from is given by
with 
Solution[edit]
The trial solution
and the weight function
can be written as follows:


When:

and for:

and
can therefore be re-written as follows:


Whith their respective derivatives:


Now substituting into the weak form yields:
![\int_{1}^{3} AE[\beta_{1}+2\beta_{2}\left(x-3\right)][\alpha_{1}+2\alpha_{2}\left(x-3\right)]dx = -0.1[A(\beta_{1}\left(x-3\right)+\beta_{2}\left(x-3\right)^{2})]_{x=1} + \int_{1}^{3} 2x[\beta_{1}\left(x-3\right)+\beta_{2}\left(x-3\right)^{2}]dx](http://upload.wikimedia.org/math/5/a/7/5a720c8fdd4023a8b6a41b924103ca9f.png)
which can be re-arranged as:
![\int_{1}^{3} AE[\beta_{1}+2\beta_{2}\left(x-3\right)][\alpha_{1}+2\alpha_{2}\left(x-3\right)]dx - 0.1[A(\beta_{1}\left(x-3\right)+\beta_{2}\left(x-3\right)^{2})]_{x=1} - \int_{1}^{3} 2x[\beta_{1}\left(x-3\right)+\beta_{2}\left(x-3\right)^{2}]dx = 0](http://upload.wikimedia.org/math/1/f/b/1fb7c48f488320644415977ea09acfae.png)
Evaluating the integral we get:
![AE \left(2\alpha_{1}\beta_{1}-4\alpha_{1}\beta_{2}-4\alpha_{2}\beta_{1}+\frac{32\alpha_{2}\beta_{2}}{3}\right)- 0.1[A(4\beta_{2}-2\beta_{1})] - \left(8\beta_{2}-\frac {20\beta_{1}}{3}\right)=0](http://upload.wikimedia.org/math/8/d/2/8d29c86e296ab059c64d7d0c3023570f.png)
Factoring out
and
we get:
![\beta_{1}\left[2AE\left(\alpha_{1}-2\alpha_{2}\right)-0.2A+\frac{20}{3}\right]+\beta_{2}\left[4AE\left(\frac{8}{3}\alpha_{2}-\alpha_{1}\right)+0.4A-8\right]=0](http://upload.wikimedia.org/math/8/8/8/888bb4a8f500a4cb5dcd31eddf39adad.png)
and
must be zero since they were arbitrarely chosen and because the above equation must hold. Therefore we can write both terms of the above equation equal to zeor as folows:
![\left[2AE\left(\alpha_{1}-2\alpha_{2}\right)-0.2A+\frac{20}{3}\right]=0](http://upload.wikimedia.org/math/b/b/1/bb1512fbdb815a4209b6b01aab640552.png)
and
![\left[4AE\left(\frac{8}{3}\alpha_{2}-\alpha_{1}\right)+0.4A-8\right]=0](http://upload.wikimedia.org/math/7/5/b/75b9dc6ff2a82299518b40fd243735f6.png)
Solving for
and
we find that:

and

The solution to the weak form can be written as
Checking if equilibrium in the strong form is satisfied, substituted into the equations:

Yields the following:

which does not satisfy.
Checking if the natural boundary condition is satisfied, the following equation can be used:

Problem 11: Solving using WRF[edit]
Solving a differential equation using Weight Residual Form. From lecture 17
Given[edit]
The partial differential equation is:
The boundary conditions are:


As weighting funtion should be used:
Find[edit]
- 11.1 Find an approximate solution of the form
for n=2 - 11.2 Find two equations that enforce the boundary conditions
- 11.3 Project the weight residues
- 11.4 Display the equations in matrix form
- 11.5 Solve for

- 11.6 Construct
and plot
and 
- 11.7 Repeat 1.1 to 1.6 for n = 4 and n = 6
Solution[edit]
11.1 Find an approximate solution with n=2[edit]
When n = 2 we have:
and
Therefore:
11.2 Find two equations that enforce the boundary conditions[edit]
The boundary conditions are:
And
11.3 Project the weight residues[edit]
In this case changing the function u(x) by the approximated function
in the PDE (Eq.11.1), we found that P(u) is:
The (Eq.11.8) can be written as:
Projecting the residue we have:
After substitution of (Eq.11.4) and (Eq.11.9) in (Eq.11.10) the following equation is obtained
11.4 Display the equations in matrix form[edit]
Performing the product and then the integration indicated in (Eq.1.11) we have:
The latter equation is clearly of the form
. We can observe that K is not symmetric.
11.5 Solve for
[edit]
In (Eq.11.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.11.6) and (Eq.11.7). From these equations we now have the system:
After solving the system in (Eq.11.13), by using the code shown in apedix, we obtain d:
11.6 Construct
and plot
and
[edit]
Replacing d in (Eq.11.5) we obtain the approximated solution:
On the other hand, the exact solution of the PDE (Eq.11.1) with the given boundary condition is:
11.7 Repeat 11.1 to 11.6) for i = 4 and i = 6[edit]
Now we repeat the procedure using i = 4 and i=6 in Eq.11.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.
In Fig.11.1 we show the exact and the approximated solution for i = 2,4, and 6. In that figure, it can be observed that all the numerical solutions fits very well the analytical solution.
We found a small error for i = 2 (0.0003); however the error lightly increases for i = 4 and decreases again for i = 6. As all the solutions are close to the analytical, we believe that this error is mainly due to round-off error which is increased with i = 4 and i = 6 due to the higher number of operations that the program has to perform. Fig. 11.2 shows the error variation as a function of i
Appendix[edit]
Matlab Code:
clear all; x = sym('x'); b = [1 cos(x) sin(x) cos(2*x) sin(2*x)]; db = -[0 cos(x) sin(x) 4*cos(2*x) 4*sin(2*x)]; k = b'*db; K = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 cos(1) sin(1) cos(2) sin(2); 0 0 1 0 2; 0 -1.6829 -0.9194 -3.6372 -5.6646; 0 -1.4546 -0.7081 -3.5540 -4.4921; 0 -0.7081 -0.5454 -0.8145 -3.1777]; f1 = [0 -4 -3 -3*sin(1) -3+3*cos(1)]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*cos(z(i)) + d(3)*sin(z(i)) + d(4)*cos(2*z(i)) + d(5)*sin(2*z(i)); %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end plot(z,fnal,'k') hold on plot(z,f2,'ko') %plots both solution % xlabel('x') % ylabel('U(x)') % legend('Numerical solution','Analytical solution') % title('Numerical and analytical solution with i = 2') err(1) = abs(fnal(6)-f2(6)); %Now for n = 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x = sym('x'); %w = 2*pi; w = 1; b = [1 cos(x) sin(x) cos(2*x) sin(2*x) cos(3*x) sin(3*x) cos(4*x) sin(4*x)]; db = -[0 cos(x) sin(x) 4*cos(2*x) 4*sin(2*x) 9*cos(3*x) 9*sin(3*x) 16*cos(4*x) 16*sin(4*x)]; k = b'*db; K = 2*int(k,0,1); f = -3*int(b',0,1); K1 = [1 cos(1) sin(1) cos(2) sin(2) cos(3) sin(3) cos(4) sin(4); 0 0 1 0 2 0 3 0 4; 0 -1.6829 -0.9194 -3.6372 -5.6646 -0.8467 -11.9400 6.0544 -13.2291; 0 -1.4546 -0.7081 -3.5540 -4.4921 -2.3890 -10.0934 2.3159 -12.9056; 0 -0.7081 -0.5454 -0.8145 -3.1777 2.6520 -5.7946 8.3210 -3.8212; 0 -0.8885 -0.2036 -3.2432 -1.6536 -5.8472 -5.4267 -6.5293 -11.4354; 0 -1.1230 -0.7944 -1.6536 -4.7568 2.8479 -9.2993 11.2230 -8.0195; 0 -0.2654 0.2947 -2.5987 1.2657 -8.5809 -0.0597 -14.9652 -7.9177; 0 -1.1215 -0.6438 -2.4119 -4.1330 -0.0597 -9.4191 6.7927 -11.9619]; f1 = [0 -4 -3 -3*sin(1) -3+3*cos(1) -3/2*sin(2) -3/2+3/2*cos(2) -sin(3) -1+cos(3)]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*cos(z(i)) + d(3)*sin(z(i)) + d(4)*cos(2*z(i)) + d(5)*sin(2*z(i))+ ... d(6)*cos(3*z(i)) + d(7)*sin(3*z(i))+d(8)*cos(4*z(i)) + d(9)*sin(4*z(i)) ; %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end plot(z,f2,'r+') %plots both solution % xlabel('x') % ylabel('U(x)') % legend('Analytical solution','Numerical solution i = 2','Numerical solution i = 4') %title('Numerical and analytical solution with i = 2') err(2) = abs(fnal(6)-f2(6)); %Now for n = 6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x = sym('x'); b = [1 cos(x) sin(x) cos(2*x) sin(2*x) cos(3*x) sin(3*x) cos(4*x) sin(4*x) cos(5*x) sin(5*x) cos(6*x) sin(6*x)]; db = -[0 cos(x) sin(x) 4*cos(2*x) 4*sin(2*x) 9*cos(3*x) 9*sin(3*x) 16*cos(4*x) 16*sin(4*x) 25*cos(5*x) 25*sin(5*x) 36*cos(6*x) 36*sin(6*x)]; k = b'*db; K = 2*int(k,0,1) f = -3*int(b',0,1) K1 = [1 cos(1) sin(1) cos(2) sin(2) cos(3) sin(3) cos(4) sin(4) cos(5) sin(5) cos(6) sin(6); 0 0 1 0 2 0 3 0 4 0 5 0 6; 0 -1.6829 -0.9194 -3.6372 -5.6646 -0.8467 -11.9400 6.0544 -13.2291 9.5892 -7.1634 3.3530 -0.4780; 0 -1.4546 -0.7081 -3.5540 -4.4921 -2.3890 -10.0934 2.3159 -12.9056 5.8942 -10.5012 3.5255 -6.4233; 0 -0.7081 -0.5454 -0.8145 -3.1777 2.6520 -5.7946 8.3210 -3.8212 10.1693 3.5658 3.8920 10.2830; 0 -0.8885 -0.2036 -3.2432 -1.6536 -5.8472 -5.4267 -6.5293 -11.4354 -3.5224 -17.4622 2.3591 -20.0375; 0 -1.1230 -0.7944 -1.6536 -4.7568 2.8479 -9.2993 11.2230 -8.0195 15.7044 1.1704 9.7280 11.2633; 0 -0.2654 0.2947 -2.5987 1.2657 -8.5809 -0.0597 -14.9652 -7.9177 -14.4580 -21.2815 -3.3419 -31.5244; 0 -1.1215 -0.6438 -2.4119 -4.1330 -0.0597 -9.4191 6.7927 -11.9619 14.1221 -8.2745 16.2354 -0.0450; 0 0.1447 0.5201 -1.6323 2.8057 -8.4179 3.8209 -17.9787 -2.2910 -22.1815 -16.8011 -14.4089 -32.1113; 0 -0.8066 -0.2388 -2.8588 -2.0049 -4.4537 -6.7285 -2.2910 -14.0213 6.1837 -19.8920 18.8700 -18.3258; 0 0.2358 0.4068 -0.5636 2.5127 -5.2049 5.0840 -14.1962 3.9576 -23.6399 -4.5977 -27.0203 -19.8074; 0 -0.4200 0.1426 -2.7940 0.1873 -7.6613 -2.9788 -10.7527 -12.7309 -4.5977 -26.3601 13.2909 -33.5657]; f1 = [0 -4 -3 -3*sin(1) -3+3*cos(1) -3/2*sin(2) -3/2+3/2*cos(2) -sin(3) -1+cos(3) -3/4*sin(4) -3/4+3/4*cos(4) -3/5*sin(5) -3/5+3/5*cos(5)]'; d = inv(K1)*f1; z = [0:0.1:1]; for i = 1:11 f2(i) = d(1)+ d(2)*cos(z(i)) + d(3)*sin(z(i)) + d(4)*cos(2*z(i)) + d(5)*sin(2*z(i))+ ... d(6)*cos(3*z(i)) + d(7)*sin(3*z(i))+d(8)*cos(4*z(i)) + d(9)*sin(4*z(i)) + d(10)*cos(5*z(i))+... d(11)*sin(5*z(i))+ d(12)*cos(6*z(i)) + d(13)*sin(6*z(i)); %calculates Uh fnal(i) = -(3/4)*z(i)*z(i)-4*z(i)+19/4; %This is the analytic solution end plot(z,f2,'bd') %plots both solution xlabel('x') ylabel('U(x)') legend('Analytical solution','Numerical solution i = 2','Numerical solution i = 4','Numerical solution i = 6') %title('Numerical and analytical solution with i = 2') err(3) = abs(fnal(6)-f2(6)); h = [2 4 6 ]; figure, plot(h,err,'k') xlabel('Number of funtions i') ylabel('error at x = 0.5')




for n=2































.









does not equal 
![\alpha =b_{i}\left[ a_{2}^{\prime }b_{j}^{\prime }+a_{2}b_{j}^{\prime \prime } \right]](http://upload.wikimedia.org/math/1/2/1/12197c72d560499f7933911e17a52464.png)
![\beta =b_{j}\left[ a_{2}^{\prime }b_{i}^{\prime }+a_{2}b_{i}^{\prime \prime } \right]](http://upload.wikimedia.org/math/d/c/d/dcd4b36939f549ffec1c830e0e222336.png)




































![d_{i}=\left[ \begin{matrix}
d_{0} & d_{1} & d_{2} \\
\end{matrix} \right]](http://upload.wikimedia.org/math/d/6/0/d60b80e6ae296a2d8ac8941e7084bde9.png)

![b_{i}=\left[ \begin{matrix}
1 & \left( x \right) & \left( x \right)^{2} \\
\end{matrix} \right]](http://upload.wikimedia.org/math/4/4/d/44d7c8e07f40ba7b6c637ebc8cddde4d.png)









![P\left( U^{h} \right)=\left[ \begin{matrix}
0 & 0 & 4 \\
\end{matrix} \right]\left[ \begin{matrix}
d_{0} \\
d_{1} \\
d_{2} \\
\end{matrix} \right]+3](http://upload.wikimedia.org/math/a/2/a/a2a6d4cf9da9ddab303d57efd12b9a78.png)


![\int_{0}^{1}{\left[ \begin{matrix}
1 \\
x \\
x^{2} \\
\end{matrix} \right]}\left[ \begin{matrix}
0 & 0 & 4 \\
\end{matrix} \right]dx\left[ \begin{matrix}
d_{0} \\
d_{1} \\
d_{2} \\
\end{matrix} \right]=-3\int_{0}^{1}{\left[ \begin{matrix}
1 \\
x \\
x^{2} \\
\end{matrix} \right]}dx](http://upload.wikimedia.org/math/0/0/1/001b2878f183e7e46d81ca6f83cf8e2b.png)

![\left[ \begin{matrix}
0 & 0 & 4 \\
0 & 0 & 2 \\
0 & 0 & \frac{4}{3} \\
\end{matrix} \right]\left[ \begin{matrix}
d_{0} \\
d_{1} \\
d_{2} \\
\end{matrix} \right]=\left[ \begin{matrix}
-3 \\
-\frac{3}{2} \\
-1 \\
\end{matrix} \right]](http://upload.wikimedia.org/math/4/2/1/421fab50d0d43811ab2ed02e648f534a.png)

![\left[ \begin{matrix}
1 & 1 & 1 \\
0 & 1 & 2 \\
0 & 0 & 2 \\
\end{matrix} \right]\left[ \begin{matrix}
d_{0} \\
d_{1} \\
d_{2} \\
\end{matrix} \right]=\left[ \begin{matrix}
0 \\
-4 \\
-3 \\
\end{matrix} \right]](http://upload.wikimedia.org/math/e/f/2/ef2e8b8a9590903039dd25ed84a1c259.png)

![\left[ \begin{matrix}
d_{0} \\
d_{1} \\
d_{2} \\
\end{matrix} \right]=\left[ \begin{matrix}
\frac{5}{2} \\
-1 \\
-\frac{4}{3} \\
\end{matrix} \right]](http://upload.wikimedia.org/math/8/d/d/8dd84bb61069bb3e65082e56418c775e.png)









with 

![\int_{1}^{3} w [\frac{\mathrm{d} }{\mathrm{d} x}(AE\frac{\mathrm{d} u}{\mathrm{d} x})+2x]dx = 0 , \forall w(x),](http://upload.wikimedia.org/math/d/b/e/dbe630dc70fd7e03468e8b1d5fd9df15.png)

![[wA(E\frac{\mathrm{d} u}{\mathrm{d} x}-0.1)]_{x=1} = 0, \forall w(1).](http://upload.wikimedia.org/math/b/2/2/b22e7b2ce870032d14c384085a29b68b.png)

![\int_{1}^{3} [w (\frac{\mathrm{d} }{\mathrm{d} x}AE\frac{\mathrm{d} u}{\mathrm{d} x})]dx = \left (wAE\frac{\mathrm{d} u}{\mathrm{d} x} \right )\mid _{x=1}^{x=3} - \int_{1}^{3} \frac{\mathrm{d} w }{\mathrm{d} x}AE\frac{\mathrm{d} u}{\mathrm{d} x}dx](http://upload.wikimedia.org/math/c/d/5/cd503dcf25563ea7d04603599e3efb23.png)

































