Solve differnetial equation of state space
44 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I want to solve a differential equation of state space dx/dt = A*x + B*u, so I have a simple model with a Ground movement.
My equation is y'' = -d/m * y' - k/m * y + d/m * u' + k/m * u. I have the y (Output) and I want to find u, thats the Input to my system.
To have a first order equation i wrote dy(1) = y(2) and than dy(2) = -(d/m)*y(1)-(k/m)*y + (d/m)*u(1) + (k/m)*u(2)
m = 50;
d = 1000;
k = 30000;
A = [0,1;-k/m,-d/m];
B = [k/m;d/m];
C = [1,0];
D = [0];
Thats the code I've tried but it doesent function.
function du = fun(u,y)
dy = zeros(2,1)
dy(1) = y(2)
du = zeros(1,1)
du(1) = u2
%dy(2) = -(d/m)*y(1)-(k/m)*y + (d/m)*u(1) + (k/m)*u(2)
du(1) = -(m/d)*dy(2)-y(1)-(k/d)*y + (k/d)*u(1)
end
tspan = [0 10]
y0 = 1;
[u,y] = ode45(@(u,y) tspan, u0);
3 commentaires
Réponse acceptée
Ameer Hamza
le 29 Avr 2020
try this code. It assumes that y is know and u is unknown. I set y(t) to sin(t) as an example.
time = linspace(0,10,1000);
y = sin(time);
dy = gradient(y,time);
ddy = gradient(dy,time);
u0 = 0;
[t, u] = ode45(@(t,u) odeFun(t,u,time,y,dy,ddy), time, u0);
plot(t,u);
function dudt = odeFun(t, u, time, y, dy, ddy)
m = 50;
d = 1000;
k = 30000;
y = interp1(time, y, t);
dy = interp1(time, dy, t);
ddy = interp1(time, ddy, t);
dudt = m/d*(ddy + d/m*dy + k/m*y - k/m*u);
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Stability Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!