Problems with matrix dimensions not agreeing
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am having issues with my matrix dimensions and getting this error in my code:
Error using /
Matrix dimensions must agree.
I used dot arithmatic but that does not seem to be the issue. It seems very simple to fix but I cannot figure out what the problem is. The issue is specifically for the variables "lnY1" and "lnY2". My code is below:
x1 = [0.0374 0.0972 0.3141 0.5199 0.7087 0.9193 0.9591];
%Data from Experimental Results
lny1 = [2.0937 1.6153 0.7090 0.3136 0.1079 0.0002 -0.0077];
lny2 = [0.0220 0.0519 0.2599 0.5392 0.8645 1.3177 1.3999];
%Data from Calculations
x2 = 1-x1;
L12 = 0.124; L21 = 0.523;
lnY1 = -log(x1+(L12*x2))+x2*((L12/(x1+(L12*x2)))-(L21/(x2+(L21*x1))));
lnY2 = -log(x2+(L21*x1))-x1*((L12/(x1+(L12*x2)))-(L21/(x2+(L21*x1))));
plot(x1,lny1,x1,lny2,x1,lnY1,x1,lnY2),grid on
title('Activity Coefficients for Ethanol/Benzene')
xlabel('x_1'),ylabel('y')
0 comentarios
Respuestas (1)
Guillaume
el 4 de Feb. de 2015
The best way for you to work out the problem would be to try each subexpression on its own and move toward more complex ones if it works.
Anyway, element-wise multiplication is .*, division of scalar by a matrix or element-wise division is ./:
lnY1 = -log(x1+(L12*x2))+x2.*((L12./(x1+(L12*x2)))-(L21./(x2+(L21*x1))));
lnY2 = -log(x2+(L21*x1))-x1.*((L12./(x1+(L12*x2)))-(L21./(x2+(L21*x1))));
If in doubt, and you do mean to operate element-wise, replace each operator +, -, *, /, ^ by its dotted equivalent.
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!