Example Creating Surfaces in MATLAB
Using the three commands meshsurface
[x, y] = meshgrid([-2:0.2:2],[-2:0.2:2])
z = x.^2 - y.^2;
mesh(x,y,z)
surf(x,y,z)
[c,h]=contour(x,y,z,[-2,-1,0,1,2]);
clabel(c,h)
Usefull links:
http://pages.pacificcoast.net/~cazelais/260/surface-plot.pdf
http://www.mathworks.com/help/techdoc/ref/surface.html
http://www.math.neu.edu/~braverman/Teaching/Fall2000/surface-contour.pdf
http://online.redwoods.cc.ca.us/instruct/darnold/MULTCALC/SURFACE/Context_Surface-s.pdf
[x, y] = meshgrid([-2:0.2:2],[-2:0.2:2])
z = x.^2 - y.^2;
mesh(x,y,z)
surf(x,y,z)
[c,h]=contour(x,y,z,[-2,-1,0,1,2]);
clabel(c,h)
Usefull links:
http://pages.pacificcoast.net/~cazelais/260/surface-plot.pdf
http://www.mathworks.com/help/techdoc/ref/surface.html
http://www.math.neu.edu/~braverman/Teaching/Fall2000/surface-contour.pdf
http://online.redwoods.cc.ca.us/instruct/darnold/MULTCALC/SURFACE/Context_Surface-s.pdf
Example working on Delauny triangulation
x=[ 1 2 3 ];
y=[ 1 2 2 ];
z=[ 1 2 3 ];
tri=delaunay(x,y);
trisurf(tri,x,y,z);
http://www.mathworks.com/help/techdoc/ref/delaunay.html
Excellent Link:
http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/demoDelaunayTri.html
y=[ 1 2 2 ];
z=[ 1 2 3 ];
tri=delaunay(x,y);
trisurf(tri,x,y,z);
http://www.mathworks.com/help/techdoc/ref/delaunay.html
Excellent Link:
http://www.mathworks.com/products/matlab/demos.html?file=/products/demos/shipping/matlab/demoDelaunayTri.html
Example Modeling a Venturi Nozzel in MATLAB
t = 0:pi/10:2*pi;
[X,Y,Z] = cylinder(2+cos(t));
surf(X,Y,Z)
axis square
This example is done using the revolve command around an axis.The following link provides the required piece of code: http://www.math.byu.edu/~gvol/math.html.
[X,Y,Z] = cylinder(2+cos(t));
surf(X,Y,Z)
axis square
This example is done using the revolve command around an axis.The following link provides the required piece of code: http://www.math.byu.edu/~gvol/math.html.
Example
clc
clear
N=250;
M=9;
H=120;
dh=H/M;
tth=30;
th=tth*(pi/180);
h=[0:dh:H];
c=M+1;
for i=1:M;
c=c-1;
r(c)=h(i)*cos(th)
end th=360/N;
co=pi/180;
theta(1)=0;
alpha(1)=co*theta(1);
for j=1:M;
for i=1:N;
theta(i+1)=theta(i)+th;
alpha(i+1)=co*theta(i+1);
x(i,j)=r(j)*cos(alpha(i));
y(i,j)=r(j)*sin(alpha(i));
z(i,j)=h(j)+2.16*randn(1,1);
plot3(x(i,j),y(i,j),z(i,j),'*r');
hold on
end
end
grid on
for j=1:M-1;
for i=1:N;
v1=[x(i,j) x(i,j+1)];
v2=[y(i,j) y(i,j+1)];
v3=[z(i,j) z(i,j+1)];
f=line(v1,v2,v3);
end
end
clear
N=250;
M=9;
H=120;
dh=H/M;
tth=30;
th=tth*(pi/180);
h=[0:dh:H];
c=M+1;
for i=1:M;
c=c-1;
r(c)=h(i)*cos(th)
end th=360/N;
co=pi/180;
theta(1)=0;
alpha(1)=co*theta(1);
for j=1:M;
for i=1:N;
theta(i+1)=theta(i)+th;
alpha(i+1)=co*theta(i+1);
x(i,j)=r(j)*cos(alpha(i));
y(i,j)=r(j)*sin(alpha(i));
z(i,j)=h(j)+2.16*randn(1,1);
plot3(x(i,j),y(i,j),z(i,j),'*r');
hold on
end
end
grid on
for j=1:M-1;
for i=1:N;
v1=[x(i,j) x(i,j+1)];
v2=[y(i,j) y(i,j+1)];
v3=[z(i,j) z(i,j+1)];
f=line(v1,v2,v3);
end
end
Polygon
clc
clear
xv = [0.1 0.4 0.15 0.1];
yv = [0 0.4 0.8 0];
x = rand(150,1);
y = rand(150,1);
in = inpolygon(x,y,xv,yv);
plot(xv,yv,x(in),y(in),'r+',x(~in),y(~in),'bo')
clear
xv = [0.1 0.4 0.15 0.1];
yv = [0 0.4 0.8 0];
x = rand(150,1);
y = rand(150,1);
in = inpolygon(x,y,xv,yv);
plot(xv,yv,x(in),y(in),'r+',x(~in),y(~in),'bo')
Reading List
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com