Mathematica 9 is now available
Fuzzy Logic Products
-----
 /
Fuzzy Logic
*What's New in Version 2?
*Features
*Sample Images
*Contents
*Q&A
*Examples
*Classifying Houses
*Representing Age
*Finding the Disjunctive Sum
<Natural Numbers
*Fuzzy Hedges
*Distance Relation
*Choosing a Job
*Digital Fuzzy Sets
*Image Processing
*References
*Who's It For?
*Download Product
Manual
*Buy Online
*Technical FAQs
*Documentation
*For More Information
*Higher Education Solutions
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

Example 4: Natural Numbers

Problem. Suppose you are asked to define the set of natural numbers close to 6. There are a number of different ways in which you could accomplish this using fuzzy sets.

Solution 1. One solution would be to manually create a fuzzy set describing the numbers near 6. This can be done as follows:

SetOptions[FuzzySet, UniversalSpace -> {0, 
20}] ;

Six1 = FuzzySet[{{3, .1}, {4, .3}, {5, .6}, 
{6, 1.0}, {7, .6}, {8, .3}, {9, .1}}] ;

FuzzyPlot[Six1] ;

[Graphics:HTMLFiles/natural_4.gif]

Solution 2. A second solution would be to use the FuzzyTrapezoid function to create the fuzzy set. For a case such as this, a triangular fuzzy set would probably be better than a trapezoid, so we set the middle two parameters of the FuzzyTrapezoid function to 6.

Six2 = FuzzyTrapezoid[2, 6, 6, 10] ;

FuzzyPlot[Six2] ;

[Graphics:HTMLFiles/natural_7.gif]

Solution 3. Another solution would be to use a function to create a fuzzy set representing numbers near 6.

CloseTo[x_] := 1/(1 + (#1 - x)^2) &

We can use this function to create a fuzzy set for numbers near 6.

Six3 = CreateFuzzySet[CloseTo[6]] ;

FuzzyPlot[Six3] ;

[Graphics:HTMLFiles/natural_11.gif]

Note that this is a convenient method because the function CloseTo can be called with any integer argument to produce a fuzzy set close to that number.

Solution 4. Still another solution is to use a piecewise function to describe the fuzzy set.

NearSix[x_] := Which[x == 6, 1, x > 6 && x < 12,
1/(x - 5)^2, x < 6 && x > 0, 1/(7 - x)^2, True, 0]

Six4 = CreateFuzzySet[NearSix] ;

FuzzyPlot[Six4] ;

[Graphics:HTMLFiles/natural_15.gif]

Now, we can view all four of our fuzzy representations of the number six to see how they compare. We do this by plotting them all on the same graph with the FuzzyPlot function.

FuzzyPlot[Six1, Six2, Six3, Six4, PlotJoined -> True] ;

[Graphics:HTMLFiles/natural_17.gif]

Any questions about topics on this page? Click here to get an individual response.