To solve a second order differential equation with initial conditions using matrix method
Afficher commentaires plus anciens
Consider a system governed by a second ODE y''+6y'+5y = 8*exp(-t) with the initial conditions y(0)=y'(0)=0, I need a matlab code to solve the equations using matrix methods
1 commentaire
madhan ravi
le 4 Juin 2020
Modifié(e) : madhan ravi
le 4 Juin 2020
Is it your homework ? What did you try so far? https://www.mathworks.com/help/symbolic/massmatrixform.html
Réponses (1)
Ameer Hamza
le 4 Juin 2020
Modifié(e) : Ameer Hamza
le 4 Juin 2020
Try the following code using ode45 (a numerical solver). Also, see this example from the documentation: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3uj8b
[t, y] = ode45(@odeFun, [0 10], [0; 0]);
plot(t, y, 'o-')
function dydt = odeFun(t, y)
A = [0 1;
-5 -6];
B = [0; 8];
u = exp(-t);
dydt = A*y + B*u;
end

Alternative method using symbolic toolbox
syms y(t)
eq = diff(y, 2) + 6*diff(y, 1) + 5*y == 8*exp(-t);
odeFun = matlabFunction(odeToVectorField(eq), 'Vars', {'t', 'Y'});
ode45(odeFun, [0 10], [0; 0])
Catégories
En savoir plus sur Symbolic Math Toolbox 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!