function KulanPlot(varargin)
% Call function with
%
%       KulanPlot(yvec,uvec)
%
% where yvec is a vector giving the positions of the ball,
%  and  uvec is a vector giving the angles of the lever.
% The vectors yvec and uvec must be of equal length.
%
% Written by Mats Werme, KTH.
%

% Start checking data
close all
if nargin ~= 2
    disp(' ')
    disp('The function should be called with two arguments')
    disp(' ')
    return
end
yvec = varargin{1};
uvec = varargin{2};
if length(yvec) ~= length(uvec)
    disp(' ')
    disp('The vectors have to be of equal length')
    disp(' ')
    return
end

% Define the lever and the diameter of the ball
L = 2;
d = 0.3;
% Scale the angle
angle = -0.15*uvec;
% Start the plotting
for k = 1:length(angle)
    clf
    x_bar = L*cos(angle(k));
    y_bar = L*sin(angle(k));
    plot([-x_bar/2 x_bar/2],[-y_bar/2 y_bar/2],'LineWidth',1)
    axis([-L/2 L/2 -L/2 L/2]), hold on, grid %axis off   
    x_B = yvec(k)*cos(angle(k))-d/2;
    y_B = yvec(k)*sin(angle(k));
    rectangle('Curvature',[1 1],'Position',[x_B y_B d d])
    drawnow, pause(0.1)
end