Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Čermák Petr
Prm1
Commits
ee9cdab0
Commit
ee9cdab0
authored
Oct 25, 2019
by
Mareš Martin
Browse files
04: Další příklady z cvičení
parent
3df3a2a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
04-trideni/odmocnina.py
0 → 100755
View file @
ee9cdab0
#!/usr/bin/env python3
# Výpočet celočíselné druhé odmocniny binárním vyhledáváním.
x
=
int
(
input
())
# Odmocnina se nachazí v intervalu [l, p]
l
=
0
p
=
x
while
l
<=
p
:
stred
=
(
l
+
p
)
//
2
pokus
=
stred
**
2
if
pokus
==
x
:
print
(
"Odmocnina je"
,
stred
)
break
elif
pokus
<
x
:
l
=
stred
+
1
else
:
p
=
stred
-
1
else
:
print
(
"Odmocnina není celé číslo"
)
04-trideni/rovnice.py
0 → 100755
View file @
ee9cdab0
#!/usr/bin/env python3
# Přibližné řešení rovnice x=cos(x) binárním vyhledáváním
from
math
import
cos
# Udržujeme interval [l,p] takový, že x-cos(x) má na obou
# krajích intervalu opačná znaménka.
l
=
0
p
=
1
while
p
-
l
>
1e-10
:
x
=
(
l
+
p
)
/
2
if
x
-
cos
(
x
)
<
0
:
l
=
x
else
:
p
=
x
print
(
"Kořen leží mezi"
,
l
,
"a"
,
p
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment