To solve a second order differential equation with initial conditions using matrix method
조회 수: 6 (최근 30일)
이전 댓글 표시
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
madhan ravi
2020년 6월 4일
편집: madhan ravi
2020년 6월 4일
Is it your homework ? What did you try so far? https://www.mathworks.com/help/symbolic/massmatrixform.html
답변 (1개)
Ameer Hamza
2020년 6월 4일
편집: Ameer Hamza
2020년 6월 4일
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])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!