12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

x = [0 0 1 1 0 .41 1 1 0 0 .41 .6 .6 .4 .4 .60 .4 .6 .6 .4 .6];y = [0 1 1 0 0 .40 1 0 0 1 .61 .6 .4 .4 .6 .61 .6 .6 .4 .4 .4];z = [0 0 0 0 0 10 0 0 0 0 10 1 1 1 1 10 1 1 1 1 1];patch(x,y,z,’y’)view(3);xyz,boxz10.51 00.5y0 00.5x1Exercise 22 (Page 171)The faces are coloured according to the colours <strong>of</strong> the vertex. We havevertices defined for z = 0 <strong>and</strong> z = 1, but the heat source is located atz =0.25. The result should be symmetric about the z =0.25 plane,but our result does not have this symmetry. The reason is that we onlyhave two z values. To produce a better display we simply need to addvertices at a range <strong>of</strong> z values. The following code does the job:N = 100; % Number <strong>of</strong> points around the circleM = 30; % Number <strong>of</strong> circles in the cylinderdt = 2*pi/N;t = (0:dt:(N-1)*dt)’;h = linspace(0,1,M); % vector <strong>of</strong> heightsxv = cos(t);yv = sin(t);% Reproduce the vertices at different heights:x = repmat(xv,M,1);y = repmat(yv,M,1);z = ones(N,1)*h;z = z(:);vert = [x y z];% These are the facets <strong>of</strong> a single ’layer’:facets = zeros(N,4);facets(1:N-1,1) = (1:N-1)’;facets(1:N-1,2) = ((N+1):(2*N-1))’;facets(1:N-1,3) = ((N+2):(2*N))’;facets(1:N-1,4) = (2:N)’;facets(N,:) = [N 2*N N+1 1];c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!