Solving system of ODE's contains complex equations

3 次查看(过去 30 天)
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 个评论
Bathala Teja
Bathala Teja 2021-8-31
I can avoid this by changing intial conditions.
My main question is how to solve this kind of problem. Dont consider values seriously.

请先登录,再进行评论。

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2021-8-31
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

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by