MATLAB Answers


Matrix dimensions must agree error

Asked by Bettie Schelske on 12 Sep 2019
Latest activity Commented on by Image Analyst
on 12 Sep 2019
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 Comment

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.

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 12 Sep 2019
 Accepted Answer

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.


Sign in to comment.

Answer by Image Analyst
on 12 Sep 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)));
% imshow(GammaA, [], 'Colormap', jet(256), 'InitialMagnification', 800,...
% 'XData', T, 'YData', Comp);
ylabel('Comp', 'FontSize', 20);
xlabel('T', 'FontSize', 20);
0000 Screenshot.png


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.
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;
This will plot 5 curves of 99 values.

Sign in to comment.