Explicit method- Error

9 次查看(过去 30 天)
Abdulrahman Emad Al-Badawi
My script to find the temperature distrubution by varying the number of nodes and time step is below, I don't know what the error is on line 32:
k = 14.0;
density = 7650;
c = 513;
h_oil = 40;
h_a = 10;
T_oil = 515;
T_inf = 298;
T_air=298;
T_initial = 298; %(initial temperature of entire chopstick)
L = 0.33; %(total length of chopstick)
L_ex = 0.16; %(total part length of chopstick in air)
r_tip = 0.005; %(the end of chopstick immersed in the oil)
beta=0.01;
x=1;
r = r_tip + beta*x;
V=pi*(r^2)*L; %Assume the chopstick is cylindrical
delta_t= input('Enter time step');
n_oil=input ('Enter the number of nodes in oil');
n_air=input('Enter the number of nodes in air');
delta_x1=L/n_oil;
delta_x2=L/n_air;
for x= 0:0.1:L
for j=0:delta_t
for i=1:n_oil
for h=1:n_air
T1(1,j)=T_initial;
T2(1,j)=T_initial;
T3(1,j)=T_initial;
T4(1,j)=T_initial;
%line 31%
T1(i+n_oil,j+1)=(delta_t*density*c*V)*(T1(i,j)+h_oil*delta_x1*pi*r*k*(T_oil-T1(i,j))+k*pi*r*(4/3)*(T2(i,j)-T1(i,j));
T2(i+n_oil,j+1)=(dleta_t*density*c*V)*(T2(i,j)+h_oil*2*pi*r*delta_x1*(T_oil-T2(i,j))+(8/3)*k*pi*r*(T1(i,j)-T2(i,j))+2*pi*r*k(T3(h,j)-T2(i,j));
T3(h+n_air,j+1)=(dleta_t*density*c*V)*(T3(h,j)+h_air*2*pi*r*delta_x2*(T_air-T3(1,j))+2*pi*r*k(T2(i)-T1(i,j)+(8/3)*pi*r*k(T4(h,j)-T3(i,j));
T4(h+n_air,j+1)=(dleta_t*density*c*V)*(T4(h,j)+h_air*pi*r*delta_x2*(T_air-T4(h,j))+(8/3)*pi*r*k(T3(h,j)-T4(h,j));
end
end
end
if T1=>0.001 & T2=>0.001 & T3=>0.001 & T4=>0.001
printf('Steady State has been reached')
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2021-3-14
编辑:Walter Roberson 2021-3-14
for j=0:delta_t
j starts at 0
for i=1:n_oil
for h=1:n_air
T1(1,j)=T_initial;
You try to use j as a subscript, but j is 0 and 0 is not a valid subscript.
You would never have reached line 32.
T2(i+n_oil,j+1)=(dleta_t*density*c*V)*(T2(i,j)+h_oil*2*pi*r*delta_x1*(T_oil-T2(i,j))+(8/3)*k*pi*r*(T1(i,j)-T2(i,j))+2*pi*r*k(T3(h,j)-T2(i,j));
^^^^^^^
You have not defined any variable named dleta_t only delta_t
  4 个评论
Walter Roberson
Walter Roberson 2021-3-15
You look carefully at your expressions and add in a ) where one is missing, or you remove an extra one you do not need.
When you start getting a line long enough that the position of the brackets is not obvious, then it is time to start breaking the line into multiple assignments.
Exception: there are some cases involving complex conjugates transpose or transpose where you should not break a * or / or \ operator. Those are matrix algebra operations and it happens that A/B' can be implemented more efficiently than calculating B' and using A/result.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by