Solve task 1 in HM2
This commit is contained in:
parent
8c8aae635f
commit
97f211fa5e
5 changed files with 171 additions and 61 deletions
Binary file not shown.
|
@ -0,0 +1,84 @@
|
||||||
|
# %%
|
||||||
|
from IPython.display import display
|
||||||
|
from sympy import Matrix, symbols
|
||||||
|
|
||||||
|
[a, b] = symbols("x_1, x_2")
|
||||||
|
x0 = Matrix([1.1, 0.9])
|
||||||
|
print("x0:")
|
||||||
|
display(x0)
|
||||||
|
|
||||||
|
f = Matrix(
|
||||||
|
[
|
||||||
|
[20.0 - (18.0 * a) - 2.0 * (b ** 2.0)],
|
||||||
|
[(-4.0 * b) * (a - (b ** 2.0))]
|
||||||
|
])
|
||||||
|
|
||||||
|
Df = Matrix(
|
||||||
|
[
|
||||||
|
[-18.0, -4.0 * b],
|
||||||
|
[-4.0 * b, (-4.0 * a) + 12.0 * (b ** 2.0)]
|
||||||
|
])
|
||||||
|
|
||||||
|
Df0 = Df.subs(
|
||||||
|
{
|
||||||
|
a: x0[0],
|
||||||
|
b: x0[1]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
f0 = f.subs(
|
||||||
|
{
|
||||||
|
a: x0[0],
|
||||||
|
b: x0[1]
|
||||||
|
})
|
||||||
|
|
||||||
|
print("Df(x0):")
|
||||||
|
display(Df0)
|
||||||
|
print("f(x0):")
|
||||||
|
display(f0)
|
||||||
|
print("||f(x0)||_2")
|
||||||
|
display(f0.norm(2))
|
||||||
|
|
||||||
|
d0 = Df0.solve(-f0)
|
||||||
|
|
||||||
|
print("d0")
|
||||||
|
display(d0)
|
||||||
|
print("||d0||_2")
|
||||||
|
display(d0.norm(2))
|
||||||
|
|
||||||
|
x1 = x0 + d0
|
||||||
|
print("x1:")
|
||||||
|
display(x1)
|
||||||
|
|
||||||
|
Df1 = Df.subs(
|
||||||
|
{
|
||||||
|
a: x1[0],
|
||||||
|
b: x1[1]
|
||||||
|
})
|
||||||
|
|
||||||
|
f1 = f.subs(
|
||||||
|
{
|
||||||
|
a: x1[0],
|
||||||
|
b: x1[1]
|
||||||
|
})
|
||||||
|
|
||||||
|
print("Df(x1)")
|
||||||
|
display(Df1)
|
||||||
|
print("f(x1)")
|
||||||
|
display(f1)
|
||||||
|
print("||f(x1)||_2")
|
||||||
|
display(f1.norm(2))
|
||||||
|
|
||||||
|
d1 = Df1.solve(-f1)
|
||||||
|
|
||||||
|
print("d1")
|
||||||
|
display(d1)
|
||||||
|
print("||d1||_2")
|
||||||
|
display(d1.norm(2))
|
||||||
|
|
||||||
|
x2 = x1 + d1
|
||||||
|
|
||||||
|
print("x2")
|
||||||
|
display(x2)
|
||||||
|
|
||||||
|
# %%
|
Binary file not shown.
1
Pipfile
1
Pipfile
|
@ -12,6 +12,7 @@ pexpect = "*"
|
||||||
pandas = "*"
|
pandas = "*"
|
||||||
ipympl = "*"
|
ipympl = "*"
|
||||||
sympy = "*"
|
sympy = "*"
|
||||||
|
autopep8 = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
|
147
Pipfile.lock
generated
147
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "8c86c6849809fd6594aed0bf17bcfecc16e4e0e68b7949900346649d7b23c60a"
|
"sha256": "ea2bd254f76cfeb786601a62ad72ebe26d45d5bdccec54be02c3c65cb752ce50"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -23,6 +23,14 @@
|
||||||
],
|
],
|
||||||
"version": "==2.2.1"
|
"version": "==2.2.1"
|
||||||
},
|
},
|
||||||
|
"autopep8": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:86e9303b5e5c8160872b2f5ef611161b2893e9bfe8ccc7e2f76385947d57a2f1",
|
||||||
|
"sha256:f9849cdd62108cb739dbcdbfb7fdcc9a30d1b63c4cc3e1c1f893b5360941b61c"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==2.0.2"
|
||||||
|
},
|
||||||
"backcall": {
|
"backcall": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e",
|
"sha256:5cbdbf27be5e7cfadb448baf0aa95508f91f2bbc6c6437cd9cd06e2a4c215e1e",
|
||||||
|
@ -147,19 +155,19 @@
|
||||||
},
|
},
|
||||||
"fonttools": {
|
"fonttools": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:2bb244009f9bf3fa100fc3ead6aeb99febe5985fa20afbfbaa2f8946c2fbdaf1",
|
"sha256:909c104558835eac27faeb56be5a4c32694192dca123d073bf746ce9254054af",
|
||||||
"sha256:820466f43c8be8c3009aef8b87e785014133508f0de64ec469e4efb643ae54fb"
|
"sha256:f5e764e1fd6ad54dfc201ff32af0ba111bcfbe0d05b24540af74c63db4ed6390"
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '3.7'",
|
"markers": "python_version >= '3.8'",
|
||||||
"version": "==4.38.0"
|
"version": "==4.39.0"
|
||||||
},
|
},
|
||||||
"ipykernel": {
|
"ipykernel": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:430d00549b6aaf49bd0f5393150691edb1815afa62d457ee6b1a66b25cb17874",
|
"sha256:24ebd9715e317c185e37156ab3a87382410185230dde7aeffce389d6c7d4428a",
|
||||||
"sha256:6e9213484e4ce1fb14267ee435e18f23cc3a0634e635b9fb4ed4677b84e0fdf8"
|
"sha256:c8ff581905d70e7299bc1473a2f7c113bec1744fb3746d58e5b4b93bd8ee7001"
|
||||||
],
|
],
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==6.21.2"
|
"version": "==6.21.3"
|
||||||
},
|
},
|
||||||
"ipympl": {
|
"ipympl": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -171,11 +179,11 @@
|
||||||
},
|
},
|
||||||
"ipython": {
|
"ipython": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:b13a1d6c1f5818bd388db53b7107d17454129a70de2b87481d555daede5eb49e",
|
"sha256:5b54478e459155a326bf5f42ee4f29df76258c0279c36f21d71ddb560f88b156",
|
||||||
"sha256:b38c31e8fc7eff642fc7c597061fff462537cf2314e3225a19c906b7b0d8a345"
|
"sha256:735cede4099dbc903ee540307b9171fbfef4aa75cfcacc5a273b2cda2f02be04"
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '3.8'",
|
"markers": "python_version >= '3.8'",
|
||||||
"version": "==8.10.0"
|
"version": "==8.11.0"
|
||||||
},
|
},
|
||||||
"ipython-genutils": {
|
"ipython-genutils": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -300,50 +308,50 @@
|
||||||
},
|
},
|
||||||
"matplotlib": {
|
"matplotlib": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:01681566e95b9423021b49dea6a2395c16fa054604eacb87f0f4c439750f9114",
|
"sha256:08308bae9e91aca1ec6fd6dda66237eef9f6294ddb17f0d0b3c863169bf82353",
|
||||||
"sha256:03eb2c8ff8d85da679b71e14c7c95d16d014c48e0c0bfa14db85f6cdc5c92aad",
|
"sha256:14645aad967684e92fc349493fa10c08a6da514b3d03a5931a1bac26e6792bd1",
|
||||||
"sha256:092e6abc80cdf8a95f7d1813e16c0e99ceda8d5b195a3ab859c680f3487b80a2",
|
"sha256:21e9cff1a58d42e74d01153360de92b326708fb205250150018a52c70f43c290",
|
||||||
"sha256:0a776462a4a63c0bfc9df106c15a0897aa2dbab6795c693aa366e8e283958854",
|
"sha256:28506a03bd7f3fe59cd3cd4ceb2a8d8a2b1db41afede01f66c42561b9be7b4b7",
|
||||||
"sha256:0dfd4a0cbd151f6439e6d7f8dca5292839ca311e7e650596d073774847ca2e4f",
|
"sha256:2bf092f9210e105f414a043b92af583c98f50050559616930d884387d0772aba",
|
||||||
"sha256:111ef351f28fd823ed7177632070a6badd6f475607122bc9002a526f2502a0b5",
|
"sha256:3032884084f541163f295db8a6536e0abb0db464008fadca6c98aaf84ccf4717",
|
||||||
"sha256:21269450243d6928da81a9bed201f0909432a74e7d0d65db5545b9fa8a0d0223",
|
"sha256:3a2cb34336110e0ed8bb4f650e817eed61fa064acbefeb3591f1b33e3a84fd96",
|
||||||
"sha256:21a8aeac39b4a795e697265d800ce52ab59bdeb6bb23082e2d971f3041074f02",
|
"sha256:3ba2af245e36990facf67fde840a760128ddd71210b2ab6406e640188d69d136",
|
||||||
"sha256:21bd4033c40b95abd5b8453f036ed5aa70856e56ecbd887705c37dce007a4c21",
|
"sha256:3d7bc90727351fb841e4d8ae620d2d86d8ed92b50473cd2b42ce9186104ecbba",
|
||||||
"sha256:3493b48e56468c39bd9c1532566dff3b8062952721b7521e1f394eb6791495f4",
|
"sha256:438196cdf5dc8d39b50a45cb6e3f6274edbcf2254f85fa9b895bf85851c3a613",
|
||||||
"sha256:3a10428d4f8d1a478ceabd652e61a175b2fdeed4175ab48da4a7b8deb561e3fa",
|
"sha256:46a561d23b91f30bccfd25429c3c706afe7d73a5cc64ef2dfaf2b2ac47c1a5dc",
|
||||||
"sha256:3d1e52365d8d5af699f04581ca191112e1d1220a9ce4386b57d807124d8b55e6",
|
"sha256:4cf327e98ecf08fcbb82685acaf1939d3338548620ab8dfa02828706402c34de",
|
||||||
"sha256:3da8b9618188346239e51f1ea6c0f8f05c6e218cfcc30b399dd7dd7f52e8bceb",
|
"sha256:4f99e1b234c30c1e9714610eb0c6d2f11809c9c78c984a613ae539ea2ad2eb4b",
|
||||||
"sha256:4497d88c559b76da320b7759d64db442178beeea06a52dc0c629086982082dcd",
|
"sha256:544764ba51900da4639c0f983b323d288f94f65f4024dc40ecb1542d74dc0500",
|
||||||
"sha256:46ca923e980f76d34c1c633343a72bb042d6ba690ecc649aababf5317997171d",
|
"sha256:56d94989191de3fcc4e002f93f7f1be5da476385dde410ddafbb70686acf00ea",
|
||||||
"sha256:4f640534ec2760e270801056bc0d8a10777c48b30966eef78a7c35d8590915ba",
|
"sha256:57bfb8c8ea253be947ccb2bc2d1bb3862c2bccc662ad1b4626e1f5e004557042",
|
||||||
"sha256:51fb664c37714cbaac69c16d6b3719f517a13c96c3f76f4caadd5a0aa7ed0329",
|
"sha256:617f14ae9d53292ece33f45cba8503494ee199a75b44de7717964f70637a36aa",
|
||||||
"sha256:56b7b79488209041a9bf7ddc34f1b069274489ce69e34dc63ae241d0d6b4b736",
|
"sha256:6eb88d87cb2c49af00d3bbc33a003f89fd9f78d318848da029383bfc08ecfbfb",
|
||||||
"sha256:691ef1f15360e439886186d0db77b5345b24da12cbc4fc57b26c4826db4d6cab",
|
"sha256:75d4725d70b7c03e082bbb8a34639ede17f333d7247f56caceb3801cb6ff703d",
|
||||||
"sha256:71b751d06b2ed1fd017de512d7439c0259822864ea16731522b251a27c0b2ede",
|
"sha256:770a205966d641627fd5cf9d3cb4b6280a716522cd36b8b284a8eb1581310f61",
|
||||||
"sha256:7d0dcd1a0bf8d56551e8617d6dc3881d8a1c7fb37d14e5ec12cbb293f3e6170a",
|
"sha256:7b73305f25eab4541bd7ee0b96d87e53ae9c9f1823be5659b806cd85786fe882",
|
||||||
"sha256:827e78239292e561cfb70abf356a9d7eaf5bf6a85c97877f254009f20b892f89",
|
"sha256:7c9a4b2da6fac77bcc41b1ea95fadb314e92508bf5493ceff058e727e7ecf5b0",
|
||||||
"sha256:8665855f3919c80551f377bc16df618ceabf3ef65270bc14b60302dce88ca9ab",
|
"sha256:81a6b377ea444336538638d31fdb39af6be1a043ca5e343fe18d0f17e098770b",
|
||||||
"sha256:8f6efd313430d7ef70a38a3276281cb2e8646b3a22b3b21eb227da20e15e6813",
|
"sha256:83111e6388dec67822e2534e13b243cc644c7494a4bb60584edbff91585a83c6",
|
||||||
"sha256:9d85355c48ef8b9994293eb7c00f44aa8a43cad7a297fbf0770a25cdb2244b91",
|
"sha256:8704726d33e9aa8a6d5215044b8d00804561971163563e6e6591f9dcf64340cc",
|
||||||
"sha256:a06a6c9822e80f323549c6bc9da96d4f233178212ad9a5f4ab87fd153077a507",
|
"sha256:89768d84187f31717349c6bfadc0e0d8c321e8eb34522acec8a67b1236a66332",
|
||||||
"sha256:b51ab8a5d5d3bbd4527af633a638325f492e09e45e78afdf816ef55217a09664",
|
"sha256:8bf26ade3ff0f27668989d98c8435ce9327d24cffb7f07d24ef609e33d582439",
|
||||||
"sha256:c0592ba57217c22987b7322df10f75ef95bc44dce781692b4b7524085de66019",
|
"sha256:8c587963b85ce41e0a8af53b9b2de8dddbf5ece4c34553f7bd9d066148dc719c",
|
||||||
"sha256:c5465735eaaafd1cfaec3fed60aee776aeb3fd3992aa2e49f4635339c931d443",
|
"sha256:95cbc13c1fc6844ab8812a525bbc237fa1470863ff3dace7352e910519e194b1",
|
||||||
"sha256:c849aa94ff2a70fb71f318f48a61076d1205c6013b9d3885ade7f992093ac434",
|
"sha256:97cc368a7268141afb5690760921765ed34867ffb9655dd325ed207af85c7529",
|
||||||
"sha256:c869b646489c6a94375714032e5cec08e3aa8d3f7d4e8ef2b0fb50a52b317ce6",
|
"sha256:a867bf73a7eb808ef2afbca03bcdb785dae09595fbe550e1bab0cd023eba3de0",
|
||||||
"sha256:cb52aa97b92acdee090edfb65d1cb84ea60ab38e871ba8321a10bbcebc2a3540",
|
"sha256:b867e2f952ed592237a1828f027d332d8ee219ad722345b79a001f49df0936eb",
|
||||||
"sha256:cf119eee4e57389fba5ac8b816934e95c256535e55f0b21628b4205737d1de85",
|
"sha256:c0bd19c72ae53e6ab979f0ac6a3fafceb02d2ecafa023c5cca47acd934d10be7",
|
||||||
"sha256:cf6346644e8fe234dc847e6232145dac199a650d3d8025b3ef65107221584ba4",
|
"sha256:ce463ce590f3825b52e9fe5c19a3c6a69fd7675a39d589e8b5fbe772272b3a24",
|
||||||
"sha256:de20eb1247725a2f889173d391a6d9e7e0f2540feda24030748283108b0478ec",
|
"sha256:cf0e4f727534b7b1457898c4f4ae838af1ef87c359b76dcd5330fa31893a3ac7",
|
||||||
"sha256:eb2e76cd429058d8954121c334dddfcd11a6186c6975bca61f3f248c99031b05",
|
"sha256:def58098f96a05f90af7e92fd127d21a287068202aa43b2a93476170ebd99e87",
|
||||||
"sha256:f336e7014889c38c59029ebacc35c59236a852e4b23836708cfd3f43d1eaeed5",
|
"sha256:e99bc9e65901bb9a7ce5e7bb24af03675cbd7c70b30ac670aa263240635999a4",
|
||||||
"sha256:f4ddac5f59e78d04b20469bc43853a8e619bb6505c7eac8ffb343ff2c516d72f",
|
"sha256:eb7d248c34a341cd4c31a06fd34d64306624c8cd8d0def7abb08792a5abfd556",
|
||||||
"sha256:f910d924da8b9fb066b5beae0b85e34ed1b6293014892baadcf2a51da1c65807",
|
"sha256:f67bfdb83a8232cb7a92b869f9355d677bce24485c460b19d01970b64b2ed476",
|
||||||
"sha256:f91d35b3ef51d29d9c661069b9e4ba431ce283ffc533b981506889e144b5b40e",
|
"sha256:f883a22a56a84dba3b588696a2b8a1ab0d2c3d41be53264115c71b0a942d8fdb",
|
||||||
"sha256:fb0304c1cd802e9a25743414c887e8a7cd51d96c9ec96d388625d2cd1c137ae3"
|
"sha256:fbdeeb58c0cf0595efe89c05c224e0a502d1aa6a8696e68a73c3efc6bc354304"
|
||||||
],
|
],
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==3.7.0"
|
"version": "==3.7.1"
|
||||||
},
|
},
|
||||||
"matplotlib-inline": {
|
"matplotlib-inline": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -355,10 +363,10 @@
|
||||||
},
|
},
|
||||||
"mpmath": {
|
"mpmath": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:604bc21bd22d2322a177c73bdb573994ef76e62edd595d17e00aff24b0667e5c",
|
"sha256:7a28eb2a9774d00c7bc92411c19a89209d5da7c4c9a9e227be8330a23a25b91f",
|
||||||
"sha256:79ffb45cf9f4b101a807595bcb3e72e0396202e0b1d25d689134b48c4216a81a"
|
"sha256:a0b2b9fe80bbcd81a6647ff13108738cfb482d481d826cc0e02f5b35e5c88d2c"
|
||||||
],
|
],
|
||||||
"version": "==1.2.1"
|
"version": "==1.3.0"
|
||||||
},
|
},
|
||||||
"nest-asyncio": {
|
"nest-asyncio": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -551,18 +559,19 @@
|
||||||
},
|
},
|
||||||
"platformdirs": {
|
"platformdirs": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:8a1228abb1ef82d788f74139988b137e78692984ec7b08eaa6c65f1723af28f9",
|
"sha256:13b08a53ed71021350c9e300d4ea8668438fb0046ab3937ac9a29913a1a1350a",
|
||||||
"sha256:b1d5eb14f221506f50d6604a561f4c5786d9e80355219694a1b244bcd96f4567"
|
"sha256:accc3665857288317f32c7bebb5a8e482ba717b474f3fc1d18ca7f9214be0cef"
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '3.7'",
|
"markers": "python_version >= '3.7'",
|
||||||
"version": "==3.0.0"
|
"version": "==3.1.0"
|
||||||
},
|
},
|
||||||
"prompt-toolkit": {
|
"prompt-toolkit": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:6a2948ec427dfcc7c983027b1044b355db6aaa8be374f54ad2015471f7d81c5b"
|
"sha256:23ac5d50538a9a38c8bde05fecb47d0b403ecd0662857a86f886f798563d5b9b",
|
||||||
|
"sha256:45ea77a2f7c60418850331366c81cf6b5b9cf4c7fd34616f733c5427e6abbb1f"
|
||||||
],
|
],
|
||||||
"markers": "python_full_version >= '3.7.0'",
|
"markers": "python_full_version >= '3.7.0'",
|
||||||
"version": "==3.0.37"
|
"version": "==3.0.38"
|
||||||
},
|
},
|
||||||
"psutil": {
|
"psutil": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
@ -598,6 +607,14 @@
|
||||||
],
|
],
|
||||||
"version": "==0.2.2"
|
"version": "==0.2.2"
|
||||||
},
|
},
|
||||||
|
"pycodestyle": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053",
|
||||||
|
"sha256:8a4eaf0d0495c7395bdab3589ac2db602797d76207242c17d470186815706610"
|
||||||
|
],
|
||||||
|
"markers": "python_version >= '3.6'",
|
||||||
|
"version": "==2.10.0"
|
||||||
|
},
|
||||||
"pygments": {
|
"pygments": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297",
|
"sha256:b3ed06a9e8ac9a9aae5a6f5dbe78a8a58655d17b43b93c078f094ddc476ae297",
|
||||||
|
@ -762,6 +779,14 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==1.11.1"
|
"version": "==1.11.1"
|
||||||
},
|
},
|
||||||
|
"tomli": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
|
||||||
|
"sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"
|
||||||
|
],
|
||||||
|
"markers": "python_version < '3.11'",
|
||||||
|
"version": "==2.0.1"
|
||||||
|
},
|
||||||
"tornado": {
|
"tornado": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:1d54d13ab8414ed44de07efecb97d4ef7c39f7438cf5e976ccd356bebb1b5fca",
|
"sha256:1d54d13ab8414ed44de07efecb97d4ef7c39f7438cf5e976ccd356bebb1b5fca",
|
||||||
|
|
Loading…
Reference in a new issue