How to solve 2nd order coupled ODE in Matlab using ode45 -or likewise function ?
Afficher commentaires plus anciens
I have to solve 2nd order coupled ODE for z(t) and x(t) in the equations below where all other terms are known and the derivatives are with respect to 't'
- (m) z''(t) + b z'(t) + c z(t) = 0
- (I+A) x''(t) + B x'(t) + c x(t) z(t) =0
The first equation is uncoupled and I was successful in finding out z(t) by solving the first equation alone using ode45(), but I am not able to solve both the equations combined.
Réponses (1)
Mischa Kim
le 30 Jan 2014
Modifié(e) : Mischa Kim
le 30 Jan 2014
Mahesh, it works just the same way. Something like:
[t,XSol] = ode45(@myODE, tspan, X0)
...
function Xd = myODE(t,X)
% define matrices and constants
x = X(1);
xd = X(2);
z = X(3);
zd = X(4);
Xd = [ xd;...
(-B*xd - c*x*z)/(I + A);...
zd;...
(-b*zd - c*z)/m];
end
The initial conditions, X0, need to be set accordingly, of course.
1 commentaire
Ryan Compton
le 25 Sep 2018
Modifié(e) : Ryan Compton
le 26 Sep 2018
Hi, I am trying to implement this code using my own diff EQs but I am getting errors. Here is my code
function Xd = myODE(t,X)
k1 = 5000
m1 = 300
k2 = 400000000
m2 = 10
r = 0
b = 3000
x1 = X(1)
x1d = X(2)
x2 = X(3)
x2d = X(4)
Xd = [x1d;...
(-k2/m1)*x2) + (k2/-m1)*x1 - (-b/m1)*x2d + (b/-m1)*x1d + (k1/-m1)*x1 - (k1/-m1)*r;...
x2d;...
(-k2/m2)*x2) + (k2/m2)*x1 - (b/m2)*x2d + (b/m2)*x1d]
end
and then calling:
tspan = [0 15]
X0 = [0 0 0 0]
[t,XSol] = ode45(@myODE, tspan, X0)
plot(t,XSol(:,1))
I am getting the following errors:
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled5 (line 4)
[t,X] = ode45(@fun, tspan, X0)
Would you be able to help me understand the issue. i am using matlab 2018a.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!