Skip to content

Commit 554d8cb

Browse files
committed
Update exercise 5
1 parent bed23a9 commit 554d8cb

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/scipy_dev/notebooks/05_bounds_and_constraints.ipynb

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"import numpy as np\n",
3434
"\n",
3535
"def criterion(x):\n",
36-
" first = (x[\"a\"] - np.pi) ** 4 \n",
37-
" second = np.linalg.norm(x[\"b\"] - np.arange(3))\n",
38-
" third = np.linalg.norm(x[\"c\"] - np.eye(2))\n",
36+
" first = (x[\"a\"] - np.pi) ** 2\n",
37+
" second = np.sum((x[\"b\"] - np.arange(3)) ** 2)\n",
38+
" third = np.sum((x[\"c\"] - np.eye(2)) ** 2)\n",
3939
" return first + second + third\n",
4040
" \n",
4141
" \n",
@@ -55,10 +55,10 @@
5555
{
5656
"data": {
5757
"text/plain": [
58-
"{'a': 2.743115791004308,\n",
59-
" 'b': array([7.20526405e-06, 1.00000542e+00, 1.99999951e+00]),\n",
60-
" 'c': array([[ 1.00000752e+00, -1.83976834e-06],\n",
61-
" [ 5.75654246e-06, 1.00000339e+00]])}"
58+
"{'a': 3.141592653589793,\n",
59+
" 'b': array([1.55630437e-16, 1.00000000e+00, 2.00000000e+00]),\n",
60+
" 'c': array([[ 1.00000000e+00, -4.50891722e-18],\n",
61+
" [-4.51479888e-18, 1.00000000e+00]])}"
6262
]
6363
},
6464
"execution_count": 2,

src/scipy_dev/notebooks/solutions/05_bounds_and_constraints.ipynb

+18-18
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"import numpy as np\n",
3434
"\n",
3535
"def criterion(x):\n",
36-
" first = (x[\"a\"] - np.pi) ** 4 \n",
37-
" second = np.linalg.norm(x[\"b\"] - np.arange(3))\n",
38-
" third = np.linalg.norm(x[\"c\"] - np.eye(2))\n",
36+
" first = (x[\"a\"] - np.pi) ** 2\n",
37+
" second = np.sum((x[\"b\"] - np.arange(3)) ** 2)\n",
38+
" third = np.sum((x[\"c\"] - np.eye(2)) ** 2)\n",
3939
" return first + second + third\n",
4040
" \n",
4141
" \n",
@@ -55,10 +55,10 @@
5555
{
5656
"data": {
5757
"text/plain": [
58-
"{'a': 2.743115791004308,\n",
59-
" 'b': array([7.20526405e-06, 1.00000542e+00, 1.99999951e+00]),\n",
60-
" 'c': array([[ 1.00000752e+00, -1.83976834e-06],\n",
61-
" [ 5.75654246e-06, 1.00000339e+00]])}"
58+
"{'a': 3.141592653589793,\n",
59+
" 'b': array([1.55630437e-16, 1.00000000e+00, 2.00000000e+00]),\n",
60+
" 'c': array([[ 1.00000000e+00, -4.50891722e-18],\n",
61+
" [-4.51479888e-18, 1.00000000e+00]])}"
6262
]
6363
},
6464
"execution_count": 2,
@@ -98,9 +98,9 @@
9898
"data": {
9999
"text/plain": [
100100
"{'a': 2.0,\n",
101-
" 'b': array([0.5 , 1.11950355, 1.82926046]),\n",
102-
" 'c': array([[1.00000104e+00, 1.57485251e-06],\n",
103-
" [5.38584210e-06, 1.00000320e+00]])}"
101+
" 'b': array([0.5, 1. , 2. ]),\n",
102+
" 'c': array([[1., 0.],\n",
103+
" [0., 1.]])}"
104104
]
105105
},
106106
"execution_count": 3,
@@ -142,9 +142,9 @@
142142
"data": {
143143
"text/plain": [
144144
"{'a': 1.0,\n",
145-
" 'b': array([1.30231301e-06, 1.00000089e+00, 2.00000549e+00]),\n",
146-
" 'c': array([[1.02551721, 1. ],\n",
147-
" [0.05069564, 0.9944641 ]])}"
145+
" 'b': array([0., 1., 2.]),\n",
146+
" 'c': array([[1., 1.],\n",
147+
" [0., 1.]])}"
148148
]
149149
},
150150
"execution_count": 4,
@@ -188,17 +188,17 @@
188188
"name": "stderr",
189189
"output_type": "stream",
190190
"text": [
191-
"/Users/Tim_Mensinger/miniconda3/envs/scipy-estimagic/lib/python3.9/site-packages/pandas/core/frame.py:6254: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)\n",
191+
"/Users/Tim_Mensinger/miniconda3/envs/scipy-test/lib/python3.9/site-packages/pandas/core/frame.py:6254: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)\n",
192192
" diff = Index(subset).difference(self.columns)\n"
193193
]
194194
},
195195
{
196196
"data": {
197197
"text/plain": [
198-
"{'a': 2.855857369098579,\n",
199-
" 'b': array([-1.03938095e-06, 1.00000208e+00, 1.99999922e+00]),\n",
200-
" 'c': array([[ 0.32051835, 0.03349061],\n",
201-
" [-0.00143225, 0.64742329]])}"
198+
"{'a': 3.1415928282824384,\n",
199+
" 'b': array([-7.47836576e-09, 9.99999785e-01, 2.00000000e+00]),\n",
200+
" 'c': array([[ 0.75000093, -0.24999997],\n",
201+
" [-0.25000073, 0.74999977]])}"
202202
]
203203
},
204204
"execution_count": 5,

0 commit comments

Comments
 (0)