To solve a second order differential equation with initial conditions using matrix method
Ältere Kommentare anzeigen
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 Kommentar
madhan ravi
am 4 Jun. 2020
Bearbeitet: madhan ravi
am 4 Jun. 2020
Is it your homework ? What did you try so far? https://www.mathworks.com/help/symbolic/massmatrixform.html
Antworten (1)
Ameer Hamza
am 4 Jun. 2020
Bearbeitet: Ameer Hamza
am 4 Jun. 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])
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!