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
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';
F1  =  accumarray(elem(:),vt,[N  1]);

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?

  • 1
    $\begingroup$ 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. $\endgroup$ – Jed Brown Dec 1 '13 at 15:30
  • 1
    $\begingroup$ 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. $\endgroup$ – Shuhao Cao Dec 2 '13 at 17:23