Matlab code for Euler method help
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I wrote the folowing code for Euler's method but Matlab is generating an error for the T(i+1) term. I need hep in understanding why is that happening and how to fix it. Thank you
%solving the equation using Euler's explicit method
% dT/dz = (Q + (4*U_eff*w/Dr)*(T-To))/G*cp;
z = 0.5;
Dr= 0.025;
cp_co2 = 0.85058;
cp_h2 = 14.865;
cp = 0.2*cp_co2 + 0.8*cp_h2;
To= 298;
Sco = -66000;
Ac = (3.1416*Dr^2);
Sc = Sco*(T-To);
Q= Sc*Ac*z ;
E = 0.4;
c = 0.75;
Gfr = 1;
p_co2 = 1.786;
p_h2 = 0.081347;
p = 0.2*p_co2 + 0.8*p_h2;
v_z = Gfr/p;
G = p*E*v_z;
tc_h2 = 0.19201;
tc_co2 = 0.01663;
tc_f = 0.2*tc_co2 + 0.8*tc_h2;
A = 1.75*(1-E)*E^3;
U_co2= 14.923*10^(-6);
U_h2 = 8.9117*10^(-6);
U = 0.2*U_co2 + 0.8*U_h2 ;
R= (p*v_z*z)/U ;
Su = A*R;
htc_w =tc_f/Su;
U_w = htc_w;
% Euler's Method notations
h= 0.001; %step size
z= 0:h:0.5; % range of bed length
N= numel(T); %range of T values
% At z= 0 T= To -- Initial Condition
%%Initializing Solutiion
T = zeros(size(z));
%% Solving equation using Euler's method
for i = 1:N-1
T(1)= To; %the initial tempereature in Euler
f = (Sc*Ac*z(i) + (4*U_w/Dr)*(T(i)-To))/G*cp;
% z(i+1) = z(i) + h*fi;
T(i+1) = T(i) + h*f;
end
plot(z,T);
1 Kommentar
Steven Lord
am 23 Okt. 2019
What is the full and exact text of the error message you received? That may give us useful information that will help us help you correct the problem. Show us all the text displayed in red (error message) and/or orange (warning message.)
Antworten (2)
James Tursa
am 23 Okt. 2019
Bearbeitet: James Tursa
am 23 Okt. 2019
z(i+1) = z(i) + f*h;
T(i+1) = T(i) + h;
plot(T,z);
2 Kommentare
James Tursa
am 23 Okt. 2019
Bearbeitet: James Tursa
am 23 Okt. 2019
Sorry ... I did not read your code properly. I now understand that z is your independent variable and T is your dependent variable. So these would be proper:
% z(i+1) = z(i) + h; % this line not really needed
T(i+1) = T(i) + h*f;
But I am still confused. In your code you use z and T in calculations prior to defining the z vector and prior to the loop. What is the value that z(1) is supposed to start at? 0.5 or 0.0 or ...?
Jim Riggs
am 23 Okt. 2019
Bearbeitet: Jim Riggs
am 23 Okt. 2019
One thing that I notice is that you are defining N based on numel(T), but it looks like T is not yet defined, so what is the value of N? It might be zero or 1. So your for loop is looping from i=1 to N-1 (i.e. i=1 to -1 or zero?).
I'm guessing that maybe N sould be numel(z)?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Error Detection and Correction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!