% NONLINEAR PHENOMENA, Spring 2013, UCSB (ECE 183 / ME 169 / PHYS 106)
% Katie Byl
% Lecture 8 (April 25, 2013)
%
% Code to demonstrate the "bead on a hoop", presented in Lecture 6.

global bfac % damping factor

% The values below must match those in the function "bead_od" within 
% the m-file "bead_on_hoop.m"!
g = 9.8;
r = 1.0; % ring radius
m = 0.1; % mass of bead
w = 4; % angular velocity of hoop spinning
phibar = acos(g/(r*w*w)); % equilibrium angle for bead
wn = ((w*sin(phibar))^2 + cos(phibar)*(g/r - w^2*cos(phibar)))^.5
bcrit = 2*wn*m*r % to get "zeta = 1" for critically damped case
%====== Do not change values above without ALSO changing "bead_on_hoop.m"

%%%%%%%%%
% Below, "bfac" is the parameter to play with:
bfac = 1.0*bcrit % bfac > 1 needed for "overdamped" case...
%%%%%%%%%

figure(3); cla
[tout,xout] = bead_on_hoop([.01;0]);

sa = 1;
for n=1:100
    x0 = 1*([rand;rand]*4 - [2;2]);
    [tout,xout] = bead_on_hoop(x0,sa);
    sa = 0;
end

    