How to solve this system of differential equations with runge kutta method or with any other method on matlab?
조회 수: 9 (최근 30일)
이전 댓글 표시
댓글 수: 3
John D'Errico
2023년 4월 18일
편집: John D'Errico
2023년 4월 18일
Please learn to use comments, not answers to make a comment.
x is one of the unknowns. Can you not cube it? I'm pretty sure that x.^3 cubes a number, but perhaps you have a really old version of MATLAB, when cubes had not yet been invented. ;-)
And, yes, you have the cube of a derivative. But again, IF you read the help as I have told you to do multiple times now, you would see that it just becomes one of the unknowns.
doc ode45
Seriously. Did you read the help for ODE45? Did you look at the examples?
I would strongly suggest you try using a tool like ODE45 on a SIMPLE problem. Learn to use it.
Next, READ the help for ODE45, AGAIN. In there, they explicitly show you how to solve a second order ODE, doing so by turning it into a pair of first order ODEs. You have two second order ODEs. So you will have a system of 4 ODEs. That they are not linear ODEs is not a problem. Nothing in the code for ODE45 requires the ODE be linear.
답변 (1개)
Yash
2023년 11월 15일
Hi Giannis,
I understand that you are interested in solving a system of Ordinary Differential Equations (ODEs) using MATLAB. To solve the equations, you can follow these steps:
- Determine the initial conditions: Since you are dealing with second-order differential equations, you will typically need two initial conditions for each variable. For example, x1(0) = 0, dx1/dt(0) = 0, x2(0), and dx2/dt(0).
- Choose a method: If you specifically want to use the Runge-Kutta method, there is no built-in function for that in MATLAB. You will need to implement your own logic. However, if you are open to using other methods, you can directly use the "dsolve" function to solve the system of differential equations. Refer to the following link for the documentation: https://www.mathworks.com/help/symbolic/dsolve.html
Given below is an example using the "dsolve" function:
syms y(t) a
eqn = diff(y,t) == a*y;
cond = y(0) == 5;
ySol(t) = dsolve(eqn,cond)
This example solves the differential equation "dy/dt = a*y" with the initial condition "y(0) = 5". The solution is stored in the symbolic expression "ySol(t)".
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Equation Solving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!