# I don't know why ODE45 function does not count time. Runs forever.

1 view (last 30 days)
seongho yoo on 16 Oct 2019
Answered: Steven Lord on 16 Oct 2019
I study about lumped method and I use ode45, but it doesn't work.
There was no error message, it just keeps calculating all day long. It keeps entering the lumpe function over and over again with no end - forever.
I used this line to call the function:
[x y] = ode45(@lumpe,[1 5], [293 293 293 293 293 293 293])
Here is my lumpe function:
function dT= lumpe(t,T)
dT=zeros(7,1);
CV1_width= 0.0123; %(m)
CV1_depth= 0.0063; %(m)
CV1_height= 0.00025; %(m);
CV1_volume = CV1_height * CV1_depth * CV1_width ;%(m^3)
CV1_front = CV1_width * CV1_depth;%(m^2)
CV1_backs = CV1_width * CV1_depth;
CV1_right = CV1_depth * CV1_height;
CV1_left = CV1_depth * CV1_height;
CV1_top = CV1_depth * CV1_width;
CV1_bot = CV1_depth * CV1_width;
CV2_width= 0.0051; %(m) ;
CV2_depth= 0.0027; %(m);
CV2_height= 0.00025; %(m);
CV2_volume = CV2_height * CV2_depth * CV2_width ;%(m^3)
CV2_front = CV2_width * CV2_depth;%(m^2)
CV2_back = CV2_width * CV2_depth;
CV2_right = CV2_depth * CV2_height;
CV2_left = CV2_depth * CV2_height;
CV2_top = CV2_depth * CV2_width;
CV2_bot = CV2_depth * CV2_width;
CV3_width= 0.036; %(m) ;
CV3_depth= 0.063; %(m);
CV3_height= 0.00025; %(m);
CV3_volume = CV3_height * CV3_depth * CV3_width ;%(m^3)
CV3_front = CV3_width * CV3_depth;%(m^2)
CV3_back = CV3_width * CV3_depth;
CV3_right = CV3_depth * CV3_height;
CV3_left = CV3_depth * CV3_height;
CV3_top = CV3_depth * CV3_width;
CV3_bot = CV3_depth * CV3_width;
CV4_width= 0.051; %(m) ;
CV4_depth= 0.018; %(m);
CV4_height= 0.00025; %(m);
CV4_volume = CV4_height * CV4_depth * CV4_width ;%(m^3)
CV4_front = CV4_width * CV4_depth;%(m^2)
CV4_back = CV4_width * CV4_depth;
CV4_right = CV4_depth * CV4_height;
CV4_left = CV4_depth * CV4_height;
CV4_top = CV4_depth * CV4_width;
CV4_bot = CV4_depth * CV4_width;
CV5_width= 0.036; %(m) ;
CV5_depth= 0.063; %(m);
CV5_height= 0.00025; %(m);
CV5_volume = CV5_height * CV5_depth * CV5_width ;%(m^3)
CV5_front = CV5_width * CV5_depth;%(m^2)
CV5_back = CV5_width * CV5_depth;
CV5_right = CV5_depth * CV5_height;
CV5_left = CV5_depth * CV5_height;
CV5_top = CV5_depth * CV5_width;
CV5_bot = CV5_depth * CV5_width;
CV6_width= 0.05; %(m) ;
CV6_depth= 0.018; %(m);
CV6_height= 0.00025; %(m);
CV6_volume = CV6_height * CV6_depth * CV6_width ;%(m^3)
CV6_front = CV4_width * CV4_depth;%(m^2)
CV6_back = CV4_width * CV4_depth;
CV6_right = CV4_depth * CV4_height;
CV6_left = CV4_depth * CV4_height;
CV6_top = CV4_depth * CV4_width;
CV6_bot = CV4_depth * CV4_width;
CV7_width= 0.0123; %(m) ;
CV7_depth= 0.0063; %(m);
CV7_height= 0.0005; %(m);
CV7_volume = CV7_height * CV7_depth * CV7_width ;%(m^3)
CV7_front = CV7_width * CV7_depth;%(m^2)
CV7_back = CV7_width * CV7_depth;
CV7_right = CV7_depth * CV7_height;
CV7_left = CV7_depth * CV7_height;
CV7_top = CV7_depth * CV7_width;
CV7_bot = CV7_depth * CV7_width;
%Thermal properties air
h = 5; %W/(m^2*K) free convection
T_air = 295.3;%(K)
%silicon
rho_sil=2330; %(kg/m^3)
Cp_sil = 704.611;%(J/kg*k)
k_sil = 149;%(W/m*k)
%air
rho_air = 1.225; %(kg/m^3)
Cp_air = 1005; %(J/kg*k)
k_air = 0.003; %(W/m*k)
% SIO2 (corning 0774(붕규산유리)
rho_sio2 = 2330; %(kg/m^3)
Cp_sio2 = 753.48; %(J/kg*K)
k_sio2 = 1.14; %(W/m*K)
%heater sorce
%platinum resistance
R_pla = 105e-9;%(ohm*m)
R_total = R_pla* 22.25e-3 / (300e-9*0.5e-3);
V_in = 24; %(V)
Q_gen = V_in^2/R_total;
%thermal resistance
CV1_R_top = 1/(h*CV1_top);
CV1_R_bot2 = (CV1_height*0.5+CV2_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV2_top;
CV1_R_bot3 = (CV1_height*0.5+CV3_height*0.5)/(k_sil)*(CV3_top);
CV1_R_bot4 = (CV1_height*0.5+CV4_height*0.5)/(k_sil)*(CV4_top);
CV1_R_bot5 = (CV1_height*0.5+CV5_height*0.5)/(k_sil)*(CV5_top);
CV1_R_bot6 = (CV1_height*0.5+CV6_height*0.5)/(k_sil)*(CV6_top);
CV1_R_leftside = 1/(h*CV1_left);
CV1_R_rightside = 1/(h*CV1_right);
CV1_R_backside = 1/(h*CV1_backs);
CV1_R_frontside = 1/(h*CV1_front);
CV2_R_top = (CV1_height*0.5+CV2_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV2_top;
CV2_R_bot = (CV2_height*0.5+CV7_height*0.5)/(k_air*CV2_height*0.25+k_sil*CV7_height*0.75)/CV2_bot;
CV2_R_leftside = (CV2_width*0.5+CV3_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV3_width)))/CV2_left;
CV2_R_rightside = (CV2_width*0.5+CV5_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV2_width+CV5_width)))/CV2_right;
CV2_R_backside = (CV2_depth*0.5+CV4_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV4_depth))+k_sil*CV5_depth*(CV5_depth/(CV2_depth+CV5_depth)))/CV2_back;
CV2_R_frontside = (CV2_depth*0.5+CV6_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV6_depth))+k_sil*CV5_depth*(CV5_depth/(CV2_depth+CV6_depth)))/CV2_front;
CV3_R_top = (CV1_height*0.5+CV3_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV3_top;
CV3_R_bot = (CV3_height*0.5+CV7_height*0.5)/(k_air*CV3_height*0.25+k_sil*CV7_height*0.75)/CV3_bot;
CV3_R_leftside = 1/(h*CV3_left);
CV3_R_rightside = (CV3_width*0.5+CV2_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV3_width)))/CV3_right;
CV3_R_backside = 1/(h*CV3_back);
CV3_R_frontside = 1/(h*CV3_front);
CV4_R_top = (CV1_height*0.5+CV4_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV4_height*0.5)/CV4_top;
CV4_R_bot = (CV4_height*0.5+CV7_height*0.5)/(k_air*CV4_height*0.25+k_sil*CV7_height*0.75)/CV4_bot;
CV4_R_leftside = (CV4_width*0.5+CV3_width*0.5)/(k_air*CV4_width*(CV4_width/(CV4_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV4_width)))/CV4_left;
CV4_R_rightside = (CV4_width*0.5+CV5_width*0.5)/(k_air*CV4_width*(CV4_width/(CV4_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV4_width+CV5_width)))/CV4_right;
CV4_R_backside = 1/(h*CV4_back);
CV4_R_frontside = (CV4_depth*0.5+CV2_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV4_depth))+k_sil*CV4_depth*(CV4_depth/(CV2_depth+CV4_depth)))/CV4_front;
CV5_R_top = (CV5_height*0.5+CV3_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV5_top;
CV5_R_bot = (CV5_height*0.5+CV7_height*0.5)/(k_air*CV5_height*0.25+k_sil*CV7_height*0.75)/CV5_bot;
CV5_R_leftside = (CV5_width*0.5+CV2_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV2_width+CV5_width)))/CV5_right;
CV5_R_rightside = 1/(h*CV5_left);
CV5_R_backside = 1/(h*CV5_back);
CV5_R_frontside = 1/(h*CV5_front);
CV6_R_top = (CV1_height*0.5+CV6_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV6_height*0.5)/CV6_top;
CV6_R_bot = (CV6_height*0.5+CV7_height*0.5)/(k_air*CV6_height*0.25+k_sil*CV7_height*0.75)/CV6_bot;
CV6_R_leftside = (CV6_width*0.5+CV3_width*0.5)/(k_air*CV6_width*(CV6_width/(CV6_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV6_width)))/CV6_left;
CV6_R_rightside = (CV6_width*0.5+CV5_width*0.5)/(k_air*CV6_width*(CV6_width/(CV6_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV6_width+CV5_width)))/CV6_right;
CV6_R_backside = (CV6_depth*0.5+CV2_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV6_depth))+k_sil*CV6_depth*(CV6_depth/(CV2_depth+CV6_depth)))/CV6_front;
CV6_R_frontside = 1/(h*CV6_back);
CV7_R_bot = 1/(h*CV7_bot);
CV7_R_top2 = (CV7_height*0.5+CV2_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))/CV2_top;
CV7_R_top3 = (CV7_height*0.5+CV3_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV3_top);
CV7_R_top4 = (CV7_height*0.5+CV4_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV4_top);
CV7_R_top5 = (CV7_height*0.5+CV5_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV5_top);
CV7_R_top6 = (CV7_height*0.5+CV6_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV6_top);
CV7_R_leftside = 1/(h*CV7_left);
CV7_R_rightside = 1/(h*CV7_right);
CV7_R_backside = 1/(h*CV7_back);
CV7_R_frontside = 1/(h*CV7_front);
dT(1)=((-1)*((T(1)-T_air)/CV1_R_top + (T(1)-T(2))/CV1_R_bot2 + (T(1)-T(3))/CV1_R_bot3+(T(1)-T(4))/CV1_R_bot4+(T(1)-T(5))/CV1_R_bot5+(T(1)-T(6))/CV1_R_bot6+(T(1)-T_air)/CV1_R_rightside+(T(1)-T_air)/CV1_R_frontside+(T(1)-T_air)/CV1_R_backside+(T(1)-T_air)/CV1_R_leftside+Q_gen)/(rho_sil*Cp_sil*CV1_volume));
dT(2)=((-1)*((T(2)-T(1))/CV2_R_top + (T(2)-T(7))/CV2_R_bot + (T(2)-T(3))/CV2_R_leftside+(T(2)-T(5))/CV2_R_rightside+(T(2)-T(4))/CV2_R_backside+(T(2)-T(5))/CV2_R_frontside)/(rho_air*Cp_air*CV2_volume));
dT(3)=((-1)*((T(3)-T(1))/CV3_R_top + (T(3)-T(7))/CV3_R_bot + (T(3)-T_air)/CV3_R_leftside+(T(3)-T(2))/CV3_R_rightside+(T(3)-T_air)/CV3_R_backside+(T(3)-T_air)/CV3_R_frontside)/(rho_air*Cp_air*CV3_volume));
dT(4)=((-1)*((T(4)-T(1))/CV4_R_top+(T(4)-T(7))/CV4_R_bot+(T(4)-T(3))/CV4_R_leftside+(T(4)-T(5))/CV4_R_rightside+(T(4)-T_air)/CV4_R_backside+(T(4)-T(2))/CV4_R_frontside)/(rho_air*Cp_air*CV4_volume));
dT(5)=((-1)*((T(5)-T(1))/CV5_R_top+(T(5)-T(7))/CV5_R_bot+(T(5)-T(2))/CV5_R_leftside+(T(5)-T_air)/CV5_R_rightside+(T(5)-T_air)/CV5_R_backside+(T(5)-T_air)/CV5_R_frontside)/(rho_air*Cp_air*CV5_volume));
dT(6)=((-1)*((T(6)-T(1))/CV6_R_top+(T(6)-T(7))/CV6_R_bot+(T(6)-T(3))/CV6_R_leftside+(T(6)-T(5))/CV6_R_rightside+(T(4)-T(2))/CV6_R_backside+(T(4)-T_air)/CV6_R_frontside)/(rho_air*Cp_air*CV6_volume));
dT(7)=((-1)*((T(7)-T_air)/CV7_R_bot+(T(7)-T(2))/CV7_R_top2+(T(7)-T(3))/CV7_R_top3+(T(7)-T(4))/CV7_R_top4+(T(7)-T(5))/CV7_R_top5+(T(7)-T(6))/CV7_R_top6+(T(7)-T_air)/CV7_R_rightside+(T(7)-T_air)/CV7_R_frontside+(T(7)-T_air)/CV7_R_backside+(T(7)-T_air)/CV7_R_leftside)/(rho_sio2*Cp_sio2*CV7_volume));
end

Stephan on 16 Oct 2019
Edited: Stephan on 16 Oct 2019
Your code repeats calculations on constants that should be done only once for performance - but more important ist that your ode appears to be stiff, try ode15s or ode23s for example - this works well:
[x,y] = fun;
plot(x,y)
function [x,y] = fun
CV1_width= 0.0123; %(m)
CV1_depth= 0.0063; %(m)
CV1_height= 0.00025; %(m);
CV1_volume = CV1_height * CV1_depth * CV1_width ;%(m^3)
CV1_front = CV1_width * CV1_depth;%(m^2)
CV1_backs = CV1_width * CV1_depth;
CV1_right = CV1_depth * CV1_height;
CV1_left = CV1_depth * CV1_height;
CV1_top = CV1_depth * CV1_width;
CV1_bot = CV1_depth * CV1_width;
CV2_width= 0.0051; %(m) ;
CV2_depth= 0.0027; %(m);
CV2_height= 0.00025; %(m);
CV2_volume = CV2_height * CV2_depth * CV2_width ;%(m^3)
CV2_front = CV2_width * CV2_depth;%(m^2)
CV2_back = CV2_width * CV2_depth;
CV2_right = CV2_depth * CV2_height;
CV2_left = CV2_depth * CV2_height;
CV2_top = CV2_depth * CV2_width;
CV2_bot = CV2_depth * CV2_width;
CV3_width= 0.036; %(m) ;
CV3_depth= 0.063; %(m);
CV3_height= 0.00025; %(m);
CV3_volume = CV3_height * CV3_depth * CV3_width ;%(m^3)
CV3_front = CV3_width * CV3_depth;%(m^2)
CV3_back = CV3_width * CV3_depth;
CV3_right = CV3_depth * CV3_height;
CV3_left = CV3_depth * CV3_height;
CV3_top = CV3_depth * CV3_width;
CV3_bot = CV3_depth * CV3_width;
CV4_width= 0.051; %(m) ;
CV4_depth= 0.018; %(m);
CV4_height= 0.00025; %(m);
CV4_volume = CV4_height * CV4_depth * CV4_width ;%(m^3)
CV4_front = CV4_width * CV4_depth;%(m^2)
CV4_back = CV4_width * CV4_depth;
CV4_right = CV4_depth * CV4_height;
CV4_left = CV4_depth * CV4_height;
CV4_top = CV4_depth * CV4_width;
CV4_bot = CV4_depth * CV4_width;
CV5_width= 0.036; %(m) ;
CV5_depth= 0.063; %(m);
CV5_height= 0.00025; %(m);
CV5_volume = CV5_height * CV5_depth * CV5_width ;%(m^3)
CV5_front = CV5_width * CV5_depth;%(m^2)
CV5_back = CV5_width * CV5_depth;
CV5_right = CV5_depth * CV5_height;
CV5_left = CV5_depth * CV5_height;
CV5_top = CV5_depth * CV5_width;
CV5_bot = CV5_depth * CV5_width;
CV6_width= 0.05; %(m) ;
CV6_depth= 0.018; %(m);
CV6_height= 0.00025; %(m);
CV6_volume = CV6_height * CV6_depth * CV6_width ;%(m^3)
CV6_front = CV4_width * CV4_depth;%(m^2)
CV6_back = CV4_width * CV4_depth;
CV6_right = CV4_depth * CV4_height;
CV6_left = CV4_depth * CV4_height;
CV6_top = CV4_depth * CV4_width;
CV6_bot = CV4_depth * CV4_width;
CV7_width= 0.0123; %(m) ;
CV7_depth= 0.0063; %(m);
CV7_height= 0.0005; %(m);
CV7_volume = CV7_height * CV7_depth * CV7_width ;%(m^3)
CV7_front = CV7_width * CV7_depth;%(m^2)
CV7_back = CV7_width * CV7_depth;
CV7_right = CV7_depth * CV7_height;
CV7_left = CV7_depth * CV7_height;
CV7_top = CV7_depth * CV7_width;
CV7_bot = CV7_depth * CV7_width;
%Thermal properties air
h = 5; %W/(m^2*K) free convection
T_air = 295.3;%(K)
%silicon
rho_sil=2330; %(kg/m^3)
Cp_sil = 704.611;%(J/kg*k)
k_sil = 149;%(W/m*k)
%air
rho_air = 1.225; %(kg/m^3)
Cp_air = 1005; %(J/kg*k)
k_air = 0.003; %(W/m*k)
% SIO2 (corning 0774(붕규산유리)
rho_sio2 = 2330; %(kg/m^3)
Cp_sio2 = 753.48; %(J/kg*K)
k_sio2 = 1.14; %(W/m*K)
%heater sorce
%platinum resistance
R_pla = 105e-9;%(ohm*m)
R_total = R_pla* 22.25e-3 / (300e-9*0.5e-3);
V_in = 24; %(V)
Q_gen = V_in^2/R_total;
%thermal resistance
CV1_R_top = 1/(h*CV1_top);
CV1_R_bot2 = (CV1_height*0.5+CV2_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV2_top;
CV1_R_bot3 = (CV1_height*0.5+CV3_height*0.5)/(k_sil)*(CV3_top);
CV1_R_bot4 = (CV1_height*0.5+CV4_height*0.5)/(k_sil)*(CV4_top);
CV1_R_bot5 = (CV1_height*0.5+CV5_height*0.5)/(k_sil)*(CV5_top);
CV1_R_bot6 = (CV1_height*0.5+CV6_height*0.5)/(k_sil)*(CV6_top);
CV1_R_leftside = 1/(h*CV1_left);
CV1_R_rightside = 1/(h*CV1_right);
CV1_R_backside = 1/(h*CV1_backs);
CV1_R_frontside = 1/(h*CV1_front);
CV2_R_top = (CV1_height*0.5+CV2_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV2_top;
CV2_R_bot = (CV2_height*0.5+CV7_height*0.5)/(k_air*CV2_height*0.25+k_sil*CV7_height*0.75)/CV2_bot;
CV2_R_leftside = (CV2_width*0.5+CV3_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV3_width)))/CV2_left;
CV2_R_rightside = (CV2_width*0.5+CV5_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV2_width+CV5_width)))/CV2_right;
CV2_R_backside = (CV2_depth*0.5+CV4_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV4_depth))+k_sil*CV5_depth*(CV5_depth/(CV2_depth+CV5_depth)))/CV2_back;
CV2_R_frontside = (CV2_depth*0.5+CV6_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV6_depth))+k_sil*CV5_depth*(CV5_depth/(CV2_depth+CV6_depth)))/CV2_front;
CV3_R_top = (CV1_height*0.5+CV3_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV3_top;
CV3_R_bot = (CV3_height*0.5+CV7_height*0.5)/(k_air*CV3_height*0.25+k_sil*CV7_height*0.75)/CV3_bot;
CV3_R_leftside = 1/(h*CV3_left);
CV3_R_rightside = (CV3_width*0.5+CV2_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV3_width)))/CV3_right;
CV3_R_backside = 1/(h*CV3_back);
CV3_R_frontside = 1/(h*CV3_front);
CV4_R_top = (CV1_height*0.5+CV4_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV4_height*0.5)/CV4_top;
CV4_R_bot = (CV4_height*0.5+CV7_height*0.5)/(k_air*CV4_height*0.25+k_sil*CV7_height*0.75)/CV4_bot;
CV4_R_leftside = (CV4_width*0.5+CV3_width*0.5)/(k_air*CV4_width*(CV4_width/(CV4_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV4_width)))/CV4_left;
CV4_R_rightside = (CV4_width*0.5+CV5_width*0.5)/(k_air*CV4_width*(CV4_width/(CV4_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV4_width+CV5_width)))/CV4_right;
CV4_R_backside = 1/(h*CV4_back);
CV4_R_frontside = (CV4_depth*0.5+CV2_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV4_depth))+k_sil*CV4_depth*(CV4_depth/(CV2_depth+CV4_depth)))/CV4_front;
CV5_R_top = (CV5_height*0.5+CV3_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV2_height*0.5)/CV5_top;
CV5_R_bot = (CV5_height*0.5+CV7_height*0.5)/(k_air*CV5_height*0.25+k_sil*CV7_height*0.75)/CV5_bot;
CV5_R_leftside = (CV5_width*0.5+CV2_width*0.5)/(k_air*CV2_width*(CV2_width/(CV2_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV2_width+CV5_width)))/CV5_right;
CV5_R_rightside = 1/(h*CV5_left);
CV5_R_backside = 1/(h*CV5_back);
CV5_R_frontside = 1/(h*CV5_front);
CV6_R_top = (CV1_height*0.5+CV6_height*0.5)/(k_sil*CV1_height*0.5+k_air*CV6_height*0.5)/CV6_top;
CV6_R_bot = (CV6_height*0.5+CV7_height*0.5)/(k_air*CV6_height*0.25+k_sil*CV7_height*0.75)/CV6_bot;
CV6_R_leftside = (CV6_width*0.5+CV3_width*0.5)/(k_air*CV6_width*(CV6_width/(CV6_width+CV3_width))+k_sil*CV3_width*(CV3_width/(CV2_width+CV6_width)))/CV6_left;
CV6_R_rightside = (CV6_width*0.5+CV5_width*0.5)/(k_air*CV6_width*(CV6_width/(CV6_width+CV5_width))+k_sil*CV5_width*(CV5_width/(CV6_width+CV5_width)))/CV6_right;
CV6_R_backside = (CV6_depth*0.5+CV2_depth*0.5)/(k_air*CV2_depth*(CV2_depth/(CV2_depth+CV6_depth))+k_sil*CV6_depth*(CV6_depth/(CV2_depth+CV6_depth)))/CV6_front;
CV6_R_frontside = 1/(h*CV6_back);
CV7_R_bot = 1/(h*CV7_bot);
CV7_R_top2 = (CV7_height*0.5+CV2_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))/CV2_top;
CV7_R_top3 = (CV7_height*0.5+CV3_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV3_top);
CV7_R_top4 = (CV7_height*0.5+CV4_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV4_top);
CV7_R_top5 = (CV7_height*0.5+CV5_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV5_top);
CV7_R_top6 = (CV7_height*0.5+CV6_height*0.5)/(k_sil*CV2_height*(CV2_height/(CV2_height+CV7_height))+k_sio2*CV7_width*(CV7_height/(CV7_height+CV2_height)))*(CV6_top);
CV7_R_leftside = 1/(h*CV7_left);
CV7_R_rightside = 1/(h*CV7_right);
CV7_R_backside = 1/(h*CV7_back);
CV7_R_frontside = 1/(h*CV7_front);
[x, y] = ode15s(@lumpe,[1 5], [293 293 293 293 293 293 293]);
function dT= lumpe(t,T)
dT=zeros(7,1);
dT(1)=((-1)*((T(1)-T_air)/CV1_R_top + (T(1)-T(2))/CV1_R_bot2 + (T(1)-T(3))/CV1_R_bot3+(T(1)-T(4))/CV1_R_bot4+(T(1)-T(5))/CV1_R_bot5+(T(1)-T(6))/CV1_R_bot6+(T(1)-T_air)/CV1_R_rightside+(T(1)-T_air)/CV1_R_frontside+(T(1)-T_air)/CV1_R_backside+(T(1)-T_air)/CV1_R_leftside+Q_gen)/(rho_sil*Cp_sil*CV1_volume));
dT(2)=((-1)*((T(2)-T(1))/CV2_R_top + (T(2)-T(7))/CV2_R_bot + (T(2)-T(3))/CV2_R_leftside+(T(2)-T(5))/CV2_R_rightside+(T(2)-T(4))/CV2_R_backside+(T(2)-T(5))/CV2_R_frontside)/(rho_air*Cp_air*CV2_volume));
dT(3)=((-1)*((T(3)-T(1))/CV3_R_top + (T(3)-T(7))/CV3_R_bot + (T(3)-T_air)/CV3_R_leftside+(T(3)-T(2))/CV3_R_rightside+(T(3)-T_air)/CV3_R_backside+(T(3)-T_air)/CV3_R_frontside)/(rho_air*Cp_air*CV3_volume));
dT(4)=((-1)*((T(4)-T(1))/CV4_R_top+(T(4)-T(7))/CV4_R_bot+(T(4)-T(3))/CV4_R_leftside+(T(4)-T(5))/CV4_R_rightside+(T(4)-T_air)/CV4_R_backside+(T(4)-T(2))/CV4_R_frontside)/(rho_air*Cp_air*CV4_volume));
dT(5)=((-1)*((T(5)-T(1))/CV5_R_top+(T(5)-T(7))/CV5_R_bot+(T(5)-T(2))/CV5_R_leftside+(T(5)-T_air)/CV5_R_rightside+(T(5)-T_air)/CV5_R_backside+(T(5)-T_air)/CV5_R_frontside)/(rho_air*Cp_air*CV5_volume));
dT(6)=((-1)*((T(6)-T(1))/CV6_R_top+(T(6)-T(7))/CV6_R_bot+(T(6)-T(3))/CV6_R_leftside+(T(6)-T(5))/CV6_R_rightside+(T(4)-T(2))/CV6_R_backside+(T(4)-T_air)/CV6_R_frontside)/(rho_air*Cp_air*CV6_volume));
dT(7)=((-1)*((T(7)-T_air)/CV7_R_bot+(T(7)-T(2))/CV7_R_top2+(T(7)-T(3))/CV7_R_top3+(T(7)-T(4))/CV7_R_top4+(T(7)-T(5))/CV7_R_top5+(T(7)-T(6))/CV7_R_top6+(T(7)-T_air)/CV7_R_rightside+(T(7)-T_air)/CV7_R_frontside+(T(7)-T_air)/CV7_R_backside+(T(7)-T_air)/CV7_R_leftside)/(rho_sio2*Cp_sio2*CV7_volume));
end
end

#### 1 Comment

darova on 16 Oct 2019
Learned something new with this idea. Thanks

Steven Lord on 16 Oct 2019
In addition to what Stephan wrote, the fact that you have numbers in your variable names is also a bit of a code smell and is close to a discouraged anti-pattern. You're not auto-generating those variables, but manually generating them is likely to be tedious at best and a source of bugs at worst. [I did identify one potential bug in your code; see the end of this answer.] Let's look at a sample of your original code.
CV1_width= 0.0123; %(m)
CV1_depth= 0.0063; %(m)
CV1_height= 0.00025; %(m);
CV1_volume = CV1_height * CV1_depth * CV1_width ;%(m^3)
CV1_front = CV1_width * CV1_depth;%(m^2)
CV1_backs = CV1_width * CV1_depth;
CV1_right = CV1_depth * CV1_height;
CV1_left = CV1_depth * CV1_height;
CV1_top = CV1_depth * CV1_width;
CV1_bot = CV1_depth * CV1_width;
CV2_width= 0.0051; %(m) ;
CV2_depth= 0.0027; %(m);
CV2_height= 0.00025; %(m);
CV2_volume = CV2_height * CV2_depth * CV2_width ;%(m^3)
CV2_front = CV2_width * CV2_depth;%(m^2)
CV2_back = CV2_width * CV2_depth;
CV2_right = CV2_depth * CV2_height;
CV2_left = CV2_depth * CV2_height;
CV2_top = CV2_depth * CV2_width;
CV2_bot = CV2_depth * CV2_width;
Rather than doing that, why not make vectors of width, depth, height, etc. values and use element-wise arithmetic operations?
CV_width = [0.0123, 0.0051, 0.036]; % Let's add in CV3 as well
CV_depth = [0.0063, 0.0027, 0.063];
CV_height = [0.00025, 0.00025, 0.00025];
CV_volume = CV_width .* CV_depth .* CV_height;
CV_front = CV_width .* CV_depth;
CV_backs = CV_front;
CV_right = CV_depth .* CV_height;
CV_left = CV_right;
CV_top = CV_depth .* CV_width; % Same as CV_front?
CV_bot = CV_top;
If you wanted to scale this to more elements (tens, hundreds, thousands?) the only thing that would need to change in those ten lines would be the lines that actually define the data. If you were to scale to hundreds or thousands you'd probably want to read in the data and pass it into your ODE function as additional parameters rather than hard-coding them in your program. See the "Parameterizing Functions" link in the description of the fun input argument on each ODE solver's documentation page for more information. This avoids copying, pasting, and modifying those ten lines of code for each element.
Potential bug: Check your definition for the area of the top and bottom. Right now it's the same as the definition for the front and back. You sure it's not supposed to be width times height? My guess is that you made that error when you wrote up CV1_top and it got copied and pasted to CV2_top, CV3_top, etc.
This would have been even more apparent with a slight rearrangement of the code to compute all three "primary" quantities first and assign them to the "secondary" quantities afterwards. Depth appears in all three quantities and height only appears in the right variable.
CV_width = [0.0123, 0.0051, 0.036]; % Let's add in CV3 as well
CV_depth = [0.0063, 0.0027, 0.063];
CV_height = [0.00025, 0.00025, 0.00025];
CV_volume = CV_width .* CV_depth .* CV_height;
CV_front = CV_width .* CV_depth;
CV_right = CV_depth .* CV_height;
CV_top = CV_depth .* CV_width; % Same as CV_front?
CV_backs = CV_front;
CV_left = CV_right;
CV_bot = CV_top;