function [u] = NewDirichlet(n) % an example forcing function g = @(x) 10*sin(pi*x(1))*cos(pi*x(2)); % construct a grid, here the code produces a uniform grid % this can easily be modified starting from an arbitrary collection of % points TR = uniform_grid(n); % find boundary vertices - often better constructed along with % triangulation, but for small grids this is adequate boundary = unique(freeBoundary(TR))'; % first stage of assembly [A,f] = NewAssemble(TR,g); % apply boundary conditions A(boundary,:)=0; A(:,boundary)=0; for i = boundary A(i,i)=1; end f(boundary)=0; % solve system, here using explicit methods % for large grids, iterative schemes can be employed instead u = A \ f; % a plot of the result p2 = [TR.Points,u]; TR2 = triangulation(TR.ConnectivityList,p2); trisurf(TR2);