필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

its showing inner matrix dimensions must agree...i want the program to run for all values of N...how can i do that..???

조회 수: 1 (최근 30일)
ER = 1.0;
EO = 8.8541e-12;
VO = 1.0;
AA = 0.001;
L = 1.0;
N = 20;
DELTA = L/N;
% SECOND, CALCULATE THE ELEMENTS OF THE COEFFICIENT
% MATRIX A
I=1:N;
Y=DELTA*(I-0.5);
for i=1:N
for j=1:N
if(i ~=j)
A(i, j)=DELTA/abs(Y(i)-Y(j) ) ;
else
A(i,j)=2.0*log(DELTA/AA);
end
end
end
% NOW DETERMINE THE MATRIX OF CONSTANT VECTOR B
% AND FIND Q
B = 4.0*pi*EO*ER*VO*ones(N,1);
C = inv(A);
RHO = C*(B);
SUM = 0.0;
for I=1:N
SUM = SUM + RHO(I);
end
Q=SUM*DELTA;
% FINALLY PLOT RHO AGAINST Y
plot(Y,RHO)
xlabel('y (cm)'), ylabel('rho_L (pC/m)')
  댓글 수: 2
ASUTOSH
ASUTOSH 2014년 2월 1일
this is the code i have used ...please help me with the answer i want to run it for all values of N...it is throwing error that inner matrix dimensions must agree
ER = 1.0;
EO = 8.8541e-12;
VO = 1.0;
AA = 0.001;
L = 1.0;
N = 20;
DELTA = L/N;
% SECOND, CALCULATE THE ELEMENTS OF THE COEFFICIENT
% MATRIX A
I=1:N;
Y=DELTA*(I-0.5);
for i=1:N
for j=1:N
if(i ~=j)
A(i, j)=DELTA/abs(Y(i)-Y(j) ) ;
else
A(i,j)=2.0*log(DELTA/AA);
end
end
end
% NOW DETERMINE THE MATRIX OF CONSTANT VECTOR B
% AND FIND Q
B = 4.0*pi*EO*ER*VO*ones(N,1);
C = inv(A);
RHO = C*(B);
SUM = 0.0;
for I=1:N
SUM = SUM + RHO(I);
end
Q=SUM*DELTA;
% FINALLY PLOT RHO AGAINST Y
plot(Y,RHO)
xlabel('y (cm)'), ylabel('rho_L (pC/m)')

답변 (1개)

Wayne King
Wayne King 2014년 2월 1일
It seems to work for a number of choices. Perhaps you have left over a matrix (for example A) in your workspace and then choose a smaller value of N so that A did not reduce in size?
For example, if you run the code above first with N=20 and then try N<20, like N=10
you will error because A will still be 20x20.
Try clearing all the variables in your workspace, or at least clear A using
clearvars A
and try again.
  댓글 수: 3
Walter Roberson
Walter Roberson 2014년 2월 1일
Use a function and pass inputs into the function.
You can also put "clear A" into the code.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by