Solve system of differential equations with vector input

1 visualización (últimos 30 días)
Xen
Xen el 14 de En. de 2020
Comentada: Star Strider el 15 de En. de 2020
Assume that I want to solve the system of equations below for u and v. A and B are known numbers (say, 1 and 2 respectively) and a(t) is a fixed vector that I want to pass to the solution and get the result. How can I do it? The code works fine when a(t) is not used.
syms A B u(t) v(t) a(t)
ode1 = diff(u,t) == A * (a - u);
ode2 = diff(v,t) == B * (u - v);
odes = [ode1; ode2];
[uSol(t), vSol(t)] = dsolve(odes);
% Above work fine; below don't
uF = matlabFunction(uSol);
vF = matlabFunction(vSol);
resultu = uF(0:10, 1, 2); % t, A, B
resultv = vF(0:10, 1, 2);

Respuesta aceptada

Star Strider
Star Strider el 14 de En. de 2020
In the derivation, let ‘a’ simply be an undefined constant, and define the initial conditions as 0 (unless you want them to be something else). Then in the solution, provide ‘a’ as a row vector to get the solution:
syms A B u(t) v(t) a
ode1 = diff(u,t) == A * (a - u);
ode2 = diff(v,t) == B * (u - v);
odes = [ode1; ode2];
[uSol(t), vSol(t)] = dsolve(odes, u(0)==0, v(0)==0)
% Above work fine; below don't
uF = matlabFunction(uSol);
vF = matlabFunction(vSol);
av = randn(1, 11);
resultu = uF(0:10, 1, 2, av); % t, A, B
resultv = vF(0:10, 1, 2, av);
This evaluates them as functions of whatever you want to define ‘a’ to be.
  2 comentarios
Xen
Xen el 15 de En. de 2020
That was way too simple... Thanks!
Star Strider
Star Strider el 15 de En. de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by