Getting Started with Fuzzy Logic Toolbox, Part 1
From the series: Getting Started with Fuzzy Logic Toolbox
Use Fuzzy Logic Toolbox™ to design fuzzy logic systems.
Fuzzy Logic Toolbox provides graphical user interfaces, MATLAB functions, and Simulink blocks for designing and simulating Fuzzy Logic systems. When is Fuzzy Logic useful? It is useful when you're developing system models and nonlinear controllers when precise definitions and boundaries do not exist or are too rigid.
Let's consider an example. In this simple demo, we will build a Fuzzy Logic system to solve the tipping problem shown here, which is to determine the proper tip percentage for a waiter in a restaurant based on quality of service and quality of food. In the United States, the average tip is 15% but can vary depending on the quality of food and service. So what we want here is to create a mapping between two inputs-- quality of food and quality of service-- and the output-- tip amount.
You would like to create the mapping somewhat similar to what is shown here. Tip should be generous when food and service are great and should be low when they are bad with somewhat flat area in the middle at about 15%, which is average tip percentage. First, let's see how you would solve that problem with non-fuzzy approach if we didn't use Fuzzy Logic Toolbox.
So what we see here is MATLAB codes that we would have to write. It creates this piece-wise linear surface that we saw in the previous slide. And this code is parametrized so that we can easily change our definitions of good and bad, food and service, and cheap and generous tip in numerical terms.
We see that the quote is difficult to understand and probably difficult to modify and maintain. It is made somewhat easier to understand by comments. What if you could use the rules described in these comments for directly designing the logic?
This is where Fuzzy Logic and Fuzzy Logic Toolbox come in. So those are the three simple rules that we have. And the Fuzzy Logic is a good solution here because it's easier to formulate the answer using simple linguistic rules as shown here. And trying to code this in MATLAB without using Fuzzy Logic Toolbox is difficult. Code is hard to understand and difficult to maintain and change.
So in that demo, we will design and simulate this Fuzzy Logic system from scratch. And in the process, you will see the various important capabilities of Fuzzy Logic Toolbox. We will go through four basic steps of building and simulating a Fuzzy Logic system.
First, define inputs and outputs. Second, great membership functions. Third, creates rules. And fourth and final, simulate the resulting Fuzzy Logic system.
All of the steps can be accomplished by using Fuzzy Logic command line functions. However, it is often more convenient to use graphical user interfaces. And that is what we will do here.
So let's now switch to MATLAB. And we will start Fuzzy Logic Toolbox by typing fuzzy at MATLAB command line. This starts the first of the five graphical user interfaces that we will see in this demo-- FIS editor, which stands for Fuzzy Inference System.
The FIS editor handles the high level issues for the system such as number of input and output variables and variable names. Fuzzy Logic toolbox doesn't limit the number of inputs or outputs allowed. This example, as we saw, has two inputs and one output.
So let's start by defining these two inputs and one output. By default, we have one input and one output. So we will add a new input variable, and we will define inputs and outputs.
The first input is going to be quality of service. We'll call it service. The second output is going to be quality of food. We'll call it food.
And the output is going to be tip percentage. We'll call it tip. OK.
This system diagram shows the name of the system and the type of inference used. We see is that the system was untitled right now. So let's save it. For that, we're going to File, Menu, and Export to File.
And we will save it into file tipper_demo. So now we see the name of our system. In this area, we see pop-up menus which are used to adjust fuzzy inference functions such as and method, or method, and defuzzification method. We will leave all these at their default values. The status line here describes the most recent declaration.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- United Kingdom (English)
- Australia (English)
- India (English)
- New Zealand (English)
- 日本Japanese (日本語)
- 한국Korean (한국어)