function y = g(x) y = zeros(size(x)); %region 1 idx = find(x>-1 & x<2); if ~isempty(idx) t=x(idx)+1; y(idx)=t.*t/3; end %region 2 idx = find(x>=2 & x<=3); if ~isempty(idx) y(idx)=3; end %region 3 idx = find(x>3 & x<6); if ~isempty(idx) t = x(idx)-3; y(idx)=3-t.*t/3; end