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
Littichai Buddaken
numer-60-2
Commits
4205dd1c
Commit
4205dd1c
authored
Apr 26, 2018
by
Littichai Buddaken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edited week13/Initial-Value.ipynb
parent
f7f9d76a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
267 additions
and
8 deletions
+267
-8
Initial-Value.ipynb
week13/Initial-Value.ipynb
+267
-8
goldenratio.png
week13/images/goldenratio.png
+0
-0
initialvalue.png
week13/images/initialvalue.png
+0
-0
powell.png
week13/images/powell.png
+0
-0
No files found.
week13/Initial-Value.ipynb
View file @
4205dd1c
...
...
@@ -14,14 +14,25 @@
"\n",
"$g(x), h(x)$ - constraint functions\n",
"\n",
"minimize $F(x)$ = maximize $-F(x)$\n"
"minimize $F(x)$ = maximize $-F(x)$\n",
"\n",
"> จงหาค่า $x$ ในช่วง $[a,b]$ ที่ทำ $f(x)$ มีค่าน้อยที่สุด"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"![image](./images/initialvalue.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
> จงหาค่า $x$ ในช่วง $[a,b]$ ที่ทำ $f(x)$ มีค่าน้อยที่สุด
\n",
"\n",
"\n",
"## Bracketing\n",
"- $x = a$\n",
...
...
@@ -29,6 +40,84 @@
"- กำหนดให้ $x = x + dx$ ไปเรื่อยๆ จนกว่า $f(x+dx) > f(x)$"
]
},
{
"cell_type": "code",
"execution_count": 99,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[-2.0, -1.9, -1.8, -1.7, -1.6, -1.5, -1.4, -1.3, -1.2, -1.1, -1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9]\n",
"[9.0, 8.41, 7.84, 7.289999999999999, 6.760000000000001, 6.25, 5.76, 5.29, 4.84, 4.41, 4.0, 3.6100000000000003, 3.24, 2.8899999999999997, 2.56, 2.25, 1.96, 1.69, 1.44, 1.21, 1.0, 0.81, 0.64, 0.49, 0.36, 0.25, 0.16000000000000003, 0.09000000000000008, 0.040000000000000036, 0.010000000000000009, 0.0, 0.010000000000000009, 0.040000000000000036, 0.09000000000000008, 0.15999999999999992, 0.25, 0.3600000000000003, 0.48999999999999977, 0.6400000000000001, 0.81]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHeZJREFUeJzt3Xl0VFW+9vHvLwkYSVRQJNoCKg4o4kQQAYcmit2KNCCi\nbavYjnFCnBFUcLhqK1wVHF7niSsaux1wRAWNvnpVGhBEEQdaVKRBbAUkgBBg3z92RRFDUhSp2udU\nPZ+1apGQquRZB/LkZJ+z9zbnHCIiEh95oQOIiMiGUXGLiMSMiltEJGZU3CIiMaPiFhGJGRW3iEjM\nqLhFRGJGxS0iEjMqbhGRmClIxydt3ry522GHHVJ67dKlSykqKmrYQA1E2VKjbKlRttTENduUKVP+\n45zbOqlP5Jxr8EdpaalLVWVlZcqvTTdlS42ypUbZUhPXbMBkl2THaqhERCRmVNwiIjGj4hYRiRkV\nt4hIzKi4RURiRsUtIhIzKm4RkZiJTnGvX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t6znaRt37EJcdV3n6uos/FjPtMTj7sTf/w54aZ2rsJ/hr8BfkaFsR+HHnlYA\n3wKvrJsNfzfAB4nHjChlC3jctgJeAz4HJgBbhj5utR0H4CzgrMTbBtyZ+PiH1HEXUYBsAxLH6AP8\nBfyuGcr1ODAPqE78XzstQsesvmxBjlniax+Iv34zfa1e69GQx04zJ0VEYib4UImIiGwYFbeISMyo\nuEVEYkbFLSISMypuEZGYUXGLiMSMiltEJGZU3CIiMfN/yqJrlosttiEAAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7f0d1b7d10b8>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def f(x) :return x**2-2*x+1\n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"x = [x/10 for x in range(-20,20,1)]\n",
"y = [f(xi) for xi in x]\n",
"print(x)\n",
"print(y)\n",
"a,b=-2,2\n",
"fa,fb =f(a),f(b)\n",
"plt.plot(x, y, 'r-')\n",
"plt.grid(True)\n",
"plt.show()\n",
"#x = a\n",
"#h = 0.01\n",
"#f(x+h),f(x+2h),f(x+3h)... \n",
"#f(x+i*h)<f(x+(i+1)*h)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"solution xi: 1.0000000000000022 0.0\n"
]
}
],
"source": [
"\n",
"#def bracket(f,a=-2,b=2,h=0.01):\n",
"def bracket(f,**kwargs): #**kwargs input is key word agrument,dicinary\n",
" a = float (kwargs['a']) \n",
" b = float (kwargs['b'])\n",
" h = float (kwargs['h'])\n",
" xi = a \n",
" oldf = f(xi)\n",
" xi += h\n",
" newf =f(xi)\n",
" while newf < oldf :\n",
" oldf=newf\n",
" xi+=h\n",
" newf =f(xi)\n",
" xi -= h\n",
" print('solution xi: ',xi,f(xi))\n",
"#bracket(f)\n",
"bracket(f,a=-2,b=2,h=0.01)"
]
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -36,14 +125,88 @@
"collapsed": true
},
"outputs": [],
"source": []
"source": [
"def Identity():\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Golden Section Search"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![image](./images/goldenratio.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"(1) \\to x_2 - x1 = 2Rh - h \\\\\n",
"(2) \\to x_1 - a = h' - Rh' \n",
"$$\n",
"แก้สมการหา $R$ จะได้\n",
"$$\n",
"2R - 1 = R(1-R) \\\\\n",
"R = \\frac{-1 + \\sqrt{5}}{2}\n",
"$$\n",
"จำนวนครั้งที่จะต้องใช้เพื่อหาคำตอบคือ\n",
"$$\n",
"n = -ln(R) ln(\\frac{\\epsilon}{|b-a|}\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import math "
]
},
{
"cell_type": "code",
"execution_count": 90,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"46"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from math import log as ln\n",
"R = (-1+5**0.5)/2\n",
"eps = 10**-9\n",
"a,b=-2,2\n",
"def n(a=-2,b=2,eps = 10**-9):\n",
" from math import log as ln\n",
" from math import ceil\n",
" R = (-1+5**0.5)/2\n",
" return int(ceil(-2.078087*ln(eps/abs(b-a))))\n",
"n()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Golden Section Search\n",
"\n",
"```python\n",
"def search(f,a,b,tol=1.0e-9):\n",
" nIter = int(math.ceil(-2.078087*math.log(tol/abs(b-a))))\n",
...
...
@@ -68,6 +231,91 @@
"```"
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {},
"outputs": [],
"source": [
"def f(x):return 4.8*x**2+6*x-2\n",
"def search(f,a,b,tol=10**-9):\n",
" N =n(a,b)\n",
" R = 0.618033989\n",
" C = 1.0 - R\n",
" # First telescoping\n",
" x1 = R*a + C*b; x2 = C*a + R*b\n",
" f1 = f(x1); f2 = f(x2)\n",
" # Main loop\n",
" for i in range(N):\n",
" if f1 > f2:\n",
" a = x1\n",
" x1 = x2; f1 = f2\n",
" x2 = C*a + R*b; f2 = f(x2)\n",
" else:\n",
" b = x2\n",
" x2 = x1; f2 = f1\n",
" x1 = R*a + C*b; f1 = f(x1)\n",
"\n",
" if f1 < f2: return x1,f1\n",
" return x2,f2\n"
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3.203906095884046e-10, -1.9999999980776564)"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"search(f,-2,2)\n",
"def f(x):return 4.8*x**2+6*x-2\n",
"search(f,0,100)"
]
},
{
"cell_type": "code",
"execution_count": 112,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHt1JREFUeJzt3Xu8lWP+//HXRygZxzG2JlFfGiTSlJQcIpEJ5ZTGqe9X\nbF+TcfiNSWXMgUeGYQzjyxAaOUUIIaW2lkJJpZFOSkWl2g5jOtFh78/vj2s1s7dk791ea19r3ev9\nfDzWY93r3vfa67MueXd13dd93ebuiIhIcm0XuwAREckuBb2ISMIp6EVEEk5BLyKScAp6EZGEU9CL\niCScgl5EJOEU9CIiCaegFxFJuO1jFwCw1157edOmTWOXUWtr165l5513jl1GzlB7bEltUpnao7Ka\ntse0adM+d/cfVXVcTgR906ZNmTp1auwyai2VStGpU6fYZeQMtceW1CaVqT0qq2l7mNnH1TlOQzci\nIgmnoBcRSTgFvYhIwinoRUQSTkEvIpJwCnoRkYRT0IuIJJyCXkQklvvug5KSrH+Mgl5EJIann4a+\nfeHhh7P+UQp6EZG6Nn48XHwxHHssDBmS9Y9T0IuI1KWZM6FH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iF5IhmwGfA39PDWQ+Z2c6xi4rF3ZcBdwCfAMuBf7n7a3GryhlF7r48vb0CKMrEL1XQ\nZ4iZ/QB4DrjG3VfFricWMzsNKHX3abFrySHbAz8F/uburYG1ZOif5PkoPe7cnfAX4I+Bnc3swrhV\n5R4PUyIzMi1SQZ8BZrYDIeSfcPcRseuJrCNwhpktJtwr+EQzezxuSdEtBZa6++Z/6T1LCP5CdRKw\nyN0/c/eNwAjg6Mg15YqVZtYIIP1cmolfqqCvJTMzwtjrHHe/M3Y9sbn7AHff192bEk6wve7uBd1b\nc/cVwBIzOyi9qzMwO2JJsX0CtDezhun/fzpTwCenv2Uk0Du93Rt4MRO/VEFfex2Biwg91xnpx89i\nFyU555fAE2b2PnAEcEvkeqJJ/8vmWWA6MJOQQwV3hayZDQMmAQeZ2VIz6wPcCnQxs/mEf/ncmpHP\n0pWxIiLJph69iEjCKehFRBJOQS8iknAKehGRhFPQi4gknIJeRCThFPQiIgmnoBcRSbj/D5tVwm9A\nlPmWAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7f0d1b5943c8>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"x = [x/10 for x in range(10,100,1)]\n",
"y = [f(xi) for xi in x]\n",
"plt.plot(x, y, 'r-')\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise\n",
"1. จงเขียนโปรแกรมหา $x$ ที่จะทห้ให้ฟังก์ชัน $f(x) = 1.6x^3 + 3x^2 -2x$ มีค่าน้อยที่สุด ในช่วงค่า $x \\ge 0$\n",
"2. จงเขียนโปรแกรมหา $x$ ที่จะทห้ให้ฟังก์ชัน $f(x) = 4.8x^2 + 6x - 2$ มีค่าน้อยที่สุด ในช่วงค่า $x \\ge 0$\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -90,9 +338,20 @@
" * $v_i = v_{i+1}$ ($v_1$ is discarded; the other vectors are reused).\n",
" * End loop\n",
" * $x_0 = x_{n+1}$\n",
"* End cycle\n",
"\n",
"\n",
"* End cycle\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Powell](./images/powell.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```python\n",
"import numpy as np\n",
"import math\n",
...
...
week13/images/goldenratio.png
0 → 100644
View file @
4205dd1c
14.7 KB
week13/images/initialvalue.png
0 → 100644
View file @
4205dd1c
21.6 KB
week13/images/powell.png
0 → 100644
View file @
4205dd1c
77 KB
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