Help with solving systems differential equations
Mostrar comentarios más antiguos
Hello everyone,
I have the following set of coupled first-order differential equations:
dA/A+dB/B=0
-dC-dD/kn1=R*A*dA
kn2*dE=-A*dA
dC/C=dE/E+dB/B
ds=kn2*dE/E-kn3*dC/C
dh=kn2*dE
dD/kn1=kn4*B*A^2/2/kn5
Where kn1,....kn5 are known parametres
I tried using the method that use here https://es.mathworks.com/matlabcentral/answers/514307-solve-numerically-a-system-of-first-order-differential-equations but matlab say it's unable to result it
I was wondering which could be a good attempt to solve numerically this system of differential equations.
Any suggestion?
Respuestas (1)
syms A(t) B(t) C(t) D(t) E(t) h(t) s(t)
syms kn1 kn2 kn3 kn4 kn5 R
dA = diff(A);
dB = diff(B);
dC = diff(C);
dD = diff(D);
dE = diff(E);
ds = diff(s);
dh = diff(h);
eqn1 = dA/A + dB/B == 0
eqn2 = -dC - dD/kn1 == R * A * dA
eqn3 = kn2*dE == -A*dA
eqn4 = dC/C == dE/E + dB/B
eqn5 = ds == kn2 * dE/E - kn3 * dC/C
eqn6 = dh == kn2*dE
eqn7 = dD/kn1 == kn4*B*A^2/2/kn5
eqns = [eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7].'
fcns = [A(t),B(t),C(t),D(t),E(t),h(t),s(t)];
[M, F] = massMatrixForm(eqns, fcns)
%convert matrix form into function of variables
syms t x [1 7]
Q = subs(M*ones(7,1)-F, fcns, x)
%parameter values for demonstration purposes
kn_vals = rand(1,5)
R_vals = rand*10
%create a function handle
obj = matlabFunction(subs(Q,[kn1,kn2,kn3,kn4,kn5,R], [kn_vals,R_vals]), 'vars', {t, x(:)})
%initial conditions for demonstration purposes
x0 = rand(1,7)
%run the function
[t,X] = ode45(obj, [0 0.015], x0);
plot(t,X)
For the random coefficients that I put in, you cannot get much further than this; shortly after this point, it fails integration, and that happens for both ode45() and ode23s()
2 comentarios
SARA TORRES UGIA
el 26 de Jul. de 2021
Walter Roberson
el 27 de Jul. de 2021
syms A(t) B(t) C(t) D(t) E(t) h(t) s(t)
syms kn1 kn2 kn3 kn4 kn5 R
dA = diff(A);
dB = diff(B);
dC = diff(C);
dD = diff(D);
dE = diff(E);
ds = diff(s);
dh = diff(h);
eqn1 = dA/A + dB/B == 0
eqn2 = -dC - dD/kn1 == B * A * dA
eqn3 = kn2*dE == -A*dA
eqn4 = dC/C == dE/E + dB/B
eqn5 = ds == kn2 * dE/E - kn3 * dC/C
eqn6 = dh == kn2*dE
eqn7 = dD/kn1 == kn4*B*A^2/2/kn5
eqns = [eqn1,eqn2,eqn3,eqn4,eqn5,eqn6,eqn7].'
fcns = [A(t),B(t),C(t),D(t),E(t),h(t),s(t)];
[M, F] = massMatrixForm(eqns, fcns)
%convert matrix form into function of variables
syms t x [1 7]
Q = subs(M*ones(7,1)-F, fcns, x)
%parameter values for demonstration purposes
Kn1= 0.001963;
Kn2= 1005;
Kn3= 287;
Kn4= 0.023;
Kn5= 0.05;
kn_vals = [Kn1 Kn2 Kn3 Kn4 Kn5]
%create a function handle
obj = matlabFunction(subs(Q,[kn1,kn2,kn3,kn4,kn5], [kn_vals]), 'vars', {t, x(:)})
%initial conditions for demonstration purposes
x0 = [85 1.703 220000 0 450 0 0];
%run the function
[t,X] = ode45(obj, [0 0.0005], x0);
plot(t,X)
Categorías
Más información sobre Formula Manipulation and Simplification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









