Matrix dimensions must agree error
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2019년 9월 12일
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.
채택된 답변
Walter Roberson
2019년 9월 12일
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
추가 답변 (1개)
Image Analyst
2019년 9월 12일
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
Image Analyst
2019년 9월 12일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!