필터 지우기
필터 지우기

How to translate these functions into a Matlab rungekutta or ode45

조회 수: 1 (최근 30일)
Jose Trevino
Jose Trevino 2016년 3월 20일
답변: Pavithra Ashok Kumar 2016년 3월 24일
Hi, I'm working on a function that will calculate the time it takes for an object to go down a "curve line" more specifically a cycloid and I got these equations to determine the amount of time it takes to reach the bottom of the halfpipe:
p(t) = c(φ(t))
if V(t):=[φ(t), φ'(t)]
then, dV/dt = F(V):= [V2, ((-sin(V1)(RV2^2-g))/(2*R(1-cos(V1))))]
and the initial conditions are
V(0) = [φ(t), 0]
R=1 G=9.8m/s
How I can translate this set of equations into a function to be able to implement ode45 or use Runge Kuta method? I know that I should write the functions and later on their derivatives for the Runge Kuta, and the function itself with another function for ode45.
I have this but I do not feel confident with the code. How can I improve it or make it work?
y(1) = [phi,0]; % initial condition
F_xy = @(V1,V2) (V2,(-sin(V1)*(R*V2^2-g))/(2*R(1-cos(V1))))) % derivatives
for i=1:(length(x)-1) % calculation loop
k_1 = F_xy(x(i),y(i));
k_2 = F_xy(x(i)+0.5*h,y(i)+0.5*h*k_1);
k_3 = F_xy((x(i)+0.5*h),(y(i)+0.5*h*k_2));
k_4 = F_xy((x(i)+h),(y(i)+k_3*h));
y(i+1) = y(i) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;

답변 (1개)

Pavithra Ashok Kumar
Pavithra Ashok Kumar 2016년 3월 24일
Hi,
You can use the ode45 method with syntax as shown below: ode45(F_xy, [t_i t_f], y(1))
Ensure that you are substituting the appropriate values in the above equation. t_i and t_f refer to the initial and final time values. Refer here for more similar examples and information.
You can then verify if this output matches the output you obtained with your code to remove any kinks if they are present.
Hope this helps.
Regards
Pavithra

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by