Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

1 Getting Started

Fuzzy vs. Nonfuzzy Logic


The Basic Tipping Problem

  77DD 8$F6  7DD


7  86 

"8 E

9$ #86  >7DD? $ 8!((=K


       &$ #
87DD 8&

+
 *'466  ,
< 7> ,F ?$  6E

>6 6 8    &(


87 & &,O$8   8
< 7  &?

The Nonfuzzy Approach

=8  6  &  < ,O7


 6 &

service = 0:.5:10;
tip = 0.15*ones(size(service));
plot(service,tip);
xlabel('Service'); ylabel('Tip');
ylim([0.05 0.25])

>
Fuzzy vs. Nonfuzzy Logic

  #< 7$ 


 <&=  7,$8
8  7O76 -O7F &+ 
  # #7  8 

tip = (.20/10)*service+0.05;
plot(service,tip);
xlabel('Service'); ylabel('Tip');
ylim([0.05 0.25])


1 Getting Started

7     $ 87  &) $


7 < 77   &F76 
7 7  &

2   *'4 766  ,> 


,F ? < 7 < 7
7 $  6E

 7 77    6 &


7  8<

food = 0:.5:10;
[F,S]=meshgrid(food,service);
tip = (0.20/20).*(S+F)+0.05;

)
Fuzzy vs. Nonfuzzy Logic

surf(S,F,tip);
xlabel('Service'); ylabel('Food');zlabel('Tip');

%$  #7$6  #  $ 


<8&  67
7 < & 77O7 88  
7 #-O&<

servRatio = 0.8;
tip = servRatio*(0.20/10*S+0.05) + ...
(1-servRatio)*(0.20/10*F+0.05);
surf(S,F,tip);
xlabel('Service'); ylabel('Food'); zlabel('Tip');

6
1 Getting Started

  7  &  77 


 $&&$ 8,O8 $6  
77F 8 6 &7$$
 8 8 &2  
     &+ $ 
6 7L 8&288   
8$8 8  F8&
tip = zeros(size(service));
tip(service<3) = (0.10/3)*service(service<3)+0.05;
tip(service>=3 & service<7) = 0.15;
tip(service>=7 & service<=10) = ...
(0.10/3)*(service(service>=7 & service<=10)-7)+0.15;
plot(service,tip);

7
Fuzzy vs. Nonfuzzy Logic

xlabel('Service'); ylabel('Tip');
ylim([0.05 0.25]);

F   $ #7 8&

servRatio=0.8;
tip = zeros(size(S));
tip(S<3) = ((0.10/3)*S(S<3)+0.05)*servRatio + ...
(1-servRatio)*(0.20/10*F(S<3)+0.05);
tip(S>=3 & S<7) = (0.15)*servRatio + ...
(1-servRatio)*(0.20/10*F(S>=3 & S<7)+0.05);
tip(S>=7 & S<=10) = ((0.10/3)*(S(S>=7 & S<=10)-7)+0.15)*servRatio + ...
(1-servRatio)*(0.20/10*F(S>=7 & S<=10)+0.05);
surf(S,F,tip);

8
1 Getting Started

xlabel('Service'); ylabel('Food');zlabel('Tip');

  #8 $678   &%    77 
  $  7  7 7&
!$   8 #   
8  8&

The Fuzzy Logic Approach

2  76 $ 8  7


66&%7# 7  6 $8 
7  8  &

 *=  &




9
Fuzzy vs. Nonfuzzy Logic

G %7$
G %78 $8
G %7F $8

    6&%  


 7&%7   7 @77$ 7  8 
 &

 *=  


G %77  $


G %77   $8

26  77 7 8 7  #&

 *=+  &


   
 

G %77  $


G %78 $8
G %7F 7   $8

 7 &0  $L 7 


 77DD 8&"8 8 8
6 > 8$7F ? 7DD7
&  877DD 8  

G )   6 E


G )  % 7  8E

7 7    <&


 7  @ 876 6 
77DD 8@6  F&"  7DD
8 6 $ $    &

Problem Solution

7  8 7DD 8 86 &

gensurf(readfis('tipper'));

:
1 Getting Started

  8 6  76 7


7&7 7DD7 #F  1 
79 79DD8&%$= !  >4%?$
86  # 889DD8 6F>!?&

# &
0 66F 7&27 
     6 &% # $6 6 
$      $ &0 $
7DD 86 &( $ 6 
   67 7  7
  8     6 &!#86<
 7   &

;
Fuzzy vs. Nonfuzzy Logic

!$687DD 8 $77 8


  87   &78887 
$$$6  8 8
7
8 $ 68&

=

 2 6 <# 6 78
7DD 78  87DD 8 &

27 7  7$68 #  


 6  6<#  &

%7  8F $  86  8  #


8&%7767$  6
 8 &
% Establish constants
lowTip = 0.05; averTip = 0.15; highTip = 0.25;
tipRange = highTip-lowTip;
badService = 0; okayService = 3;
goodService = 7; greatService = 10;
serviceRange = greatService-badService;
badFood = 0; greatFood = 10;
foodRange = greatFood-badFood;

% If service is poor or food is rancid, tip is cheap


if service<okayService,
tip = (((averTip-lowTip)/(okayService-badService)) ...
*service+lowTip)*servRatio + ...
(1-servRatio)*(tipRange/foodRange*food+lowTip);

% If service is good, tip is average


elseif service<goodService,
tip = averTip*servRatio + (1-servRatio)* ...
(tipRange/foodRange*food+lowTip);

% If service is excellent or food is delicious, tip is generous


else,
tip = (((highTip-averTip)/ ...
(greatService-goodService))* ...
(service-goodService)+averTip)*servRatio + ...
(1-servRatio)*(tipRange/foodRange*food+lowTip);
end

(   $8   $  8


6&2 6 8$ 8

<
1 Getting Started

 8 8  7  &=$    8


   &

%787 8F7$ 


F 7DD 8     &
% If service is poor or food is rancid, tip is cheap
% If service is good, tip is average
% If service is excellent or food is delicious, tip is generous

%7$ 7DD$    $# 


#  &9DD 8 88 
$8  $ 8$  
7 <76 8886   &

=#8< 6 > ?#8 7


$6  7&) $   8
   7  8&0
6 #8   FP7DD 8  8   
 # 7  &

)>

You might also like