Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
numer-60-2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kittipong Maneewong
numer-60-2
Commits
81a24dbc
Commit
81a24dbc
authored
Apr 26, 2018
by
Kittipong Maneewong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ส่งงาน week12
parent
2f8ed6b1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
Initial-Value.py
week12/Initial-Value.py
+7
-2
No files found.
week12/Initial-Value.py
View file @
81a24dbc
...
@@ -27,13 +27,17 @@ def bracket(f, **kwargs):
...
@@ -27,13 +27,17 @@ def bracket(f, **kwargs):
xi
-=
h
xi
-=
h
print
(
'Solution xi'
,
xi
,
f
(
xi
))
print
(
'Solution xi'
,
xi
,
f
(
xi
))
bracket
(
f
,
a
=-
2
,
b
=
2
,
h
=
0.01
)
bracket
(
f
,
a
=-
2
,
b
=
2
,
h
=
0.01
)
#Output Solution xi 1.0000000000000022 0.0
#Golden Section Search
#Golden Section Search
import
math
import
math
from
math
import
log
as
ln
R
=
(
-
1
+
5
**
0.5
)
/
2
R
=
(
-
1
+
5
**
0.5
)
/
2
def
n
(
a
=-
2
,
b
=
2
,
ebs
=
10
**-
9
)
:
eps
=
10
**-
9
def
n
(
a
=-
2
,
b
=
2
,
eps
=
10
**-
9
)
:
from
math
import
log
as
ln
from
math
import
log
as
ln
return
int
(
-
ln
(
R
)
*
ln
(
eps
/
abs
(
b
-
a
)))
return
int
(
ceil
(
-
2.078087
)
*
ln
(
eps
/
abs
(
b
-
a
)))
def
search
(
f
,
a
,
b
,
tol
=
1.0e-9
):
def
search
(
f
,
a
,
b
,
tol
=
1.0e-9
):
nIter
=
n
(
a
,
b
)
nIter
=
n
(
a
,
b
)
0.618033989
0.618033989
...
@@ -55,3 +59,4 @@ def search(f,a,b,tol=1.0e-9):
...
@@ -55,3 +59,4 @@ def search(f,a,b,tol=1.0e-9):
if
f1
<
f2
:
return
x1
,
f1
if
f1
<
f2
:
return
x1
,
f1
return
x2
,
f2
return
x2
,
f2
search
(
f
,
-
2
,
2
)
search
(
f
,
-
2
,
2
)
#Output (0.9999999940181203, 0.0)
Write
Preview
Markdown
is supported
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