Effacer les filtres
Effacer les filtres

Writing code to implement Runge-Kutta methods 1 and 4 for a second order nonlinear ODE

1 vue (au cours des 30 derniers jours)
Hi, I am very stuck... I rewrote the equation to where it is written as two 1st order ODE's.
Given: y"(t)+0.05y'(t)+y^3(t)=7.5cos(t)
After re-writing I have:
y_1=y y'_1=y_2
y_2=y' y'_2=-0.05y_2-(y^3_1)+7.5cos(t)
So,
y_(1,i+1)=y_(1,i)+h*y_(2,i) y_(2,i+1)=y_(2,i)+h*(-0.05y_(2,i)-y^3_1+7.5cos(t)
Initial conditions as: y_1(0)=0 and y_2(0)=1
I need to implement these y_1 and y_2 into the Runge Kutta methods for RK1 and RK4.
Thank you!
  3 commentaires
James Tursa
James Tursa le 5 Mai 2016
@Jan: The usual meaning is RK1 is 1st order Runge Kutta (i.e., Euler Method), and RK4 is 4th order Runge Kutta.
James Tursa
James Tursa le 5 Mai 2016
@Bear12: Are you intending to use MATLAB provided functions for the integration? I.e., ode45? Or are you supposed to write the RK1 and RK4 integration code yourself?

Connectez-vous pour commenter.

Réponses (1)

Manali Gupta
Manali Gupta le 21 Juin 2019
Hi,
Attached file trk.m calculates the derivatives of the variables. The RK4 algorithm to solve the set of equations is implemented in solveOde.m.
I hope this helps.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by