I am very new to MATLAB but I have to deliver an assignment. How do I solve matrix dimension issue in line 10 and 11.

3 views (last 30 days)
Given the following matrix dimensions
L=39360*39360
y=39360*1
q=1*39360
E= 2.8709
X=39360*39360
T=39360*39360
code
1. dq=L*y;
2. dtr=dq.*q'/E;
3. ql = q * L;
4. ldf = L * y;
5. dt = zeros(39360, 39360);
6. dtr = zeros(39360, 39360);
7. for a = 1:39360
8. for b = 1:39360
9. if X(b, :) ~= 0
10. dt(a,b) = ql(:,a)*ldf(b,:) /X(b,:);
11. dtr(a,b) = (ql(:,a)*ldf(b,:)* T))/(X(b,:)*E);
else
dt(a, b) = 0;
dtr(a, b) = 0;
end
end
end
  1 Comment
Walter Roberson
Walter Roberson on 11 Jun 2024
N = 39360;
L = rand(N, N);
y = rand(N, 1);
q = rand(1, N);
E = 2.8709;
X = rand(N, N);
T = rand(N, N);
dq=L*y;
dtr=dq.*q'/E;
ql = q * L;
ldf = L * y;
dt = zeros(39360, 39360);
dtr = zeros(39360, 39360);
for a = 1:39360
for b = 1:39360
if X(b, :) ~= 0
dt(a,b) = ql(:,a)*ldf(b,:) /X(b,:);
dtr(a,b) = (ql(:,a)*ldf(b,:)* T))/(X(b,:)*E);
1 0 1 2 1 2 1 0? 0 1 0 ?
else
dt(a, b) = 0;
dtr(a, b) = 0;
end
end
end
You have too many )

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 11 Jun 2024
Moved: Walter Roberson on 11 Jun 2024
Your ldf is 39360 x 1. Your ql is 1 x 3936. Select rows and columns out of those and you get 1 x 1 and 1 x 1. Use * to multiply two 1 x 1 and you get 1 x 1. You cannot / between 1 x 1 and a 1 x something (not unless the "something" is 1)
%N = 39360; %too large for actual test
N = 3936;
L = rand(N, N);
y = rand(N, 1);
q = rand(1, N);
E = 2.8709;
X = rand(N, N);
T = rand(N, N);
dq=L*y;
dtr=dq.*q'/E;
ql = q * L;
ldf = L * y;
whos ql ldf
Name Size Bytes Class Attributes ldf 3936x1 31488 double ql 1x3936 31488 double
dt = zeros(N, N);
dtr = zeros(N, N);
for a = 1:N
for b = 1:N
if X(b, :) ~= 0
temp1 = ql(:,a);
temp2 = ldf(b,:);
temp3 = temp1 * temp2;
temp4 = X(b,:);
whos temp1 temp2 temp3 temp4
dt(a,b) = temp3 / temp4;
temp4 = (ql(:,a)*ldf(b,:)* T);
temp5 = (X(b,:)*E);
whos temp4 temp5
dtr(a,b) = (ql(:,a)*ldf(b,:)* T)/(X(b,:)*E);
else
dt(a, b) = 0;
dtr(a, b) = 0;
end
end
end
Name Size Bytes Class Attributes temp1 1x1 8 double temp2 1x1 8 double temp3 1x1 8 double temp4 1x3936 31488 double
Error using /
Matrix dimensions must agree.

More Answers (0)

Categories

Find more on MATLAB 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!