How to resolve the algorithm Runge-Kutta method step by step in the PureBasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Runge-Kutta method step by step in the PureBasic programming language

Table of Contents

Problem Statement

Given the example Differential equation: With initial condition: This equation has an exact solution:

Demonstrate the commonly used explicit   fourth-order Runge–Kutta method   to solve the above differential equation.

Starting with a given

y

n

{\displaystyle y_{n}}

and

t

n

{\displaystyle t_{n}}

calculate: then:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Runge-Kutta method step by step in the PureBasic programming language

Source code in the purebasic programming language

EnableExplicit
Define.i i
Define.d y=1.0, k1=0.0, k2=0.0, k3=0.0, k4=0.0, t=0.0

If OpenConsole()  
  For i=0 To 100
    t=i/10
    If Not i%10
      PrintN("y("+RSet(StrF(t,0),2," ")+") ="+RSet(StrF(y,4),9," ")+#TAB$+"Error ="+RSet(StrF(Pow(Pow(t,2)+4,2)/16-y,10),14," "))            
    EndIf    
    k1=t*Sqr(y)
    k2=(t+0.05)*Sqr(y+0.05*k1)
    k3=(t+0.05)*Sqr(y+0.05*k2)
    k4=(t+0.10)*Sqr(y+0.10*k3)    
    y+0.1*(k1+2*(k2+k3)+k4)/6    
  Next  
  Print("Press return to exit...") : Input()
EndIf
End

  

You may also check:How to resolve the algorithm Top rank per group step by step in the F# programming language
You may also check:How to resolve the algorithm Parallel brute force step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Password generator step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Eiffel programming language
You may also check:How to resolve the algorithm String prepend step by step in the OCaml programming language