QA0010
P.Karamodin asked in researchgate.net how to implement 36 fuzzy logic rules shown in supplied table
% table is 4D, but it may be simplified with 2x18 complex numbers.
% 1.- Define table ranges
% df possible values: 1=L; 2=N; 3=H
range_df=[1:3]
% dv possible values: 1=NL; 2=NM; 3=NS; 4=PS; 5=PM; 6=PL;
range_dv=[1:6]
% dp possible values: 1=L; 2=N; 3=H
range_dp=[1:3]
% dq possible values: 1=NL; 2=NM; 3=NS; 4=PS; 5=PM; 6=PL;
range_dq=[1:6]
% 2.- Generate table
[F,V]=meshgrid(range_df,range_dv)
[P,Q]=meshgrid(range_dp,range_dq)
tR=[F(:) V(:) [1:numel(F)]']
tX=[P(:) Q(:) [1:numel(F)]']
R=tR(:,3)/10 % put here r values
X=tX(:,3)/10 % put here w values
% diving by 10 just to avoid R indices and R values same numbers
R+1j*X % all possible cases of r and w values
% 3.- generating input to measure: mf mv mp mq
t=[randi([1 3],1,1) randi([1 6],1,1) randi([1 3],1,1) randi([1 6],1,1)]
% 4.- measuring input
t1=t(1)+1j*t(2)
t2=t(3)+1j*t(4)
mf=nonzeros(range_df.*(real(t1)==range_df)) % capture df
mv=nonzeros(range_dv.*(imag(t1)==range_dv)) % capture dv
mp=nonzeros(range_dp.*(real(t2)==range_dp)) % capture dp
mq=nonzeros(range_dq.*(imag(t2)==range_dq)) % capture dq
% R measured value, r to be assigned, is
mr=R(nonzeros([1:numel(F)] .* [[mf==tR(:,1)] .* [mv==tR(:,2)]]'))
% X measured value, w to be assigned, is
mw=X(nonzeros([1:numel(F)] .* [[mp==tX(:,1)] .* [mq==tX(:,2)]]'))