MATLAB Answers

0

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

Bear12 님이 질문을 제출함. 5 May 2016
최근 활동 Manali Gupta 님이 답변함. 21 Jun 2019
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

Please use the "{} Code" button to format your equations. Currently they are not readable. Are you aware that we cannot guiess what "RK1" and "RK4" means? Did you search for the thousands of examples for Runge-Kutta integrators written in Matlab?
@Jan: The usual meaning is RK1 is 1st order Runge Kutta (i.e., Euler Method), and RK4 is 4th order Runge Kutta.
@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?

로그인 to comment.

답변 수: 1

Manali Gupta 님의 답변 21 Jun 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.

  댓글 수: 0

로그인 to comment.



Translated by