Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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 Comments
ASUTOSH
ASUTOSH on 1 Feb 2014
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)')

Answers (1)

Wayne King
Wayne King on 1 Feb 2014
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 Comments

This question is closed.

Community Treasure Hunt

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

Start Hunting!