Solve differnetial equation of state space
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
Ameer Hamza
le 29 Avr 2020
Thats not how we usually solve differential equations. Normally, u is given, and the goal is to find 'y'. Can you give an example of how vector y is given?
Bleron Kroni
le 29 Avr 2020
Ameer Hamza
le 29 Avr 2020
I misinterpreted the question initially. Try the code in my answer.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!