Παρασκευή 19 Ιουνίου 2026

Romberg Integration

 This program use a triangle array which start with one item.  Each step add another array of single value. Each array start with one item and append as we work more.

rsin() is sin() using radians (the sin() function use degrees).


'https://rosettacode.org/wiki/Numerical_integration/Romberg_integration#M2000_Interpreter

 https://en.wikipedia.org/wiki/Romberg%27s_method


Module Romberg_integration {
    function Romberg(func as lambda,lower,upper,steps,acc=1e-8) {
      h0= upper-lower
      s0= func(lower)+func(upper)
      single r[0][0]
      r[0][0]=s0*h0/2
      rr= 0
      n= 1
      for i=1 to steps
           ro= rr
         n= 2*n
         h= h0/n
         s=s0/2
         for j= 1 to n-1
            s+=func(lower+j*h)
         next
         f=1
         r[i][0] = s*h
         for k= 1 to i
            r1= r[i][k-1]
            r2= r[i-1][k-1]
            f*=4
            rr=(f*r1-r2)/(f-1)
            r[i][k]=rr
         next
         if Abs(rr-ro) < acc then exit for
      next
      =rr
    }
    print round(Romberg((lambda->rsin(number)),0,1,5),8)=0.45969769    ' true
    print round(Romberg((lambda->exp(number)),-3,3,5),6)=20.035749 ' true
}
Romberg_integration

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.