Matrix dimensions must agree error

2 visualizaciones (últimos 30 días)
Bettie Schelske
Bettie Schelske el 12 de Sept. de 2019
Comentada: Image Analyst el 12 de Sept. de 2019
Hi,
To preface, I have no idea what im doing. I am trying to use the equations to get 99 different GammaA's at the 5 different temperatures. However, I understand that the matrix dimensions need to be the same i.e theres way more comp than temp.
I appericate your help.
  1 comentario
Walter Roberson
Walter Roberson el 12 de Sept. de 2019
Caution:
for i=length(Comp)
would only execute once, with i assigned the length of Comp . You would be more likely to want to use
for i=1:length(Comp)
and you would probably want to use Comp(i) inside the loop.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Sept. de 2019
Your T is a vector. You have an expression / another expression. The / operator is not ordinary division: it is matrix division, with A/B being similar to A * pinv(B) where * here indicates algebraic matrix multiplication. The numerator you have only has one column, but the denominator has length(T) columns, but the / operator requires that the number of columns be the same.
It is a lot more likely that you would want to use the ./ operator, which is element-by-element division.

Más respuestas (1)

Image Analyst
Image Analyst el 12 de Sept. de 2019
Try 2 for loops:
Comp = 0.01 : 0.01 : 0.99;
T = 400 : 200 : 1400;
R = 8.314;
ohm = 15000;
for k1 = 1 : length(Comp)
for k2 = 1 : length(T)
GammaA(k1, k2) = exp((ohm * (1 - Comp(k1)) ^2) / (R * T(k2)));
end
end
image(GammaA);
% imshow(GammaA, [], 'Colormap', jet(256), 'InitialMagnification', 800,...
% 'XData', T, 'YData', Comp);
ylabel('Comp', 'FontSize', 20);
xlabel('T', 'FontSize', 20);
0000 Screenshot.png
  2 comentarios
Bettie Schelske
Bettie Schelske el 12 de Sept. de 2019
Editada: Bettie Schelske el 12 de Sept. de 2019
Thank you so much for this! However, I am trying to plot comp vs a (composition vs activity). The GammaA equation is needed to find 99 different a vaules to plot.
Image Analyst
Image Analyst el 12 de Sept. de 2019
Each column of GammaA is 99 values. So there are 5 sets of 99 values. As I'm sure you know, you can extract a column and plot it
for col = 1 : size(GammaA, 2)
plot(Comp, GammaA(:, col), '-');
hold on;
end
This will plot 5 curves of 99 values.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by