Explicit method- Error

조회 수: 9 (최근 30일)
Abdulrahman Emad Al-Badawi
Abdulrahman Emad Al-Badawi 2021년 3월 14일
댓글: Walter Roberson 2021년 3월 15일
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
Abdulrahman Emad Al-Badawi
Abdulrahman Emad Al-Badawi 2021년 3월 14일
How do I fix this?
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