Code covered by the BSD License

# Discrete Lorenz Water Wheel Simulation

by

### Trevor (view profile)

This is a simulation of an 8 tank lorenze water wheel. The water speed is manually controlled.

plotLorenze(r,theta,h,t,P)
```function  plotLorenze(r,theta,h,t,P)

% Plotting for the Lorenze Wheel (controlling Lorenze with NLC)
% Trevor Slade working with PRISM, under Dr. Hedengren
% PRISM group, Brigham Young University
% -----------------------------------------------------------------

% Vectors r,theta, and h must be oriented vertically !!!

% r and theta are matrices containing the position values for the center
% of each tank.

persistent drawOutline;
persistent drawLiquid;

% normalize r so that it is 1

% Convert to Cartesian

x = r.*cos(theta);
y = r.*sin(theta);

tank_Height = P.TH;
tank_Width = P.TW;

% Find the Corners of the Tanks

T.y_1 = y - .5*tank_Height;
T.y_2 = y + .5*tank_Height;

T.x_1 = x - .5*tank_Width;
T.x_2 = x + .5*tank_Width;

% Find the Corners of the water in the tanks
buffer = .01;

W.y_1 = y - tank_Height/2+buffer;
W.y_2 = y - tank_Height/2 + buffer + h./tank_Height*(tank_Height - 2*buffer);

W.x_1 = x - .5*tank_Width + buffer;
W.x_2 = x + .5*tank_Width - buffer;

% Data to plot the circle

% Faces Matrix for plots

facesOutline = ones(length(r),4);
sizeR = length(r);

for i = 1:length(r)

ind1 = i;
ind2 = sizeR+i;
ind3 = 2*sizeR + i;
ind4 = 3*sizeR + i;

facesOutline(i,:) = [ind1,ind2,ind4,ind3];

end

facesLiquid = facesOutline;

if t == 0

r_star = mean(r);
r_circ = mean(r_star)*ones(1000,1);
theta_circ = linspace(0,2*pi,1000)';

x_circ = r_circ.*cos(theta_circ);
y_circ = r_circ.*sin(theta_circ);

figure(1),clf

plot(x_circ,y_circ,'k');

axis([-1.5*r_star,1.5*r_star,-1.5*r_star,1.5*r_star])

% plot the Tank Outline

% verticies are ordered as follows: x1,y1; x1,y2; x2,y1; x2,y2

vertsOutline = [ T.x_1,T.y_1; T.x_1,T.y_2; T.x_2,T.y_1; T.x_2,T.y_2];

vertsLiquid = [ W.x_1,W.y_1; W.x_1,W.y_2; W.x_2,W.y_1; W.x_2,W.y_2];

drawOutline = patch('Faces',facesOutline,'Vertices',vertsOutline,'FaceColor','w');
drawLiquid = patch('Faces',facesLiquid,'Vertices',vertsLiquid,'FaceColor','c');

else

vertsOutline = [ T.x_1,T.y_1; T.x_1,T.y_2; T.x_2,T.y_1; T.x_2,T.y_2];

vertsLiquid = [ W.x_1,W.y_1; W.x_1,W.y_2; W.x_2,W.y_1; W.x_2,W.y_2];

set(drawOutline,'Vertices',vertsOutline);
drawnow
set(drawLiquid,'Vertices',vertsLiquid);
drawnow
end

end
```