필터 지우기
필터 지우기

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.

조회 수: 2 (최근 30일)
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
Walter Roberson
Walter Roberson 2024년 6월 11일
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 )

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2024년 6월 11일
이동: Walter Roberson 2024년 6월 11일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by