Agenda 27 March 2013

%

% Note: Test Dry Run Friday

%

% Today:

% Matrix Multiply Divide (normal operator not .*)

% Plotting Surfaces

% Array Operations

Arrays same size or one scalar

Used .* operator

Result was same size as larger

Product of corresponding elements

Matrix Operations

Uses normal * operator

Matrices do not have to be the same size

(columns in first = rows in second)

(result is a matrix of columns2 x rows2)

%% ______Matrix Operations______

clear

clc

% simultaneous equations

% ax + by + cz = u

% dx + ey + fz = v

% gx + hy + kz = w

%

% A(3*3) * V(3*1) = B(3*1)

A = [1 2 3

4 5 6

-7 8 9];

B = [ 5

-6

2]

V = inv(A) * B

V1 = A \ B

B1 = A * V

_____ Surfaces ______

______Plotting/Surfaces ______

meshgrid(x, y)- creates the fabric

mesh(xx,yy,zz) – white with edges

surf(XX, yy, zz)- filled

______simple surface plot -----

clear

clc

close all

x = -3:3;

y = x;

[xx,yy] = meshgrid(x,y);

zz = xx.^2 + yy.^2;

mesh(xx, yy, zz)

%surf (xx, yy, zz)

axis tight

title('z = x^2 + y^2')

xlabel('xx'), ylabel('yy'), zlabel('zz')

______Good Example______

clear

clc

close all

x = -3:0.01:3;

[xx yy] = meshgrid(x, x);

zz = xx.^4 + yy.^4;

zz(zz > 70) = NaN;

zz = zz ./ 10;

%subplot(1, 2, 1)

%mesh(xx, yy, zz)

%subplot(1,2,2)

surf(xx, yy, zz)

shading interp

axis equal

%axis off

colormap copper

lightangle(45, -45)

______cylinder______

clear

clc

close all

x = [0 2];

r = 1;

th = linspace(0, 2*pi);

[xx tth] = meshgrid(x, th);

yy = r .* cos(tth);

zz = r .* sin(tth);

surf(xx, yy, zz)

colormap bone

shading interp

alpha(0.7)

% axis off

lightangle(45, 45)

_____top/bowl other ------

clear

clc

close all

% create v = fn(u)

%

u = linspace(0,1);

v = u .^ 4;

th = linspace(0, 2*pi);

[uu tth] = meshgrid(u, th);

vv = meshgrid(v, th);

rr = vv;

xx = uu;

zz = rr .* cos(tth);

yy = rr .* sin(tth);

surf(xx, yy, zz)

colormap bone

shading interp

alpha(0.7)

%axis off

lightangle(45, 45)

______donut ______

clear

clc

close all

% create v = fn(u)

%

phi = linspace(0, 2*pi);

R = 5;

r = 2;

%u = r.*cos(phi);

u = R + r.*cos(phi);

v = r.*sin(phi);

th = linspace(0, 2*pi);

[uu tth] = meshgrid(u, th);

vv = meshgrid(v, th);

rr = uu;

zz = vv;

xx = rr .* cos(tth);

yy = rr .* sin(tth);

surf(xx, yy, zz)

colormap copper

shading interp

alpha(0.7)

axis equal

%axis off

lightangle(45, 45)

------sphere ------

clear

clc

close all

R = 5;

r = 2.5;

phi = linspace(0, 2*pi);

u = R + r .* cos(phi);

v = r .* sin(phi);

th = linspace(0, 2*pi);

[uu tth] = meshgrid(u, th);

vv = meshgrid(v, th);

rr = vv;

xx = uu;

% just doit Part 2

zz = rr .* cos(tth);

yy = rr .* sin(tth);

surf(xx, yy, zz)

______rotating stuff ______

function Rotating_stuff_3

clear

clc

close all

x = -3:0.1:3;

y = x;

[xx yy] = meshgrid(x, y);

zz = xx .^ 2 + yy .^ 2;

ang = 0;

th = 0;

while true

drawIt(xx, yy, zz)

drawIt(xx + 12, yy, zz)

drawIt(xx, yy + 12, zz)

shading interp

colormap copper

lightangle(45, 20)

axis equal

xlabel('X')

ylabel('Y')

zlabel('Z')

view(ang, 45)

ang = ang + 1;

th = th + 0.05;

pause(0.03)

hold off

end

end

function drawIt(xx, yy, zz)

surf(xx, yy, zz)

hold on

end

____ easy example ____

clear

clc

close all

x = -3:0.02:3;

y = -4:0.02:4;

[xx yy] = meshgrid(x, y);

zz = xx.^2 .* yy.^2;

surf(xx, yy, zz)

shading interp

colormap copper

grid off

lightangle(-45, 45)