How to troubleshoot mtimes/times error in matrix multiplication
7 views (last 30 days)
Show older comments
i have developed a function for least squares estimation of the consequent parameters of first order TS fuzzy models. apparently the matrix size are ok and rules of matrix multiplication are being followed but as i run the following code (using a simulimk model), it gives error message of times/mtimes error. the problem remains whether i choose matrix normal multiplication or element by element multiplication. the error is being appeared for second last statement of the code because if im commenting it, the model runs fine but since that particular statement is updating my constants so i can not avoid it. kindly look at the following code and suggest me what i can do to troubleshoot the problem.
{
function [ output_args ] = RLS_Function( input_args )
%RLS_FUNCTION Summary of this function goes here
% Detailed explanation goes here
x1=input_args(1);
x2=input_args(1);
number_of_rules=5;
%---------------------------------------------
%--------Initializing weights-----------------
%---------------------------------------------
persistent w;
if isempty(w)
w=ones(3,number_of_rules*number_of_rules)*0.1;
end
%---------------------------------------------
%-----------Initializing P---------------------
%---------------------------------------------
Pt=eye(25); % P(t)
%---------------------------------------------
%-----------Identification Process------------
%---------------------------------------------
no_x1_mf=5;
no_x2_mf=5;
%---------------------------------------------
%-----------Fuzzification --------------------
%---------------------------------------------
PossIx1=Fuzzification_x(x1);
PossIx2=Fuzzification_x(x2);
%---------------------------------------------
%--------Calculating Strength of the rule-----
%---------------------------------------------
count=1;
for i=1:no_x1_mf
for j=1:no_x2_mf
a(count)=PossIx1(i)*PossIx2(j); % dim(a) = 1 x 25
% a(count)=PossIx1(i); % dim(a) = 1 x 25
count=count+1;
end
end
%count=total number of rules
%---------------------------------------------
%-----------Calculating K---------------------
%---------------------------------------------
num=Pt*a';
den=1+a*Pt*a';
K=num/den;
%---------------------------------------------
%-----------Calculating P---------------------
%---------------------------------------------
Pt=Pt-K*a*Pt;
%---------------------------------------------
%------Calculating epsilon--------------------
%---------------------------------------------
epsilon=x2-a*w'*[x2 x1 1]'; %since y=x2
%
%---------------------------------------------
%------------Weight update--------------------
%---------------------------------------------
w=w'*[x2 x1 1]'+K*epsilon;
output_args=a*w';
%
end
}
if you find any flaw in the development of code, kindly let me know
regards
0 Comments
Answers (1)
bym
on 30 Oct 2011
this line,
w=w'*[x2 x1 1]'+K*epsilon;
changes w from (3x25) to (25x1), combined with the use of
persistent w;
would cause the following line to fail on the next function call
epsilon=x2-a*w'*[x2 x1 1]'; %since y=x2
Also, don't you mean
x1=input_args(1);
x2=input_args(2); %<-- changed index to 2
0 Comments
See Also
Categories
Find more on Fuzzy Logic in Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!