% FEm.PSE template, steady conduction with a source, quadratic basis


global X1;	%  node coordinates

% set up problem parameters
Tb = 0;         % fixed temperature applied to both ends
A = 100;        % source strength parameter
L = 1;          % length of the domain
cond = 0.1;     % constant conductivity
nnodes = 9;     % 9 grid points for four quadratic elements

% set up grid and source data
X1 = linspace(0,L,nnodes); 
SRC = (A * sin(pi*X1/L))'; % nodal source data.  column matrix.

load femlib;    % load library matrix data

% set up diffusion matrix
DIFF = asjac1D(cond,[],[],-1,'A211Q',[]);

% set up data column matrix
b = asres1D([],[],[],1,'A200Q',SRC);

% enforce the left Dirichlet B.C.
DIFFdiri = DIFF;  % copy DIFF
DIFFdiri(1,:) = zeros(1,nnodes);
DIFFdiri(1,1) = 1;
b(1,1) = Tb;

%  enforce the right Dirichlet B.C.
DIFFdiri(nnodes,:) = zeros(1,nnodes);
DIFFdiri(nnodes,nnodes) = 1;
b(nnodes,1) = Tb;

%  Solve for Q
Q = DIFFdiri \ b

% Calculate the energy norm
format long; % display Enorm in long format
Enorm = 0.5 * Q' * DIFF * Q
format short;


