📄 fuzdemo1.m
字号:
function fuzdemo1
%# call gamma_a gamma_b
echo on
clc
% fuzdemo1.
%
% FSTB - Fuzzy Systems Toolbox for MATLAB
% Copyright (c) 1993-1996 by Olaf Wolkenhauer
% Control Systems Centre at UMIST
% Manchester M60 1QD, UK
% See the READ.ME file for more information.
pause % Strike any key to continue.
clc
% This version requires MATLAB 4.0 and for control SIMULINK.
% The files are with detailed comments. See help for more information !
pause % Strike any key to continue.
clc
% From Siler & Ying 1988 - Fuzzy Control Theory: 'The Linear Case' :
% The correct choice of fuzzy logics depends on any prior associations
% between the logic operands; that strongly positive associations imply
% the applicability of the Zadeh logic; zero associations, or independence,
% imply the applicability of probability logic; and negative associations
% imply the applicability of Lukasiewicz logic.
% From Siler & Ying 1989 - Fuzzy Control Theory: 'A Nonlinear Case' :
% In evaluating the control rules, it is proper to use the Zadeh AND to
% evaluate the individual control rules, and the Lukasiewicz OR to evaluate
% the implied OR between control rules. The Lukasiewicz OR should be used
% since the conditions being ORd are maximally negatively correlated.
% Probability Logic: a AND b = a*b (Algebraic Product)
% a OR b = a+b-a*b (Algebraic Sum)
% Lukasiewicz Logic: a AND b = max(0,1-(a+b))
% Zadeh Logic: a AND b = min(a,b)
% a OR b = max(a,b)
pause % Strike any key to continue.
clc
% A fuzzy set in this toolbox can have different forms:
% - For general operations with fuzzy sets a discrete form.
% - For control simulation a compact form of a general trapezoid or a
% discete form is used.
% (A second more compact yet more restricted form is possible)
% - Fuzzy numbers are described by some parameters.
% The structure of the operator files is fairly simple and can be changed
% easily.
% A fuzzy set in the LR-form (see Zimmermann[1992]) is discrete and
% is generated by:
% [y,x]=modlrset(L,R,[xmin,xmax,m1,m2,alpha,beta,ymin,ymax],resx)
% resx should be an arbitrary value between 100 and 300 to get smooth plots.
% m1 and m2 are the left and right "edges" of of membershipfunction.
% alpha and beta are values for the stretching to both sides of m1,m2.
% plot_set(x,y) plots the set:
xmin = 0; xmax = 50; xmima=[xmin,xmax]; resx=200;
% [A,x] = modlrset('tr','',[xmima,32.5,32.5,7.5,7.5,0,1],resx)
% plot_set(x,A)
% plot_set(x,modlrsetr('tr','',[xmima,30,35,5,5,0,1],resx))
pause % Press any key after plot...
clf; echo off
[A,x] = modlrset('tr','',[xmima,32.5,32.5,7.5,7.5,0,1],resx);plot_set(x,A),
hold on, plot_set(x,modlrset('tr','',[xmima,30,35,5,5,0,1],resx)),
title('Two possible LR forms for fuzzy sets'),pause
hold off; echo on
clc
% Beside trapezoid and triangular forms others are possible:
% modlrset('1./(1+x.^2)','1./(1+x.^2)',[xmima,30,35,5,2,0,1],resx)
pause % Press any key after plot...
[A,x]=modlrset('1./(1+x.^2)','1./(1+x.^2)',[xmima,30,35,5,2,0,1],resx);
plot_set(x,A), title('L=1./(1+.^2) R=1./(1+x.^2)'),pause
clc
% For control a general trapezoid is suitable. A trapezoid is described
% by four characteristic points from left to right:
% A = [P1;P2;P3;P4] (note: column vector)
% This can be one membershipfunction of a fuzzy set. An example for a whole
% set is: (4 msf from left to right in each column)
% A = [-inf, 0, 40, 60 ;
% 0 , 20, 60, 100;
% 0 , 40, 60, 100;
% 40 , 60, 80, inf];
% To display the set plot_set(A) is used.
pause % Press any key after plot...
clf; echo off
A = [-inf, 0, 40, 60 ;
0 , 20, 60, 100;
0 , 40, 60, 100;
40 , 60, 80, inf];
plot_set(A), title('example compact trapezoid form :'), pause;
clc; echo on;
% Set operations are easy to implement with MATLAB. They can be visualised
% in different ways.
% Below we first define two sets, and
xmin = 0; xmax = 100; xmima = [xmin,xmax];
[A,x] = modlrset('tr','',[xmima,20,40,20,20,0,1],resx);
B = modlrset('tr','',[xmima,60,80,20,20,0,1],resx);
% The following operations are displayed:
% fuz_or('max',A,B) 'union/disjunction - maximum operator'
% fuz_and('min',A,B) 'intersection/conjunction - minimum operator'
% fuz_not(and('min',A,B)) 'complement not(and(min,A,B))'
pause % Press any key after plot...
clc
clf; echo off
subplot(2,2,1); plot_set(x,A), hold on, plot_set(x,B), hold off;
title('The sets A and B');
subplot(2,2,2); plot_set(x,fuz_or('max',A,B));
title('union');
subplot(2,2,3); plot_set(x,fuz_and('min',A,B));
title('intersection');
subplot(2,2,4); plot_set(x,fuz_not(fuz_and('min',A,B)));
title('not(and(min,A,B))'),pause
clf;
subplot(2,2,1); plot_set(x,fuz_or('min',A,B));
title('bounded-sum s1');
subplot(2,2,2); plot_set(x,fuz_or('sum',A,B));
title('algebraic-sum s2');
subplot(2,2,3); plot_set(x,fuz_and('max',A,B));
title('bounded-difference t1');
subplot(2,2,4); plot_set(x,fuz_and('pro',A,B));
title('algebraic-product t2'),pause
clc; echo on
% Another way to show the effect of an operator is as follows:
% First a gamma operator with changing gamma. Then two operators
% and two different graphics showing their effect.
% The plots are made with show_op('operator',parameter). Use help
% for more details.
pause % Press any key after plot...
clc
% Working, please wait...
echo off
clf;
subplot(2,2,1); show_op('gamma_b',0); title('gamma=0 = max.operator');
subplot(2,2,2); show_op('gamma_b',0.3); title('gamma=0.3');
subplot(2,2,3); show_op('gamma_b',0.6); title('gamma=0.6');
subplot(2,2,4); show_op('gamma_b',1); title('gamma=1 = min.operator'),pause
clf;
show_op('gamma_a',0,'gamma_a',1); pause
clc; echo on
% Modification of a (discrete) set with modi_set() :
%
[C,x] = modlrset('tr','',[xmima,40,60,40,40,0,0.6],resx);
% modi_set(C,'norm') 'normalisation'
% modi_set(C,'con') 'concentration'
% modi_set(C,'dil') 'dilation'
% modi_set(C,'int') 'contrast-intensification'
pause % Press any key after plot...
clf; echo off
subplot(2,2,1); plot_set(x,C); hold on; plot_set(x,modi_set(C,'norm')); hold off;
title('normalised');
subplot(2,2,2); plot_set(x,C); hold on; plot_set(x,modi_set(C,'con')); hold off;
title('concentrated');
subplot(2,2,3); plot_set(x,C); hold on; plot_set(x,modi_set(C,'dil')); hold off;
title('dilation');
subplot(2,2,4); plot_set(x,C); hold on; plot_set(x,modi_set(C,'int')); hold off,pause
clc; echo on
% With the associative operators it is possible to combine them recursive
% for more than two sets.
% (All T- and Co-T- norms are associative)
%
% It is shown, that a combination of three LR sets gives nor LR set as a
% result.
% In the following example the gamma-operator fuz_for() is used.
% For gamma=1 the operator is equal to the maximum operator.
% For gamma=0 the average value is calculated.
xmin = 0; xmax = 50; xmima = [xmin,xmax];
[hot,x] = modlrset('tr','',[xmima,30,35,5,5,0.1,0.8],resx);
warm = modlrset('tr','',[xmima,15,25,5,5,0.2,0.4],resx);
cold = modlrset('tr','',[xmima,5,15,2,5,0.05,0.7],resx);
% fuz_for(1,fuz_for(1,hot,warm),cold)
% fuz_for(0.5,fuz_for(0.5,hot,warm)
% fuz_for(0,fuz_for(0,hot,warm),cold)
pause % Press any key after plot...
echo off
clf;
subplot(2,2,1), plot_set(x,hot), hold on,
subplot(2,2,1), plot_set(x,warm),
subplot(2,2,1), plot_set(x,cold),
hold off, title('the sets hot warm cold');
subplot(2,2,2), plot_set(x,fuz_for(1,fuz_for(1,hot,warm),cold)),
hold off, title('hot or warm or cold.g=1');
subplot(2,2,3), plot_set(x,fuz_for(0.5,fuz_for(0.5,hot,warm),cold)),
hold off, title('hot or warm or cold.g=0.5');
subplot(2,2,4), plot_set(x,fuz_for(0,fuz_for(0,hot,warm),cold)),
hold off, title('hot or warm or cold.g=0'),pause
clc; echo on
% Besides fuzzy sets through the extension principle from Zadeh an
% arithmetic with fuzzy numbers or intervals is possible.
% Fuzzy numbers/intervals are discribed in in LR-form with ymin=0, ymax=1
% The parameters are identical with the parameter in modlrset() for generating
% a fuzzy LR-set:
% f = [xmin xmax m n alpha beta]
% The abscissa range for both numbers must be the same.
% The function plot_num() plots three fuzzy numbers.
xmin = -50; xmax = 50; xmima = [xmin,xmax];
x1 = [xmima,17,19,1,3];
x2 = [xmima,10.5,12.5,0.5,1.9];
add = fuz_add(x1,x2);
sub = fuz_sub(x1,x2);
sire = fuz_sire(x2);
pause % Press any key after plot...
clc
% Working, please wait...
echo off
clf
subplot(2,2,1); plot_num(x1,x2,[0 0 0 0 0 0]); title('x1, x2');
subplot(2,2,2); plot_num(x1,x2,add); title('x1 + x2');
subplot(2,2,3); plot_num(x1,x2,sub); title('x1 - x2');
subplot(2,2,4); plot_num(x2,sire,[0 0 0 0 0 0]); title('sign reversal x2'),pause
x1 = [xmima,10,12,2,3];
x2 = [xmima,2,2.5,0.5,0.8];
mul = fuz_mul(x1,x2);
mx1 = fuz_sire(x1); % sign reversal of the number.
mx2 = fuz_sire(x2);
clf
subplot(2,2,1); plot_num(x1,x2,mul); title('x1 * x2');
subplot(2,2,2); plot_num(x1,x2,fuz_mul(x1,mx2)); title('x1 * -x2');
subplot(2,2,3); plot_num(mx1,mx2,fuz_mul(mx1,mx2)); title('-x1 * -x2');
subplot(2,2,4); plot_num(mx1,x2,fuz_mul(mx1,x2)); title('-x1 * x2'),pause
x1 = [xmima,40,45,0.5,0.8];
x2 = [xmima,9,10,2,3];
mx1 = fuz_sire(x1);
mx2 = fuz_sire(x2);
clf
subplot(2,2,1); plot_num(x1,x2,fuz_div(x1,x2)); title('x1 / x2');
subplot(2,2,2); plot_num(x1,mx2,fuz_div(x1,mx2)); title('x1 / -x2');
subplot(2,2,3); plot_num(mx1,mx2,fuz_div(mx1,mx2)); title('-x1 / -x2');
subplot(2,2,4); plot_num(mx1,x2,fuz_div(mx1,x2)); title('-x1 / x2'),pause
xmin = 0; xmax = 100; xmima = [xmin,xmax];
x1 = [xmima,50,60,5,10];
clf
subplot(2,1,1); plot_num(x1, [0 0 0 0 0 0 ], fuz_log(x1));
title('x1, log(x1)');
subplot(2,1,2); plot_num(x1, [0 0 0 0 0 0], fuz_exp(x1));
title('x1, exp(log(x1))'), pause;
clc; echo on
pause % Press any key after plot...
clc
% Any constructive feedback would be most welcome.
% Please feel free to criticize and comment upon this toolbox.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -