How to define a system of differential equations with three variables and calculate their variation with time?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Michelle Westin
il 22 Apr 2020
Commentato: Michelle Westin
il 22 Apr 2020
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
0 Commenti
Risposta accettata
darova
il 22 Apr 2020
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);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!