?? Error using ==> times Matrix dimensions must agree.

Hi everyone. When I am executing the below given program, I got the error message " ??? Error using ==>times Matrix dimensions must agree." Please check the problem and help me to resolve the issue,
datos=[C14; C13; Ptotal; NH4_total; Mgtotal; T; Kest];
Aeq = [0 1 0 0 0 0 0 1 1 1 1 0 0 datos(3);
1 1 0 0 1 1 1 0 1 0 1 0 0 datos(3);
0 0 1 1 0 0 0 0 0 0 0 0 0 datos(3) ;
0 0 0 -1 3 2 1 -2 -1 -1 1 -1 1 0];
beq = [datos(5); datos(3); datos(4); datos(1)-datos(2)];
z=[0 0 0 1 -3 -2 -1 2 1 1 -1 1 -1];
sqrtI=@(x) sqrt(0.5*(x(:,1).*z(:,1).^2+x(:,2).*z(:,2).^2+x(:,3).*z(:,3).^2+x(:,4).*z(:,4).^2+x(:,5).*z(:,5).^2+x(:,6).*z(:,6).^2+x(:,7).*z(:,7).^2+...
x(:,8).*z(:,8).^2+x(:,9).*z(:,9).^2+x(:,10).*z(:,10).^2+x(:,11).*z(:,11).^2+...
x(:,12).*z(:,12).^2+x(:,13).*z(:,13).^2)); %escalar I
F=@(x,sqrtI) (sqrtI(x)./(1+sqrtI(x)))-0.3*sqrtI(x); %escalar F
a=-A_DH.*z.^2;
exponente=@(x,sqrtI,F) times(a,F(x,sqrtI));
lambda=@(x,sqrtI,F) 10.^(exponente(x,sqrtI,F));
uLi=[-1142.65 -1577.3 -26.5 -79.31 -1018.80 -1089.26 -1130.40 -454.8 -1593.84 -626.7 -1511.21 0 -157.29];
uS=-3051.1;
uL=@(x,sqrtI,F,lambda) uLi+R*T*( log(x(:,1:13).*lambda(x,sqrtI,F)) );
G=@(x,sqrtI,F,lambda) [times(x(:,1:13),uL(x,sqrtI,F,lambda)) uS.*x(:,14).*datos(3)] ;
options = gaoptimset('Generations',1000,'StallGenLimit',200,'MutationFcn',@mutationadaptfeasible,...
'PlotFcns',{@gaplotbestf,@gaplotstopping},'Vectorized','on','UseParallel','always');
tic;[x G] = ga(@(x)G(x,sqrtI,F,lambda),14,[],[],Aeq,beq,[],[],[],options);toc
Please Help me. Thank you.,

 採用された回答

James Tursa
James Tursa 2015 年 8 月 5 日
編集済み: James Tursa 2015 年 8 月 5 日

0 投票

Type the following at the command line:
dbstop if error
Then run your code. It will pause at the line with the error. Examine all of the variables that you are using the .* operator with and see where the mismatch is. Then figure out why this is happening and fix it.

6 件のコメント

CLMSP
CLMSP 2015 年 8 月 5 日
thanks, but I don´t see the mistake I think it is a problem of the length of vectorized fitness function. But I can´t see it.
James Tursa
James Tursa 2015 年 8 月 6 日
編集済み: James Tursa 2015 年 8 月 6 日
You don't have to "see" it. All you have to do is look at the line that is generating the error, and then look for everywhere in that line there is a .* operator. One by one, examine the left and right operands for this operator and discover which ones don't match in size.
CLMSP
CLMSP 2015 年 8 月 7 日
I don´t "see" because I did not "find" the mistake
Walter Roberson
Walter Roberson 2015 年 8 月 7 日
編集済み: Walter Roberson 2015 年 8 月 7 日
Provide us with some representative data. It can be random, but every variable you list in your code must be initialized to exactly the same size as the variables at the time you encounter the problems. I do not assume that C13 and so on are each scalars: my assumption is that some of them are vectors. Check every variable before reporting its size to us.
CLMSP
CLMSP 2015 年 8 月 10 日
They are scalars: For example: datos=[1e-3; 8e-3; 4e-3; 4e-3; 4e-3; 298.15; 5.3703e-14]
Walter Roberson
Walter Roberson 2015 年 8 月 11 日
A_DH is undefined
Which line is the error occurring on? Please provide a traceback of the error.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by