# assembly matrices in finite element method [closed]

I'm trying to construct the right–hand side of my 2D Poisson's equation in Matlab. I used the vertex rule in order to approximate the integral:

function F1 = rightVer(p,t,f)

%area triangle
it1=t(1,:);
it2=t(2,:);
it3=t(3,:);
area = ((p(1,it2)-p(1,it1)).*(p(2,it3)-p(2,it1))-(p(1,it3)-p(1,it1)).*(p(2,it2)-p(2,it1)))/2;

area = abs(area)/3;
vt1 = area.*f(p(1,it1),p(2,it1));
vt2 = area.*f(p(1,it2),p(2,it2));
vt3 = area.*f(p(1,it3),p(2,it3));

vt = [vt1';vt2';vt3'];
elem = t';
elem(:,4)=[];
N=size(p,2);
F1  =  accumarray(elem(:),vt,[N  1]);
end


I also construct it with the pde toolbox with the function assema() but the two f which I obtained are the same except for the last 4 numbers. Can anyone help me?

• It is unclear what question is being asked. Asking for debugging help with a chunk of code isn't searchable and isn't likely to help other people. This site works better when you pose questions that may be encountered by other people attempting to do similar things. – Jed Brown Dec 1 '13 at 15:30
• Where are the last 4 nodes? What is p(end-4:end,:)? Are those nodes on boundary? Mostly like MATLAB already modified the Dirichlet boundary's load. – Shuhao Cao Dec 2 '13 at 17:23