function [val,dval] = basisfun (px,py,coord,uv);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% basisfun: P1 on triangular elements
%% works with ACF code (Alberty/Carstensen/Funken)
%% MPeszynska, for MTH 655-9, Winter 2017
%% Mathematics, Oregon State University
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Remarks: returns the value of the FE solution at any points <px,py> 
%% inside the given triangular element, with FE nodal values in <uv>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
d = size(coord,2);
if d ~= 2 return; end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set coordinates and area
%x1 = coord(1,1);x2 = coord(2,1);x3 = coord(3,1);
%y1 = coord(1,2);y2 = coord(2,2);y3 = coord(3,2);

cmat = [coord,[1;1;1]];
cof = zeros(3,3);

r = eye(3);r=r(:,1);cof(:,1) = cmat\r;
r = eye(3);r=r(:,2);cof(:,2) = cmat\r;
r = eye(3);r=r(:,3);cof(:,3) = cmat\r;
%coord,cof

val = uv(1)*(cof(1,1)*px + cof(2,1)*py + cof(3,1));
val = val + uv(2)*(cof(1,2)*px + cof(2,2)*py + cof(3,2));
val = val + uv(3)*(cof(1,3)*px + cof(2,3)*py + cof(3,3));

dval(1) = uv(1)*cof(1,1) + uv(2)*cof(1,2) + uv(3)*cof(1,3);
dval(2) = uv(1)*cof(2,1) + uv(2)*cof(2,2) + uv(3)*cof(2,3);


