fuzzy using matlab

38
FUZZY SYSTEMS: %DVLFVXVLQJ0$7/$%)X]]\ 7RROER[ %\ +HLNNL1.RLYR #

Upload: amryassin

Post on 21-Jul-2016

27 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fuzzy Using Matlab

FUZZY SYSTEMS:

��������������������

���� ��

��

� �������������

����

Page 2: Fuzzy Using Matlab

2. �� Fuzzy sets

���������� ������

��� ������������� ���� ����� � � ��������

�� ��� ��������� ������������� ��!

" �# ��$�%��������µ������ �����������������

[ ]1,0: →UFµ

������

{ }UxxxF F ∈= )(,µ&$ ����� �����$ �� �# ��$�%��������µ��'�(�� ����# ���$ � � ����� �# ��$�%���������$ ��� ��� �����)����� ������ �# �* ��������

Fig.2. 1.�" �# ��$�%������������������ ����� � ��$�% ����� �# ���$�% ����������������% ����������� ���

u

µ(u)1

bellshaped triangular trapezoidal singleton

Page 3: Fuzzy Using Matlab

+

�� ����������������� ������� ��!����

,-.�/0"� ����� / �� �$ � ����� � �% ����� � �� # � �� �� ������#� �� 1$����� �� � ��� *��$� �$� � ���� � �� '�� �(� �% ����� �!���� !"#��!�����

2./�&).�!�� ������� �� ��$ �� �% ����� ��� �� ���[00,400].

2. When MATLAB is open, then open GUI (GUI =Graphical User Interface)

by typing fuzzy

The result is shown below:

Fig.2.2. GUI of Fuzzy toolbox. Study the content ofGUI to have an overall understanding beforeproceeding.

���)%���� �# ��$�%������������ ���� � � ����� �+��.��%���� �# ��$�%�������

Page 4: Fuzzy Using Matlab

3

Next activate input membership block by moving mouseon top of it and by clicking once. Activation is shown bya red boundary on the block. If you click twice, theMEMBERSHIP FUNCTION EDITOR opens up. Thisis needed when defining membership functions.

Another way to do the same is to use View menu (cf.Figure below). Input block is again activated first.

Fig.2.3. Editing membership functions from�Viewmenu.

Page 5: Fuzzy Using Matlab

4

Fig.2.4. Display to edit input membership functions.

First change Range to the one given in the problem or to[00,400]. This is done by moving the cursor to the Rangearea and clicking once. Then you can correct the figuresin the range domain as you would correct text in a textdocument. Note that you have to leave space between thenumbers.

Next click Close or anywhere in the light grey area abovewith the mouse. The result is shown below.

Page 6: Fuzzy Using Matlab

5

Fig.2.5. Change the range of input variable to [00,400].

Now you are ready to define new membership functions.Choose Add MF’s from EDIT menu. The followingdisplay is shown.

Fig.2.6. Type and number of membership functions canbe chosen.

Page 7: Fuzzy Using Matlab

6

Default value is three triangular (trimf) (3) membershipfunctions as seen on the display. These will divide therange into three equal parts.

Click OK, if you are happy with the default values,otherwise make your own choice. (Try e.g. five gaussianmembership functions. Different membership functionscan be found under MF type.)

The result is shown below. Note that the default namesfor the membership functions are mf1, mf2 and mf3.

Fig.2.7. The result of choosing three, triangularmembership functions, which by default are named mf1,mf2 and mf3.

Page 8: Fuzzy Using Matlab

7

2. 3. Fuzzy set operations

Let A and B be two fuzzy sets in universal discourse U.Their corresponding membership functions are

µA and µB.

The basic set operations union, intersection andcomplement are defined by the membership functions asfollows:

Union

{ } Uuuuu BABA ∈∀=∪ ,)(),(max)( µµµ

������7��&$ �� �# ��$�%����������� ���BA ∪ ����� �� ��#��������$ ��"!� ����

� �# ��$�%�������������������

)(uBA∪µ

� )(uBµ

)(uµ

Page 9: Fuzzy Using Matlab

8

Intersection

{ } Uuuuu BABA ∈∀=∩ ,)(),(min)( µµµ

�����8��The membership function of intersection of fuzzysets BA∩ is defined by taking the minimum ofmembership functions of A or B.

Complement

The membership function of the complement of a fuzzyset A, A is defined as follows

Uuuu AA ∈∀−= ),(1)( µµ

Fig.2.10. Membership functions of a fuzzy set A and itscomplement A .

u

µ( u)

1bel lsha ped t ri angul ar t rapezoi dal sing let on

BA∩µ)(uAµ )(uBµ

)(uAµ )(uAµ

u

µ( u)

1bel lsha ped t ri angul ar t rapezoi dal sing let on

Page 10: Fuzzy Using Matlab

��

2.3. Fuzzy logical operations

The membership function of the logical operation or of

two fuzzy sets A and B is

{ } VvUuvuvu BABA ∈∧∈=∨ ,)(),(max),( µµµ

The membership function of the logical operation and of

two fuzzy sets A and B is

{ } VvUuvuvu BABA ∈∧∈=∧ ,)(),(min),( µµµ

The membership function of the logical operation not of

a fuzzy set A is

Uuuu AA ∈−= ),(1)( µµ

Page 11: Fuzzy Using Matlab

��

#$��%�#

&��#���#

-�� �$!�)�������$���������$��$ �����%$�-�� �&!�)�������&���������&��$ �����%&�

� � ������$���$����%$���&���&����%&�� ��� ��� ���

��������"���!

���� "�'��� ��������'������������ ������ ������� ��������'����������� �"!(� ����� ��������'����������� �"!

�)&#��#�#&���*����� 0 0( ( ), ( ))

i ii A BT x yα µ µ=�� ’ ( ) ( , ( ))

iii CC

z T zµ α µ=��������������� ��

(�1 2

*( ) ( ( ), ( ),..., ( ))NC C C Cz T z z zµ µ µ µ=

Page 12: Fuzzy Using Matlab

��

��++*����#&#�,#�-��./)&0

0

1µC

(z)1

0

1µC (z)

2

z

z0

1µA

(x)1

x

0

1µA (x)

2

xx0

0

1µB

(y)1

0

1µB (y)

2

y

y

y0 min

0

1µC (z)

C’2z( )

µC’1

z( )

0������ ���������� �����

1 11 0 0min( ( ), ( ))A Bx yα µ µ=���� ’ 11

1( ) min( , ( ))CCz zµ α µ=

0������ �� ������� ����

2 22 0 0min( ( ), ( ))A Bx yα µ µ=���� ’ 22

2( ) min( , ( ))CCz zµ α µ=

1��#� �#��$���� ��'9� �� (’ ’1 2

( ) max( ( ), ( ))C C Cz z zµ µ µ=

: �� ���1��%�� �� � �����������

Page 13: Fuzzy Using Matlab

�+

)��%����#��#&�1�%����,��)�������#�)��

0

1µC (z)

1

0

1µC

(z)2

z

z0

1µA (x)

1

x

0

1µA

(x)2

xx0

0

1µB (y)

1

0

1µB

(y)2

y

y

y0 min

0

1µC (z)

z

µC’2

z( )

µC’1

z( )

Page 14: Fuzzy Using Matlab

�3

��++*����#&#�,#�-%&).�,�0

Page 15: Fuzzy Using Matlab

�4

��(�����/����

��"�2 "������

"�%%��� [ ] [ ] [ ]1,01,01,0: →×T

T-norm satisfies the following criteria:

),(),( abTbaT = � ���� �"�3��

)),(,()),,(( cbTaTcbaTT = "����"�3��

),(),( dcTbaTdbca ≤=≤∧≤ ���'����"��2

aaTaT == ),1()1,( 4� 0)0,0( =T �� �'"��

Example: Intersection of sets.

REMARK: In fuzzy control T-norm is used to connectdifferent propositions in connection of and-operation. Thearguments are then the corresponding membershipfunctions.

The most common T-norms are

���"������������ ),min( ba

���,���������������� #

Page 16: Fuzzy Using Matlab

�5

��(�����/������

��"�2 "��������

Mapping� [ ] [ ] [ ]1,01,01,0:* →×T

In addition to T-norm criteria it must satisfy the

following!

1)1,1(* , ),0(*)0,(* === TaaTaT

Example 2.2:

T-conorm is generally used to connect propositions in

connection of or-operation.

The most common T-conorms:

����"�;�������� ),max( ba

����)�%��#�#�������$ �����#' (#

+����������������� �# ��$�%�������������'#' �������� �

����'���$��$������ ��������������$ ��#�� ���������(

Page 17: Fuzzy Using Matlab

�6

2.4. Fuzzy reasoning

1. Generalized Modus Ponens (GMP)

(forward chaining)

2. Generalized Modus Tollens (GMT)

(backward chaining)

Example 2.3: Consider two fuzzy sets A and B, and their

���%� � ��� A ����B ��&$

-��%0

������!��� ����� A

Premise 2: If x is A then y is B

1�������!�����������B

-���0

������!� ����B

,� ��� ��!� If x is A then y is B

1�������! ����� A

Page 18: Fuzzy Using Matlab

�7

#!"� ����5!�%#�� ��)��*

Fig.2.11. 1����9����������$�$*���

<��� �� � ������ ����9��� ��$�$*����<���*��� ��� � %� �

��� ������� �������������������������: ������� �=����

���� ���*$��$�������� ���$ �� >��� � ���

,��� ����������*�!

���: � ��� ��$ �� >��� ���� �������#� ������$ ����� ��

#��������$ ���� �#�� �

����� ��� ��� ���������$ ����$ ��% ��#����������$

������ #�� �

:�����

29�0:)2&9�10

Page 19: Fuzzy Using Matlab

�8

�)����)�!

���� ����3"�"� ����2�����*��$������%� ���� �

)�,�&!�:����� �

.�&,�&!��� ����%�* ��

&$� �'+(�� �# ��$�%����������� ��$�� �����#��$��%��������%���

" �# ��$�%�������������)�,�&!

:����� � �'� � ��(!�������������� ����

" �# ��$�%�������������.�&,�&!

�� ����%�* �� �'?(!� ��������������

@ �*������ ��$ ��� ������#�;����� �� ��$ ��� ������ ��#������� ���������� �������$ ������#� �������� ��

)�"9&/9����%

�������

&$����% ���$ �A�)��9������ ��$ ��%���*���*�

Page 20: Fuzzy Using Matlab

��

A�� ����� �����$ ��� ���%��������#� ��1������� ���#�����1����%�����

Fig.2.12. Naming the input variable in GUI.

Next click the input block twice with mouse to open themembership function window. First define the range, sayfrom 0 to 30 m/s.

Page 21: Fuzzy Using Matlab

��

Fig. 2.13. Set the range in GUI.

Next choose from Edit Add MFs. Pick the default values:3 triangular membership functions. Give a name to each:Call them high, medium, and short. When you arefinished, click Close.

Page 22: Fuzzy Using Matlab

��

�������3��&$� ����������� �# ��$�%���������$�� �# �$�� � ���� �$ � �%��� �����#� � ���#����� &$ ������ � � � $��# �������� ������ �� ������� ����

Repeat the same procedure with the output b, breakingpower.

Define the name of the output, break, and its range. Usethree membership functions: hard, medium and no. Thefollowing GUI display is obtained.

Page 23: Fuzzy Using Matlab

�+

Fig. 2.15. Three triangular membership functions arechosen for the output variable breaking. The last one hasbeen activated and renamed as hard.

What is missing from the fuzzy system now is the rulebase. Open View menu and click Edit rules. Then thefollowing display opens.

Page 24: Fuzzy Using Matlab

�3

�������5��-�� �0���������%�����.��$ ���$��� �$ � �%������ �.��$ �� �����$ ����%������ �

The left-hand side contains the membership functions ofthe input, distance. The right-hand side has themembership functions of the output, brake. If the inputside has several variables, which are connected either byand or or, the Connection block is in the lower left-handcorner. In this case we only have one input variable, sothe connective is not used. The weight factor (defaultvalue = 1), indicates the importance of the rule inquestion.

The construction of the rule base is the hardest part of thedesign task. Here a simple-minded rule base is construc-ted based on driving experience. Typical rule is

Page 25: Fuzzy Using Matlab

�4

If distance is low, then brake is hard.

With mouse choose the membership function low for thedistance and hard for brake. This is done in the figureabove. Then click Add rule. The result is seen below.

�������6��2 �����%������ �*��$�-�� �0������

Let us set two other rules, one for medium distance andthe other for long distance. Our simple, rule base is nowcomplete. Click Close.

Page 26: Fuzzy Using Matlab

�5

�������7��1��%� � ���� �#�� �����$� ���� ������ ��$ * �$���%���� � ��'�(�����$ � ����� ��$���� ���� ���������� �$�� ��$ ���� �* �$���

Now the design of the fuzzy system is complete. TheToolbox provides two more interesting ways expressingthe rule base.

Page 27: Fuzzy Using Matlab

�6

�������8��&$ ���� �#�� ����# � ;%� �� �����*����$ ��*�����A�)��� � �� �#�� ������������$�*�

Check under Options and there choose Format. Underthat you can see that the rules as shown are given verbose.The other forms are symbolic and indexed. Check in whatform the rule base is given in each case.

Viewing rules gives you the overall picture of thedeveloped fuzzy system. From the main FIS editor,choose from View menu View rules.

Page 28: Fuzzy Using Matlab

�7

���� ������ ��� �$����� View� �$ � ��� � #�� � ��� # � �� * ����� � ����

The display View rules is shown below.

Page 29: Fuzzy Using Matlab

�8

���� ������ &$ � ��� � #�� � ��� # � ���%��� �� ��%$�������� &$ � �� �� ��� �$ � � ��� ������ �� �$ ����� ���� �$ � �%���� �4���2����������$ �#������$ ���$��$������ �������� ���$ ����%������ ��4�?�

On the left-hand side you can see the input, distance sideand on the left the output, brake side. There are three rulesand the corresponding triangular membership functionsdisplayed. In the right-hand side lower corner is the resultof fuzzy reasoning. At this point it is a fuzzy set.Applying defuzzification method, in the figure center ofgravity has been chosen, a crisp value is obtained.

Page 30: Fuzzy Using Matlab

+�

����������- ���������� ��� ��������#��� �B�4�?�

Different input values can be tried by moving the red,vertical line on the left-hand side (Fig. 2.23).

Page 31: Fuzzy Using Matlab

+�

���� ���+�� 1$��� �$ � �%��� ���� � � ������ �� ���� � ����%������� ��

Finally, the input-output mapping can be observed byviewing surface. Choose View menu and under it Viewsurface. It is clear that our map is nonlinear. This is wherethe power of fuzzy systems is strong (Fig. 2.24).

Page 32: Fuzzy Using Matlab

+�

�������3��&$ ��� ������ ���� * ������%��=���%����%%��

Page 33: Fuzzy Using Matlab

++

#$��%�#���67�,"��.�3�2�/������ ��

8�"��������2���#!"� ����59

�%##.:

-�� "�3�����'����;����3��� �����"�'��0�

�)����)�7

2 ���%��� *���� �#�� �*��$��*���%���������� �����% ��� ����%����#�����%�* ��

� � ������$ ������� %���� ��$�*�

:�����

Page 34: Fuzzy Using Matlab

+3

���� ���4�� �� �� ���� �� *��$� �*�� �%����� ������ � ��� ������������ ����%����#� ���

The second input can be added by opening Edit menu.Otherwise the steps are as before. Remember to give aname for the added input. Call it velocity.

Only velocity membership functions are shown becausethey are new. Note that the speed range is from -40 to 40km/h and the range has been divided into threemembership functions: slow, medium, and high speed.

Page 35: Fuzzy Using Matlab

+4

�������5��" �# ��$�%��������������$ � *��%����� �������

Eight rules have been constructed, which are easy tounderstand (Fig. 2.27). Of course, the rules are notunique. Other rules could be used as well. The rule basemust be viewed and tested to see its effectiveness andhow well the system specifications are satisfied.

Page 36: Fuzzy Using Matlab

+5

�������6��9���� �#�� �����0;��%� ���4�

Viewing the rules is shown in Fig. 2.28.

Page 37: Fuzzy Using Matlab

+6

�������7��&$ ���� �#�� ������ * ����%$��������:��� � ��%�������# ��$�� ����� �*$����$ ����%���*����# �

9����������� ����$ ����� ��#���$��������� � ������ �����%�����)���$ �� ��������������������������$ �� �� ��$ ���� ���0������� ����$����$ ��� ������$���������� ����$�$�% ���� ������� ������ ��$�#������ �%�� �

Page 38: Fuzzy Using Matlab

+7

���������$ ������� ��� *�����$ ���� ������$�*�

�������8��&$ ������� ��� *�����$ ��������� ����� �#�� �

��� ��$����$ ���$��$��=��� ���� �� ��������*��$����� � ���� �������������� ��� ���<�������$� ��$���#������������ *�� �# ��$�%�������� ��� �����#� ����%�* ���<�������$�� �����$� ��$ ���� �#�� ��&$�������� �# ��*�