Index exceeds number of array elements

1 次查看(过去 30 天)
I am trying to write up the code for solving the heat transfer equation for a sphere and i have receieved the following error message.
Index exceeds number of array elements
Index exceeds the number of array elements. Index must not exceed 1600.
I am new to coding and any help to fix this would be very much appreciated.

回答(2 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2022-4-17
编辑:KALYAN ACHARJYA 2022-4-17
I didnot find any coding syntax error, but code improvement is required.
r1=17.6e-2; % inner radius of sphere, m
r2=23.6e-2; % outer radius of sphere, m
k=0.034; % thermal conductivity of sphere wall, W /(m C)
bc1=40; % temperature at inner sphere wall, deg C
bc2=-81; % temperature at outer sphere wall, deg C
n=100*2*2*2*2; % number of unknown temperatures between the two radii
m=(r2-r1)/(n+1); % step size: difference between two consecutive difference pointa, m
%%%%%%%%%% GENERATION OF MATRIX A5
for i=1:n
r(i)=r1+i*m;
a(i,i)=-2*r(i)^2/m^2;
if(i==1)
a(i,i+1)=(r(i)^2/m^2 +r(i)/(m));
end
if((i>1)&&(i<n))
a(i,i-1)=(r(i)^2/m^2 -r(i)/(m));
a(i,i+1)=(r(i)^2/m^2 +r(i)/(m));
end
if(i==n)
a(i,i-1)=(r(i)^2/m^2 -r(i)/(m));
end
end
%%%% BOUNDARY CONDITION MATRIX GENERATION OF MATRIX B5
b(1,1)=-(r(1)^2/m^2 -r(i)/(m))*bc1;
b(n,1)=-(r(n)^2/m^2 +r(i)/(m))*bc2;
t=inv(a)*b;
temp(1,1)=bc1;
temp(2:n+1,1)=t(1:n);
temp(n+2,1)=bc2;
radius(1,1)=r1;
radius(2:n+1,1)=r(1:n);
radius(n+2,1)=r2;
figure,
plot(radius,temp)
xlabel('Radius, m','fontsize',20,'fontweight','b')
ylabel('Temperature, (^{o}C)','fontsize',20,'fontweight','b')

Torsten
Torsten 2022-4-17
Maybe it's interesting to compare with the analytical solution:
T(r ) = a/r + b
where
a = 121/(1/0.176 - 1/0.236)
b = 40 - a/0.176

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by