Solving system of ODE's contains complex equations
Mostrar comentarios más antiguos
Iam forming system of 3 ODE's(dy1/dt, dy2/dt, dy3/dt) using matrices A, B and V.
A and B matrices(both 3*3) are interms of some variable teta.
I want to substitute y3 in place of teta and proceed solving ODE's.
My ODE is inv(B).*(V-(A*Y)), where V = column matrix of order 3.
i tried like this
syms teta
Ai = cos(teta).*([2 5 1;
7 9 0;
4 1 3])
Bi = sin(teta).*([1 2 3;
4 5 6;
7 8 9])
V = ones(3, 1)
odefun = @(t,Y) inv(B).*(V-(A*Y));
A = subs(Ai, teta, Y(3))
B = subs(Bi, teta, Y(3))
tspan = [0 10];
Y0=zeros(3,1);
[t, Y] = ode45(odefun, tspan, Y0);
Y1 = Y(:, 1);
hold on
plot(t, Y1);
Y2 = Y(:, 1);
plot(t, Y2);
Y3 = Y(:, 1);
plot(t, Y3);
legend('Y1','Y2','Y3')
But iam getting this error
Unrecognized function or variable 'Y'.
Error in Untitled5 (line 43)
A = subs(Ai, teta, Y(3))
Facing issue in substituting Y3, how to resolve that?
4 comentarios
Bjorn Gustavsson
el 30 de Ag. de 2021
Even before that, what does the A and B-matrices look like for your initial conditions?
Bathala Teja
el 30 de Ag. de 2021
Bjorn Gustavsson
el 30 de Ag. de 2021
This surely makes
, which you then attempt to invert?
, which you then attempt to invert?
Bathala Teja
el 31 de Ag. de 2021
Respuestas (1)
Bjorn Gustavsson
el 31 de Ag. de 2021
The way it looks to me you have a problem something like this:
One problem is that the B-matrix you've given is singular which might be a problem. For problems like this there's not much need to doodle on with symbolic calculations, just implement the mass-matrix and ODE-function as matlab-functions and look for a numeric solution with ode45 or ode15s etc. Look at the help and documentation for those functions and focus in particular on the examples with mass-matrices. I'd figure the ODE-function would look something like:
function dydt = yourODE(t,y,A,V)
dydt = V - cos(y(3))*A*Y(:);
end
and the mass-matrix-function:
function M = yourMassM(t,y,B)
M = sin(y(3))*B;
end
Then you'll have to inform the ode-solver about the mass-matrix:
options = odeset('Mass',@(t,y) yourMassM(t,Y,B));
and then solve with some suitable initial conditions.
y0 = [pi/7,pi/11,pi/13];
t_span = [0,exp(17*pi)];
sol = ode15s(@(t,y) yourODE(t,y,A,V)),t_span,y0,options);
Since your mass-matrix is singular I dont guarantee that this works.
HTH
Categorías
Más información sobre Numeric Solvers 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!