Using Runge-Kutta in Matlab
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to solve an equation dx/dt = f(x,t) where f(x,t) is a velocity. I want to solve for the positions x to obtain the trajectory x(t). I've seen that the time evolution of the positions x can be calculated using Runge-Kutta, but Matlab's implementation via ode45 (or similar) looks like it requires a function in the first argument. Here, I instead have a starting position x0 and compute the velocity at that initial point, f(x0,t0). How do I use Runge-Kutta to determine the time evolution of the position based on the velocities? If it matters, I can calculate an arbitrary instantaneous velocity f(x,t) from the forces acting on a position x. To give more context, I am calculating the velocity fxt = S*Fx where the matrix S and the force Fx both depend on the particle position, so the velocity that I calculate is a scalar.
댓글 수: 0
채택된 답변
Bruno Luong
2023년 8월 23일
편집: Bruno Luong
2023년 8월 23일
" I can calculate an arbitrary velocity f(x,t) from the forces acting on a position x."
Good this is a very good starting point. If you have f(x,t) in MATLAB function form,
then simply call
sol = ode45(@(t,x) f(x,t), [t0 tend], x0)
tend is the last time where you want the solution to be computed.
Read the doc of ode45
댓글 수: 8
추가 답변 (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!