How to define a system of differential equations with three variables and calculate their variation with time?

1 次查看(过去 30 天)
Hello,
I have the following system of equations (d is time derivative):
[M]xdd+[C]xd+[K]x = 0
where:
[M], [C] and [K] are 3x3 matrices.
xdd = [hdd; thetadd;betadd]
xd = [hd; thetad; betad]
x = [h; theta; beta]
With these I want to calculate [h;theta;beta;hd;thetad;betad].
I have literally try everythig, but I always get "not enough arguments".
My last try was to create a function like:
function dydt = dynamics(t,y,Mt,Ct,Kt)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = inv(Mt)*(-real(Ct)*y(2)-real(Kt)*y(1));
end
Saved as dynamics.m and in another file (besides specify Mt, Ct and Kt):
t = [0:30];
h = 0;
theta = 0;
beta = 0;
X0 = [h;theta;beta];
[t,Y] = ode45(@(t,Y)dynamics(t,Y,Mt,Ct,Kt),t,X0);
What am I doing wrong? Is there any other way to solve this kind of problem?
Thank you

采纳的回答

darova
darova 2020-4-22
Since your matrices are of 3x3 size the result should be of 3x1 size
function dydt = dynamics(t,y,Mt,Ct,Kt)
dydt = zeros(6,1);
y = y(:); % make column;
dydt(1:3) = y(4:6); % xd = [hd; thetad; betad]
dydt(4:6) = inv(Mt)*(-real(Ct)*y(4:6)-real(Kt)*y(1:3)); % xdd = [hdd; thetadd;betadd]
end
You have 3 variable of second degree each. YOu should have 6 initial conditions
X0 = [h;theta;beta;hd;thetad;betad];
[t,Y] = ode45(@(t,Y)dynamics(t,Y,Mt,Ct,Kt),t,X0);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by