You are on page 1of 2

Explanation of FEM2Order1D: This seems to be one of the most basic functions in the library that Oleksyn produced.

It produces the stiness matrix using a function valuated over the step size h from 0 to 1.
1 Notes on Oleksyns Programming
Oleksyns thesis contains many programs. This is a review of the dierent programs that he seems to actually have used in
the implementation. This will also be a survey of the way in which they t together.
Major Components: Before going into his most basic examples, we need to look at the way in which he builds up the
stiness matrices and load vectors. This involves:
1. Creating a 1-D grid consisting of N dierent steps going from 0 to 1.
2. Take that grid and evaluate it at dierent points for a function F and a function G.
3. Turn F and G into a load vector (F) and stiness matrix (G). This involves approximating the integral over the grid
using Simpsons rule.
Stiness2order1D:
function MatrixK = Stiffness2order1D(kvec)
N=length(kvec)-2;
h=1/(N+1);
for i=1:N
K(i,i)= (1/(2*h))*(kvec(i)+2*kvec(i+1)+kvec(i+2));
end
Note that the integral is approximated at each point using Simpsons rule.
for i=1: N-1
K(i+1,i)=-1/(2*h)*( kvec(i+1)+kvec(i+2));
K(i,i+1)=K(i+1,i);
end
This section constructs the sub and superdiagonals of the matrix which will be the same. Above we see that building a stiness
matrix from the original function involves feeding a vector containing its discrete valuations into the integral approximation
function to build the main diagonal. To build the super diagonal, we use a similar expression derived from the basis functions
MatrixK=K;
end
We also have to construct the load vector. This is much more simple - we feed in the function F and then use a basic loop
to construct the values of the load vector over the grid:
for i=1:N
F(i,1)=(h/6)*(f(xk(i))+4*f(xk(i+1))+f(xk(i+2)));
end
Explanation of FEM2Order1D:
function NumerU = FEM2order1D(k, f, N)
h = 1/(N+1);
The step size.
xk = 0:h:1;
Our vector containing the grid.
kvec = k(xk);
1
Output feeding the grid points into the function k.
%stiffness matrix
K=Stiffness2order1D(kvec);
%load vector
F=Load2order1D(f,N);
NumerU=K\F;
In the nal lines, we see that this just constructs the stiness matrix using just the rst function argument. The second
function argument is used to construct the load vector. Then the system of equations represented by the stiness matrix is
solved in terms of the load vector. This script is displayed below:
N=5;
h = 1/(N+1);
xk = 0:h:1;
We set up the step size, and calculate the value for h. xk represents a vector going from 0 to 1 consisting of that h step size.
ffun = @(x)(-4*x.^3+6*x.^2+2);
kfun = @(x)((x.^3+1).^2);
ufun = @(x)((x-x.^2)./(x.^3+1));
%ffun = @(x)(-(64*x.^2-64*x+32/3)./(2-x)+(log(2-x)+1).*(128*x-64));
%kfun = @(x)(log(2-x)+1);
%ufun = @(x)(-64/3*x.^3+32*x.^2-32/3*x);
The dierent functions we might produce using this program.
OutU=FEM2order1D(kfun, ffun, N);
ApprU = [0; OutU; 0];
ExactU= ufun(xk);
At this point, we just graph the approximation
plot(xk, ApprU, xk, ExactU);
subplot(2,1,1)
X=0:0.001:1;
Y=ufun(X);
plot(X,Y);
title(EXACT SOLUTION)
axis tight
subplot(2,1,2)
plot(xk,ApprU)
title(NUMERICAL SOLUTION)
axis tight
2

You might also like