
function mf = petal_mf(x, dimension, size)
% Input parameters: x is an array, dimension and size are strings.
% Dimension can be lenth or width, Size may be small, medium or large.

%	Larry Bush September 20, 2001
%   email: bushl2@rpi.edu
%   Student ID: 660 220 742  

%  MF 

% This function calculates the membership functions.


x = x(:);

% Respective triangular MF parameters:
angle = zeros(2,3);
angle(1,:) =  [ -1.2 -.6 .2] ;
angle(2,:) =  [-.2 .6  1.2];
%angle(1,:) =  [ -.5 -.20 -.1] ;
%angle(2,:) =  [-.20 -.1  0   ];
angle(3,:) =  [ -.1  0    .1 ];
angle(4,:) =  [ 0     .1  .20];
angle(5,:) =  [  .1   .20 .5 ];

angular_velocity = zeros(2,3);
% worked  angular_velocity(1,:) =  [-10 -2 2];
%worked  angular_velocity(2,:) =  [ -2 2  10];
angular_velocity(1,:) =  [-10 -5 2];
angular_velocity(2,:) =  [ -2 5  10];
angular_velocity(3,:) =  [ -1  0  1];
angular_velocity(4,:) =  [  0  1  5];
angular_velocity(5,:) =  [  1  5 10];

cart_position = zeros(2,3);
cart_position(1,:) =  [ -10 -5 2] ;
cart_position(2,:) =  [-2 5  10];
cart_position(3,:) =  [ -.1  0    .1 ];
cart_position(4,:) =  [ 0     .1  .20];
cart_position(5,:) =  [  .1   .20 10 ];

cart_velocity = zeros(2,3);
cart_velocity(1,:) =  [-10 -5 2];
cart_velocity(2,:) =  [ -2 5  10];
cart_velocity(3,:) =  [ -1  0  1];
cart_velocity(4,:) =  [  0  1  5];
cart_velocity(5,:) =  [  1  5 10];

%Choose which MF parameters to use based on the dimension and size parameters passed in.
if strcmp(dimension,'angle'),
	    mf = triangle_mf(x,angle(size,:) );
           
elseif strcmp(dimension, 'angular_velocity'),
    	mf = triangle_mf(x,angular_velocity(size,:) );

elseif strcmp(dimension,'cart_position'),
	    mf = triangle_mf(x,cart_position(size,:) );
           
elseif strcmp(dimension, 'cart_velocity'),
    	mf = triangle_mf(x,cart_velocity(size,:) );

else
   	error('Unknown Dimension.');
end
