So this is the function I want graph using surf.m:
%simple multivariate function;
function [f]=ps2func(x1,x2)if ((x1<=2) &&(x2<=2)) f=4.*x1+3.*x2; %case 1 for the function
elseif ((x1>2) &&(x2>2)) f=x1.^2+x2.^2; %case 2 for the function
else f=0; %case 3 for the function
end%this is the suf.m function i used in an attempt to graph it:
x1 = 1:.1:4;x2 = 1:.1:4;[X,Y] = meshgrid(x1,x2);Z= [f]; mesh(X,Y,Z)grid onhold on
Best Answer