Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
baillif_exercices
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
maths
baillif_exercices
Commits
26da14b5
Commit
26da14b5
authored
1 year ago
by
iliya
Browse files
Options
Downloads
Patches
Plain Diff
feat: added missing type annotations
parent
b9f6b029
Branches
revampProbStat
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
derive_and_min-max.py
+4
-4
4 additions, 4 deletions
derive_and_min-max.py
rf_methods.py
+16
-6
16 additions, 6 deletions
rf_methods.py
with
20 additions
and
10 deletions
derive_and_min-max.py
+
4
−
4
View file @
26da14b5
...
...
@@ -3,20 +3,20 @@ from rf_methods import rec_bisection, rec_regula_falsi, iter_bisection, \
from
Dual_Numbers
import
Dual_Number
def
f
(
x
:
Dual_Number
):
def
f
(
x
:
Dual_Number
)
->
float
:
return
((
x
*
x
-
1
)
*
Dual_Number
.
exp
(
x
-
1
)).
d
def
g
(
x
:
Dual_Number
):
def
g
(
x
:
Dual_Number
)
->
float
:
return
(
Dual_Number
.
sin
(
x
*
x
)
+
Dual_Number
.
exp
(
x
+
3
)
*
Dual_Number
.
cos
(
5
-
x
)).
d
def
dfdx
(
x
:
float
):
def
dfdx
(
x
:
float
)
->
float
:
return
f
(
Dual_Number
(
x
,
1
))
def
dgdx
(
x
:
float
):
def
dgdx
(
x
:
float
)
->
float
:
return
g
(
Dual_Number
(
x
,
1
))
...
...
This diff is collapsed.
Click to expand it.
rf_methods.py
+
16
−
6
View file @
26da14b5
import
numpy
as
np
from
typing
import
Callable
def
f
(
x
:
float
)
->
float
:
...
...
@@ -17,7 +18,8 @@ def z(x: float) -> float:
return
x
**
3
-
x
**
2
-
1
def
rec_regula_falsi
(
start
:
float
,
stop
:
float
,
func
,
debug
:
bool
)
->
float
:
def
rec_regula_falsi
(
start
:
float
,
stop
:
float
,
func
:
Callable
[[
float
],
float
],
debug
:
bool
)
->
float
:
cN
=
(
start
*
func
(
stop
)
-
stop
*
func
(
start
))
/
(
func
(
stop
)
-
func
(
start
))
if
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
start
)):
...
...
@@ -31,13 +33,14 @@ def rec_regula_falsi(start: float, stop: float, func, debug: bool) -> float:
# Testing the y-axis
if
np
.
abs
(
func
(
cN
))
<
1e-9
:
return
cN
return
rec_regula_falsi
(
start
,
stop
,
func
,
debug
)
else
:
return
cN
def
iter_regula_falsi
(
init_start
:
float
,
init_stop
:
float
,
func
,
debug
:
bool
)
\
->
float
:
def
iter_regula_falsi
(
init_start
:
float
,
init_stop
:
float
,
func
:
Callable
[[
float
],
float
],
debug
:
bool
)
->
float
:
cN
=
(
init_start
*
func
(
init_stop
)
-
init_stop
*
func
(
init_start
))
/
(
func
(
init_stop
)
-
func
(
init_start
))
start
=
init_start
...
...
@@ -48,18 +51,22 @@ def iter_regula_falsi(init_start: float, init_stop: float, func, debug: bool) \
while
np
.
abs
(
func
(
stop
)
-
func
(
start
))
>
1e-9
or
np
.
abs
(
func
(
cN
))
>
1e-9
:
if
debug
:
print
(
f
"
Iter =
{
iter
}
\t
x =
{
cN
}
\t
f(x) =
{
func
(
cN
)
}
"
)
cN
=
(
start
*
func
(
stop
)
-
stop
*
func
(
start
))
/
\
(
func
(
stop
)
-
func
(
start
))
if
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
start
)):
stop
=
cN
elif
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
stop
)):
start
=
cN
iter
+=
1
return
cN
def
rec_bisection
(
start
:
float
,
stop
:
float
,
func
,
debug
:
bool
)
->
float
:
def
rec_bisection
(
start
:
float
,
stop
:
float
,
func
:
Callable
[[
float
],
float
],
debug
:
bool
)
->
float
:
cN
=
(
stop
+
start
)
/
2
if
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
start
)):
...
...
@@ -70,13 +77,14 @@ def rec_bisection(start: float, stop: float, func, debug: bool) -> float:
if
np
.
abs
(
stop
-
start
)
>
1e-9
:
if
debug
:
print
(
f
"
x =
{
cN
}
\t
f(x) =
{
func
(
cN
)
}
"
)
return
rec_bisection
(
start
,
stop
,
func
,
debug
)
else
:
return
cN
def
iter_bisection
(
init_start
:
float
,
init_stop
:
float
,
func
,
debug
:
bool
)
->
\
float
:
def
iter_bisection
(
init_start
:
float
,
init_stop
:
float
,
func
:
Callable
[[
float
],
float
],
debug
:
bool
)
->
float
:
cN
=
(
init_stop
+
init_start
)
/
2
start
=
init_start
stop
=
init_stop
...
...
@@ -86,7 +94,9 @@ def iter_bisection(init_start: float, init_stop: float, func, debug: bool) -> \
while
np
.
abs
(
stop
-
start
)
>
1e-9
:
if
debug
:
print
(
f
"
Iter =
{
iter
}
\t
x =
{
cN
}
\t
f(x) =
{
func
(
cN
)
}
"
)
cN
=
(
stop
+
start
)
/
2
if
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
start
)):
stop
=
cN
elif
np
.
sign
(
func
(
cN
))
!=
np
.
sign
(
func
(
stop
)):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment