Info
This question is closed. Reopen it to edit or answer.
Subscript indicies must either be real positive integers or logicals
1 view (last 30 days)
Show older comments
Hi,
I am trying to multiply two matrices together in a for loop however when I run my code it says that my matrix B, "Subscript indicies must either be real positive integers or logicals".
What does this mean and how can I fix it?
Thank you!
clear all;
clc;
K=0.6285;
alpha=1.516*10^-7;
dT=50;
r=0.02;
h=1000;
Fo=alpha*dT/(r/2)^2;
Tinf=100;
Bi=h*(r/2)/K;
T1(1)=2; % Temp @ Node-1
T2(1)=2; % Temp @ Node-2
T3(1)=2; %Temp @ Node-3
time(1)=0;
rho=997;
c=1.99;
%% Implicit Method
for k=1:20
A=[-((T1(k)*K*4*pi*(r/4)^2)/(r/2))-((rho*(4/3)*(r/4)^3*c*T1(k))/dT) ((T2(k)*K*4*pi*(r/4)^2)/(r/2)) 0; ((T1(k)*K*4*pi*(r/4)^2)/(r/2)) -((T2(k)*K*4*pi*(r/4)^2)/(r/2))-(((K*4*pi*((r/2)+(r/4))^2))/(r/2))-((rho*((4/3)*pi*(((r/2)+(r/4)^3)-(r/3)^3))*c*T2(k))/dT) ((K*4*pi*((r/2)+(r/4)^2)*T3(k))/(r/2)); 0 ((K*4*pi*r^2*T2(k))/(r/2)) -((K*4*pi*r^2*T3(k))/(r/2))-(h*4*pi*r^2*T3(k))-((rho*(4/3)*pi*r^3*c*T3(k))/dT)];
B=[-((rho*(4/3)*(r/4)^3*c*T1(k-1))/dT); -((rho((4/3)*pi*(((r/2)+(r/4)^3)-(r/3)^3))*c*T2(k-1))/dT); -((rho*(4/3)*pi*r^3*c*T3(k-1))/dT)-h*4*pi*r^2*Tinf];
X=inv(A)*B;
T1(k+1)=X(1);
T2(k+1)=X(2);
time(k+1)=k*dT;
whos ind
end
close all
plot(time, T1,'--*k',time, T2,'--pm',time, T3,'--og')
legend('T1','T2','T3')
xlabel('Time(sec)')
Subscript indices must either be real positive integers or logicals.
Error in Implicit_Method (line 22)
ind_double=[-((rho*(4/3)*(r/4)^3*c*T1(k-1))/dT);
-((rho((4/3)*pi*(((r/2)+(r/4)^3)-(r/3)^3))*c*T2(k-1))/dT);
-((rho*(4/3)*pi*r^3*c*T3(k-1))/dT)-h*4*pi*r^2*Tinf];
0 Comments
Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!