How to define a system of differential equations with three variables and calculate their variation with time?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michelle Westin
am 22 Apr. 2020
Kommentiert: Michelle Westin
am 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 Kommentare
Akzeptierte Antwort
darova
am 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!