フィルターのクリア

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 日間)
ASUTOSH
ASUTOSH 2014 年 2 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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