RK4 method for solving first order equations

2 vues (au cours des 30 derniers jours)
Ali Mukhtar
Ali Mukhtar le 31 Mai 2024
% % % Equations % % %
syms T1(t) T2(t) T3(t) T4(t) T5(t) T6(t)
delta_T1 = ((2*alpha_1/lamda1^2)*(zeeta_12+eeta_1-2)*T1 + (2*alpha_1/lamda1^2)*zeeta_21*T2 + (2*alpha_1/lamda1^2)*eeta_5*T5 + (2*alpha_1/lamda1^2)*eeta_6*T6) == -((2*alpha_1/lamda1^2)*((Qe/2)/(k1*A1/lamda1)+(k5*A5/lamda5)+(k6*A6/lamda6)));
delta_T2 = ((2*alpha_2/lamda2^2)*zeeta_12*T1 + (2*alpha_2/lamda2^2)*(zeeta_21+zeeta_23-2)*T2 + (2*alpha_2/lamda2^2)*zeeta_32*T3);
delta_T3 = (2*alpha_3/lamda3^2)*(zeeta_23*T2 + (zeeta_32+zeeta_34-2)*T3 + zeeta_43*T4);
delta_T4 = ((2*alpha_4/lamda4^2)*(zeeta_34*T3 + (zeeta_43+eeta_4-2)*T4 + eetap_5*T5 + eetap_6*T6)) + ((2*alpha_4/lamda4^2)*((h_air*Sc*Tc/2)/(k4*A4/lamda4)+(k5*A5/lamda5)+(k6*A6/lamda6)+(h_air*Sc/2)));
delta_T5 = (2*alpha_5/lamda5^2)*(eeta_1*T1 + eetap_4*T4 + (eeta_5+eetap_5-2)*T5 + (eeta_6+eetap_6)*T6) + ((2*alpha_5/lamda5^2)*(h_steam*Sc*Tc/2)/(k4*A4/lamda4)+(k5*A5/lamda5)+(k6*A6/lamda6)+(h_steam*Sc/2)) == -((2*alpha_5/lamda5^2)*(Qe/2)/(k4*A4/lamda4)+(k5*A5/lamda5)+(k6*A6/lamda6));
delta_T6 = (2*alpha_6/lamda6^2)*(eeta_1*T1 + eetap_4*T4 + (eeta_5+eetap_5)*T5 + (eeta_6+eetap_6-2)*T6) + ((2*alpha_6/lamda6^2)*(h_liquid*Sc*Tc/2)/(k4*A4/lamda4)+(k5*A5/lamda5)+(k6*A6/lamda6)+(h_liquid*Sc/2)) == -((2*alpha_6/lamda6^2)*(Qe/2)/(k1*A1/lamda1)+(k5*A5/lamda5)+(k6*A6/lamda6));
delta_T = [delta_T1; delta_T2; delta_T3; delta_T4; delta_T5; delta_T6];
vars = [T1(t) T2(t) T3(t) T4(t) T5(t) T6(t)];
i have these 6 equtions i need to solve them through iteratively through RK4 method im facing difficulty to solve all six of them simultanenously and update them accordingly
  1 commentaire
John D'Errico
John D'Errico le 31 Mai 2024
Modifié(e) : John D'Errico le 31 Mai 2024
help ode45
ODE45 Solve non-stiff differential equations, medium order method. [TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) integrates the system of differential equations y' = f(t,y) from time TSPAN(1) to TSPAN(end) with initial conditions Y0. Each row in the solution array YOUT corresponds to a time in the column vector TOUT. * ODEFUN is a function handle. For a scalar T and a vector Y, ODEFUN(T,Y) must return a column vector corresponding to f(t,y). * TSPAN is a two-element vector [T0 TFINAL] or a vector with several time points [T0 T1 ... TFINAL]. If you specify more than two time points, ODE45 returns interpolated solutions at the requested times. * YO is a column vector of initial conditions, one for each equation. [TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0,OPTIONS) specifies integration option values in the fields of a structure, OPTIONS. Create the options structure with odeset. [TOUT,YOUT,TE,YE,IE] = ODE45(ODEFUN,TSPAN,Y0,OPTIONS) produces additional outputs for events. An event occurs when a specified function of T and Y is equal to zero. See ODE Event Location for details. SOL = ODE45(...) returns a solution structure instead of numeric vectors. Use SOL as an input to DEVAL to evaluate the solution at specific points. Use it as an input to ODEXTEND to extend the integration interval. ODE45 can solve problems M(t,y)*y' = f(t,y) with mass matrix M that is nonsingular. Use ODESET to set the 'Mass' property to a function handle or the value of the mass matrix. ODE15S and ODE23T can solve problems with singular mass matrices. ODE23, ODE45, ODE78, and ODE89 are all single-step solvers that use explicit Runge-Kutta formulas of different orders to estimate the error in each step. * ODE45 is for general use. * ODE23 is useful for moderately stiff problems. * ODE78 and ODE89 may be more efficient than ODE45 on non-stiff problems that are smooth except possibly for a few isolated discontinuities. * ODE89 may be more efficient than ODE78 on very smooth problems, when integrating over long time intervals, or when tolerances are tight. Example [t,y]=ode45(@vdp1,[0 20],[2 0]); plot(t,y(:,1)); solves the system y' = vdp1(t,y), using the default relative error tolerance 1e-3 and the default absolute tolerance of 1e-6 for each component, and plots the first component of the solution. Class support for inputs TSPAN, Y0, and the result of ODEFUN(T,Y): float: double, single See also ODE23, ODE78, ODE89, ODE113, ODE15S, ODE23S, ODE23T, ODE23TB, ODE15I, ODESET, ODEPLOT, ODEPHAS2, ODEPHAS3, ODEPRINT, DEVAL, ODEEXAMPLES, FUNCTION_HANDLE. Documentation for ode45 doc ode45 Other uses of ode45 dlarray/ode45
Unless of course, this is homework, and then you need to write it yourself. But if you need to write it yourself, then you should not be asking others to do it for you.
If not homework, then you should use ode45. Never write your own solvers when far better tools are available, written by professionals for your use. So which is it? Homework, in which case you have no choice, or actual work, in which case you should not be doing what you think you need to do?

Connectez-vous pour commenter.

Réponses (1)

Francisco J. Triveno Vargas
Francisco J. Triveno Vargas le 17 Juil 2024
You need to define the parameters alpha, lambda eta, zeta, etap, after you need to review
because you are using the simbolic toolbox
Regards

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by