MATLAB Answers

0

How to solve the "Subscript indices must either be real positive integers or logicals." error.

Asked by Naiara Tabanez on 11 Sep 2019
Latest activity Answered by Shunichi Kusano on 11 Sep 2019
Hi, guys.
First of all, I am trying to solve a heat transfer problem with the finite volume method, but I don't know where am I failing in, and how to solve it.
Thank you all!
%unidimensional heat transfer
Ts=50;
i=6;
s=100;
T=zeros(i);
alfa=6.82*10^-6;
x=[1 2 3 4 5 6];
L=1;
dt=0.01;
for t=1:s
Tc=(2*Ts-T(1));
Tf=(2*Ts-T(6));
T(1)=alfa*dt((1/alfa*t*dt)*T(1)+(1/alfa*t*dt)*T(1)-(2/alfa*(L/6))*T(1)+(1/alfa*(L/6))*T(2)+(1/alfa*(L/6))*Tc);
T(2)=alfa*dt((1/alfa*t*dt)*T(2)+(1/alfa*t*dt)*T(2)-(2/alfa*(L/6))*T(2)+(1/alfa*(L/6))*T(3)+(1/alfa*(L/6))*T(1));
T(3)=alfa*dt((1/alfa*t*dt)*T(3)+(1/alfa*t*dt)*T(3)-(2/alfa*(L/6))*T(3)+(1/alfa*(L/6))*T(4)+(1/alfa*(L/6))*T(2));
T(4)=alfa*dt((1/alfa*t*dt)*T(4)+(1/alfa*t*dt)*T(4)-(2/alfa*(L/6))*T(4)+(1/alfa*(L/6))*T(5)+(1/alfa*(L/6))*T(3));
T(5)=alfa*dt((1/alfa*t*dt)*T(5)+(1/alfa*t*dt)*T(5)-(2/alfa*(L/6))*T(5)+(1/alfa*(L/6))*T(6)+(1/alfa*(L/6))*T(4));
T(6)=alfa*dt((1/alfa*t*dt)*T(6)+(1/alfa*t*dt)*T(6)-(2/alfa*(L/6))*T(6)+(1/alfa*(L/6))*Tf+(1/alfa*(L/6))*T(5));
end
plot(x,T);

  0 Comments

Sign in to comment.

1 Answer

Answer by Shunichi Kusano on 11 Sep 2019

Hi Naiara,
The error occurs, since you use "dt" as an array, though it is a scalar. The problem is the first "dt" of each sentence in the following codes.
T(1)=alfa*dt((1/alfa*t*dt)*T(1)+(1/alfa*t*dt)*T(1)-(2/alfa*(L/6))*T(1)+(1/alfa*(L/6))*T(2)+(1/alfa*(L/6))*Tc);
T(2)=alfa*dt((1/alfa*t*dt)*T(2)+(1/alfa*t*dt)*T(2)-(2/alfa*(L/6))*T(2)+(1/alfa*(L/6))*T(3)+(1/alfa*(L/6))*T(1));
T(3)=alfa*dt((1/alfa*t*dt)*T(3)+(1/alfa*t*dt)*T(3)-(2/alfa*(L/6))*T(3)+(1/alfa*(L/6))*T(4)+(1/alfa*(L/6))*T(2));
T(4)=alfa*dt((1/alfa*t*dt)*T(4)+(1/alfa*t*dt)*T(4)-(2/alfa*(L/6))*T(4)+(1/alfa*(L/6))*T(5)+(1/alfa*(L/6))*T(3));
T(5)=alfa*dt((1/alfa*t*dt)*T(5)+(1/alfa*t*dt)*T(5)-(2/alfa*(L/6))*T(5)+(1/alfa*(L/6))*T(6)+(1/alfa*(L/6))*T(4));
T(6)=alfa*dt((1/alfa*t*dt)*T(6)+(1/alfa*t*dt)*T(6)-(2/alfa*(L/6))*T(6)+(1/alfa*(L/6))*Tf+(1/alfa*(L/6))*T(5));

  0 Comments

Sign in to comment.