GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | DIFFEQN

Edit History

DIFFEQN

DIFFEQN x0, y0, xf, maxseg, maxerr, BYREF yf, BYREF errcode USE expr

Home > Reference > Math

Solving first-order differential equations using Runge-Kutta method.

  • expr : f(y,x) = dy/dx with start condition: y(x = x0) = y0
  • x0, y0 : initial x, y
  • xf : final x
  • yf : result
  • maxseq : equivalent to precision
  • maxerr : maximum allowed error
  • errcode : 0 for success; otherwise calculation error

Example 1

' Solving dy/dx = 7*y^2 * x^3 with start condition y(2) = 3 

def f1(x,y) = 7*y^2 * x^3

y0 = 3
x0 = 2
yf = 0
xf = 1 
maxseg = 10000
maxerr = 0.001
errcode = 0

diffeqn x0, y0, xf, maxseg, maxerr, yf, errcode USE f1(x,y)

' Exact solution for comparision
def g1(x) = -1 / (7/4 * x^4 - 85/3)

print "g1(xf) = "; g1(xf)
print "yf(xf) = "; yf

if(errcode != 0) then
    print "Error solving equation"
    print "Increasing maxseg might help"
endif

Example 2

' Defining the differential equation for a stiffness system

def f2(y,t) = -1000*y + 3000 - 2000 * exp(-t)

' Solving equation at time tf = 0.001 seconds with y(0) = 0
y0 = 0
t0 = 0
yf = 0
tf = 0.001 
maxseg = 1000
maxerr = 0.001
errcode = 0

diffeqn t0, y0, tf, maxseg, maxerr, yf, errcode USE f2(y,t)

' Exact solution for comparision
def g2(t) = 3 - 0.998*exp(-1000*t) - 2.002 * exp(-t)

print "g2(tf) = "; g2(tf)
print "yf(tf) = "; yf

if(errcode != 0) then
    print "Error solving equation"
    print "Increasing maxseg might help"
endif
Math
ABS   ABSMAX   ABSMIN   ACOS   ACOSH   ACOT   ACOTH   ACSC   ACSCH   ASEC   ASECH   ASIN   ASINH   ATAN   ATAN2   ATANH   ATN   CEIL   COS   COSH   COT   COTH   CSC   CSCH   DEG   DERIV   DETERM   DIFFEQN   EXP   EXPRSEQ   FIX   FLOOR   FRAC   INT   INTERSECT   INVERSE   LINEQN   LOG   LOG10   M3APPLY   M3IDENT   M3ROTATE   M3SCALE   M3TRANS   MAX   MIN   POLYAREA   POLYCENT   POLYEXT   POW   PTDISTLN   PTDISTSEG   PTSIGN   RAD   RND   ROOT   ROUND   SEC   SECH   SEGCOS   SEGLEN   SEGSIN   SEQ   SGN   SIN   SINH   SQR   STATMEAN   STATMEANDEV   STATMEDIAN   STATSPREADP   STATSPREADS   STATSTD   SUM   SUMSQ   TAN   TANH   TRANSPOSE  
This page was last edited on Mon, 23 Oct 2023 15:36:14 +0200 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.