Skip to content

Instantly share code, notes, and snippets.

@dobrakmato
Created November 25, 2020 17:02
Show Gist options
  • Save dobrakmato/202148f0fe2b08bc34ca56a1b7c69ca0 to your computer and use it in GitHub Desktop.
Save dobrakmato/202148f0fe2b08bc34ca56a1b7c69ca0 to your computer and use it in GitHub Desktop.

Revisions

  1. dobrakmato created this gist Nov 25, 2020.
    30 changes: 30 additions & 0 deletions differencia
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    import math


    def f(x):
    return math.pow(3, x)


    a = 1
    h = 1
    riadkov = 5
    k = 1

    F = [[0.0 for _ in range(riadkov)] for _ in range(riadkov)]

    # spocitame prvy stlpec tabulky doprednou diferenciou, presnost O(h)
    for idx, h in enumerate([1 / 2 ** x for x in range(riadkov)]):
    F[idx][0] = (f(a + h) - f(a)) / h

    # pomocou richardsonovej extrapolacie dopocitame dalsie stlpce
    for j in range(1, riadkov):
    for i in range(j, riadkov):
    F[i][j] = (F[i - 1][j - 1] - (2 ** (k + j - 1)) * F[i][j - 1]) / (1 - (2 ** (k + j - 1)))

    # vpravo dole sa nachadza aprroximacia f'(a)
    # podla kalkulatora by to malo byt 3.2958368660043290741857357107675771139424716734682483552040830009
    for l in F:
    print(l)

    print("f_actual = 3.2958368660043290741857357107675771139424716734682483552040830009")
    print(f"f_approx = {F[riadkov - 1][riadkov - 1]}")