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 个评论

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by