function f=J2(smid,sdev)
% max J2 (or von Mises norm of sdev-smid)

sa=zeros(size(sdev));
for i=1:size(sdev,1)
	sa(i,:)=sdev(i,:)-smid;
end

for i=1:size(sa,1) % make stress tensor
	s=[sa(i,1) sa(i,4) sa(i,5);...
	   sa(i,4) sa(i,2) sa(i,6);...
	   sa(i,5) sa(i,6) sa(i,3)];
	% evaluate SUM(SijSji)	
	t=0;
	for k=1:3
		for l=1:3
			% t=xxx;
		end
    end
	% sJ2(i)=xxx;
end
f=max(sJ2);
