-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dodanie algorytmów: pierwiastek metodą Herona i całka nieoznaczona Ri…
…emanna.
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Obliczanie wartości pierwiastka kwadratowego z podanej liczby | ||
# przy użyciu metody Herona: a(n) = (a(n-1) + x / a(n-1)) / 2 | ||
# <eCG> | ||
|
||
|
||
def pierwiastek(x, d): | ||
a = x # inicjalizacja szkuanej wartości | ||
while abs(a - (x / a)) > d: | ||
a = (a + (x / a)) / 2 | ||
return a | ||
|
||
|
||
def main(args): | ||
# liczba dla której szukamy pierwiastka | ||
x = float(raw_input("Podaj liczbę: ")) | ||
# dokładność obliczeń | ||
d = float(raw_input("Podaj dokładność: ")) | ||
# drukujemy wynik z dokładnością do 6 miejsc | ||
print "Pierwiastek kwadratowy: {:.6f}".format(pierwiastek(x, d)) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
sys.exit(main(sys.argv)) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Obliczanie pola obszaru ograniczoneg wykresem funkcji: | ||
# y = x^2, prostymi x = a, x = b i osią OX | ||
# (oznaczona całka Riemanna) | ||
# <eCG> | ||
|
||
|
||
def funkcja(x): | ||
return x * x | ||
|
||
|
||
def pole(a, b, n): | ||
p = 0 # wyliczane pole | ||
d = (b - a) / n # długość przedziałów w zakresie <a;b> | ||
for i in range(n): | ||
x = a + (d * i) + (d / 2) # punkty pośrednie przedziałów | ||
p += abs(funkcja(x)) # suma pól prostokątów | ||
return p | ||
|
||
|
||
def main(args): | ||
a = int(raw_input("Podaj lewy kraniec: ")) | ||
b = int(raw_input("Podaj prawy kraniec: ")) | ||
n = int(raw_input("Podaj liczbę przedziałów: ")) | ||
print "Pole: {:.3f}".format(pole(a, b, n)) | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
sys.exit(main(sys.argv)) |