How to resolve the algorithm Thiele's interpolation formula step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Thiele's interpolation formula step by step in the Wren programming language

Table of Contents

Problem Statement

Thiele's interpolation formula is an interpolation formula for a function f(•) of a single variable.   It is expressed as a continued fraction:

ρ

{\displaystyle \rho }

represents the   reciprocal difference,   demonstrated here for reference: Demonstrate Thiele's interpolation function by:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Thiele's interpolation formula step by step in the Wren programming language

Source code in the wren programming language

import "/fmt" for Fmt

var N = 32
var N2 = N * (N - 1) / 2
var STEP = 0.05

var xval = List.filled(N, 0.0)
var tsin = List.filled(N, 0.0)
var tcos = List.filled(N, 0.0)
var ttan = List.filled(N, 0.0)
var rsin = List.filled(N2, 0/0)
var rcos = List.filled(N2, 0/0)
var rtan = List.filled(N2, 0/0)

var rho 
rho = Fn.new { |x, y, r, i, n|
    if (n < 0) return 0
    if (n == 0) return y[i]
    var idx = (N - 1 - n) * (N - n) / 2 + i
    if (r[idx].isNan) {
        r[idx] = (x[i] - x[i + n]) /
                 (rho.call(x, y, r, i, n - 1) - rho.call(x, y, r, i + 1, n - 1)) +
                  rho.call(x, y, r, i + 1, n - 2)
    }
    return r[idx]
}

var thiele
thiele = Fn.new { |x, y, r, xin, n|
    if (n > N - 1) return 1
    return rho.call(x, y, r, 0, n) - rho.call(x, y, r, 0, n -2) +
           (xin - x[n]) / thiele.call(x, y, r, xin, n + 1)
}

for (i in 0...N) {
    xval[i] = i * STEP
    tsin[i] = xval[i].sin
    tcos[i] = xval[i].cos
    ttan[i] = tsin[i] / tcos[i]
}
Fmt.print("$16.14f", 6 * thiele.call(tsin, xval, rsin, 0.5, 0))
Fmt.print("$16.14f", 3 * thiele.call(tcos, xval, rcos, 0.5, 0))
Fmt.print("$16.14f", 4 * thiele.call(ttan, xval, rtan, 1.0, 0))

  

You may also check:How to resolve the algorithm Amicable pairs step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm 100 doors step by step in the GML programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Fantom programming language
You may also check:How to resolve the algorithm Even or odd step by step in the SQL programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the Mathematica / Wolfram Language programming language