"Anna Larsen" wrote in message <jfca3a$r4q$1@newscl01ah.mathworks.com>...
> I have the following 3D funktion that I want to plot over a triangular region instead of a rectangular region. How can I solve this problem, and is it possible to z(max)=1
>
> [x,y] = meshgrid(0:0.1:1);
> z = x*(2*x.^2+2*y^2+2*(1xy).^2+3*y.*(1xy)1);
> figure
> surf(x,y,z)
        
You could make a mesh of parameters s and t defined as follows. Let P1 = (x1,y1), P2 = (x2,y2), and P3 = (x3,y3) be the three vertices of your triangle. Then do:
[s,t] = meshgrid(linspace(0,1,100));
x = (1sqrt(s))*x1 + sqrt(s).*((1t)*x2+t*x3);
y = (1sqrt(s))*y1 + sqrt(s).*((1t)*y2+t*y3);
z = x.*(2*x.^2+2*y.^2+2*(1xy).^2+3*y.*(1xy)1);
z(z>1) = 1;
surf(x,y,z)
(Note: The square root avoids having greater density near P1.)
Roger Stafford
