Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
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 comentarios
ASUTOSH
ASUTOSH el 1 de Feb. de 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)')

Respuestas (1)

Wayne King
Wayne King el 1 de Feb. de 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 comentarios
Walter Roberson
Walter Roberson el 1 de Feb. de 2014
Use a function and pass inputs into the function.
You can also put "clear A" into the code.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by