Created
November 25, 2020 17:02
-
-
Save dobrakmato/202148f0fe2b08bc34ca56a1b7c69ca0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment