MATLAB: IF..THEN rules

fuzzyif then rulesMATLAB

Hi,
I want to create if..then rules using Matlab coding. I know that there is tool box for fuzzy, but I am trying to do it in a different way.
Suppose I have 3 membership functions (x1 and x2 are the inputs, and y is the output).
x = 0:0.01:1
x1 = gaussmf(x, [0.125 0.5]) %medium
x2 = gaussmf(x, [0.0625 0.125]) %low
y = gaussmf(x, [0.15 0.6]) %medium
Now I try to relate these membership functions based on this rule:
'If x1 is medium and x2 is low, then y is medium.'
Is there any code for this?
Thank you.

Best Answer

Hey,
Following is an example going through various process included for achieving a fully functional fuzzy inference system
Take the example of an autonomous plane flying at an optimal altitude (Ao), and we are trying to control throttle based on altitude.
Ar is the current altitude and error= Ar — Ao. Error-dot is equal to the rate of change of error.
Based on error Let us define the outputs as Increase throttle, No Change, and Decrease Throttle.
Step 1: Initialization
Crisp Input
If the change in error is decreasing = Negative
If the change in error is not change = Zero
If the change in error is increasing = Positive
Crisp output
Increase throttle
(No change)
Decrease throttle.
Step 2: Fuzzification
Assigning a member function for crisp values. Membership function can be Sigmoid function (sigmf), Triangular function (trimf) and many more. Three main membership functions are Increase throttle, (No change) and Decrease throttle.
Step 3:
IF-THEN rules:
If error is Negative (Ar < Ao) and error-dot is Negative THEN Increase throttle.
If error is Zero (Ar = Ao) and error-dot is Zero THEN No Change.
If error is Negative (Ar < Ao) and error-dot is Zero THEN Increase throttle.
In matrix format
The graphs for the membership function sets (error, error-dot and output) looks like:
For the output
For altitude error:
Green color is assigned where answer > 0.
Step 4:
Inference Mechanism
Fuzzy inferences mechanisms are
1. Mamdani fuzzy inference
2. Sugeno fuzzy inference
3. Tsukamoto fuzzy inference
Step 5:
Defuzzification
Using Root-sum-squared calculate the strength of each output membership function, Decrease Throttle, No Change and Increase Throttle.
For more details look over following link:
Related Question