Matrix dimensions must agree error
1 view (last 30 days)
Show older comments
Bettie Schelske
on 12 Sep 2019
Commented: Image Analyst
on 12 Sep 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 Comment
Walter Roberson
on 12 Sep 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.
Accepted Answer
Walter Roberson
on 12 Sep 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.
0 Comments
More Answers (1)
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)));
end
end
image(GammaA);
% imshow(GammaA, [], 'Colormap', jet(256), 'InitialMagnification', 800,...
% 'XData', T, 'YData', Comp);
ylabel('Comp', 'FontSize', 20);
xlabel('T', 'FontSize', 20);
2 Comments
Image Analyst
on 12 Sep 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.
See Also
Categories
Find more on Graphics Objects 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!