cost_checks.nb 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. (* Content-type: application/vnd.wolfram.mathematica *)
  2. (*** Wolfram Notebook File ***)
  3. (* http://www.wolfram.com/nb *)
  4. (* CreatedBy='Wolfram 14.3' *)
  5. (*CacheID: 234*)
  6. (* Internal cache information:
  7. NotebookFileLineBreakTest
  8. NotebookFileLineBreakTest
  9. NotebookDataPosition[ 154, 7]
  10. NotebookDataLength[ 24335, 580]
  11. NotebookOptionsPosition[ 22033, 534]
  12. NotebookOutlinePosition[ 22429, 550]
  13. CellTagsIndexPosition[ 22386, 547]
  14. WindowFrame->Normal*)
  15. (* Beginning of Notebook Content *)
  16. Notebook[{
  17. Cell[BoxData[{
  18. RowBox[{
  19. RowBox[{"Clear", "[",
  20. RowBox[{"GetBeta", ",", " ", "Cost"}], "]"}], ";"}], "\[IndentingNewLine]",
  21. RowBox[{
  22. RowBox[{
  23. RowBox[{
  24. RowBox[{"GetBeta", "[",
  25. RowBox[{"{",
  26. RowBox[{"cc_", ",", "epsilon_", ",", "k1_", ",", "k2_"}], "}"}], "]"}],
  27. ":=",
  28. RowBox[{"Module", "[",
  29. RowBox[{
  30. RowBox[{"{",
  31. RowBox[{"beta", ",", "a", ",", "b", ",", "c", ",", "d"}], "}"}], ",",
  32. "\[IndentingNewLine]",
  33. RowBox[{
  34. RowBox[{"d", "=", "cc"}], ";", "\[IndentingNewLine]",
  35. RowBox[{"c", "=",
  36. RowBox[{
  37. RowBox[{"k2", "^", "2"}], "+",
  38. RowBox[{"epsilon", "^", "2"}]}]}], ";", "\[IndentingNewLine]",
  39. RowBox[{"b", "=",
  40. RowBox[{"k1", "*", "k2"}]}], ";", "\[IndentingNewLine]",
  41. RowBox[{"a", "=",
  42. RowBox[{
  43. RowBox[{"k1", "^", "2"}], "/", "3"}]}], ";", "\[IndentingNewLine]",
  44. "\[IndentingNewLine]",
  45. RowBox[{"Return", "[",
  46. RowBox[{"{",
  47. RowBox[{"d", ",", "c", ",", "b", ",", "a"}], "}"}], "]"}]}]}],
  48. "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]",
  49. RowBox[{
  50. RowBox[{"Cost", "[",
  51. RowBox[{"pars_", ",", "lam2_", ",", "x_", ",", "y_"}], "]"}], ":=",
  52. RowBox[{"Module", "[",
  53. RowBox[{
  54. RowBox[{"{",
  55. RowBox[{"beta", ",", "X", ",", "nllf", ",", "s", ",", "i"}], "}"}], ",",
  56. "\[IndentingNewLine]",
  57. RowBox[{
  58. RowBox[{"beta", " ", "=", " ",
  59. RowBox[{"GetBeta", "[", "pars", "]"}]}], ";", "\[IndentingNewLine]",
  60. "\[IndentingNewLine]",
  61. RowBox[{"s", "=",
  62. RowBox[{
  63. RowBox[{"2", "*", "y"}], "-", "1"}]}], ";", "\[IndentingNewLine]",
  64. RowBox[{"X", "=",
  65. RowBox[{"Transpose", "[",
  66. RowBox[{"Table", "[",
  67. RowBox[{
  68. RowBox[{"x", "^", "i"}], ",",
  69. RowBox[{"{",
  70. RowBox[{"i", ",", "0", ",", "3"}], "}"}]}], "]"}], "]"}]}], ";",
  71. "\[IndentingNewLine]",
  72. RowBox[{"nllf", " ", "=", " ",
  73. RowBox[{"Total", "[",
  74. RowBox[{"Log", "[",
  75. RowBox[{"1", "+",
  76. RowBox[{"Exp", "[",
  77. RowBox[{
  78. RowBox[{"-", "s"}], "*",
  79. RowBox[{"(",
  80. RowBox[{"X", ".", "beta"}], ")"}]}], "]"}]}], "]"}], "]"}]}], ";",
  81. "\[IndentingNewLine]", "\[IndentingNewLine]",
  82. RowBox[{"Return", "[",
  83. RowBox[{"nllf", " ", "+", " ",
  84. RowBox[{"lam2", " ",
  85. RowBox[{"Total", "[",
  86. RowBox[{"pars", "^", "2"}], "]"}]}]}], "]"}]}]}],
  87. "\[IndentingNewLine]", "]"}]}]}], "Input",
  88. CellChangeTimes->{{3.980215196159321*^9, 3.98021520112125*^9}, {
  89. 3.980215465357512*^9, 3.9802155187192497`*^9}, {3.980215561493145*^9,
  90. 3.98021556877605*^9}, {3.980215603281454*^9, 3.980215766491699*^9}, {
  91. 3.980215809381616*^9, 3.980215824734212*^9}, {3.9802159883378687`*^9,
  92. 3.980216092393737*^9}, {3.9802179711796503`*^9, 3.980217994933426*^9}, {
  93. 3.980218037526173*^9, 3.9802180508589983`*^9}, {3.980218114391039*^9,
  94. 3.9802182123715487`*^9}, {3.980218668097128*^9, 3.9802186800955877`*^9}, {
  95. 3.980219900715466*^9, 3.980219900917904*^9}, {3.9802199440804777`*^9,
  96. 3.980219950481944*^9}, {3.980220901657138*^9,
  97. 3.9802209090949917`*^9}},ExpressionUUID->"db312a24-878f-40c8-962f-\
  98. 6aedbdf27fe4"],
  99. Cell[CellGroupData[{
  100. Cell[BoxData[
  101. RowBox[{
  102. RowBox[{"(*",
  103. RowBox[{"TRIM", ",", " ", "log"}], "*)"}], "\[IndentingNewLine]",
  104. RowBox[{
  105. RowBox[{"x", "=",
  106. RowBox[{"{",
  107. RowBox[{
  108. "0.7444588568509963", ",", "0.4294306635860587", ",",
  109. "0.2424791244329582", ",", "0.1722166015253219", ",",
  110. "0.5155957608380367", ",",
  111. RowBox[{"-", "0.0044000248522457"}], ",", "0.2619898405306257", ",",
  112. "0.3707014579741952", ",", "0.3458779082346233", ",",
  113. RowBox[{"-", "0.0230997734892581"}], ",", "1.4235506263993014", ",",
  114. "0.1974151389300383", ",", "0.3479428293749495", ",",
  115. "0.038497594143739", ",",
  116. RowBox[{"-", "0.0494408800705622"}], ",", "0.1562561841152657", ",",
  117. "0.2440810426279506", ",", "0.738605475021583", ",",
  118. "0.3388466870335315", ",", "0.2730058878681247", ",",
  119. "0.2349466740981531", ",", "0.0152345391191637", ",",
  120. RowBox[{"-", "0.1306983645886834"}], ",", "0.3863126943346241", ",",
  121. "0.32696785342031", ",", "0.3960496407131636", ",", "0.116543550839155",
  122. ",", "0.3745678322136136", ",", "0.3902449371047537", ",",
  123. RowBox[{"-", "0.0224728544974076"}], ",", "0.3120049574170508", ",",
  124. "0.140909818171296", ",", "0.4065884615650837", ",",
  125. "0.1347990203891564", ",", "0.1747544412028135", ",",
  126. "0.8025435019583259", ",", "0.3424702625117166", ",",
  127. RowBox[{"-", "0.2576749555237702"}], ",", "0.2098741187455145", ",",
  128. "0.1827383448113199", ",", "0.4344451063845957", ",",
  129. "0.3628263770555691", ",", "0.3418422883292066", ",",
  130. "0.2690071065545839", ",", "0.3785734614926337", ",",
  131. "0.2619248908950089", ",", "0.232085349459071", ",",
  132. "0.1599028123673964", ",", "0.5800908847567773", ",",
  133. "0.208084169807583", ",",
  134. RowBox[{"-", "0.0239525163747711"}], ",", "0.2010508033108026", ",",
  135. "0.4280507666730073", ",", "0.4184257480672208", ",",
  136. "0.444582693795233", ",", "0.2107665896841349", ",",
  137. "0.3642384221371574"}], "}"}]}], "\[IndentingNewLine]",
  138. RowBox[{"y", "=",
  139. RowBox[{"{",
  140. RowBox[{
  141. "1", ",", "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "0", ",",
  142. "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "0", ",", "0", ",",
  143. "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "0", ",", "0", ",",
  144. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  145. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  146. "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  147. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  148. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  149. "0"}], "}"}]}], "\[IndentingNewLine]",
  150. RowBox[{"p", "=",
  151. RowBox[{"{",
  152. RowBox[{
  153. RowBox[{
  154. RowBox[{"-", "1.1319747348643707"}], " ",
  155. RowBox[{"10", "^", "1"}]}], ",",
  156. RowBox[{
  157. RowBox[{"-", "6.5316161792581431"}], "*", " ",
  158. RowBox[{"10", "^",
  159. RowBox[{"-", "5"}]}]}], ",", "1.6944026199144295", ",",
  160. "3.9357124963564112"}], "}"}]}], "\[IndentingNewLine]",
  161. RowBox[{"lam2", "=",
  162. RowBox[{"10", "^",
  163. RowBox[{"-", "3"}]}]}]}]}]], "Input",
  164. CellChangeTimes->{{3.980219550729746*^9, 3.980219552713852*^9}, {
  165. 3.980219691095812*^9, 3.9802197156948*^9}, {3.98022297307031*^9,
  166. 3.980222979562756*^9}},ExpressionUUID->"f22ff9ef-193c-434b-91da-\
  167. e9e8b3175259"],
  168. Cell[BoxData[
  169. RowBox[{"{",
  170. RowBox[{
  171. "0.7444588568509963`", ",", "0.4294306635860587`", ",",
  172. "0.2424791244329582`", ",", "0.1722166015253219`", ",",
  173. "0.5155957608380367`", ",",
  174. RowBox[{"-", "0.0044000248522457`"}], ",", "0.2619898405306257`", ",",
  175. "0.3707014579741952`", ",", "0.3458779082346233`", ",",
  176. RowBox[{"-", "0.0230997734892581`"}], ",", "1.4235506263993014`", ",",
  177. "0.1974151389300383`", ",", "0.3479428293749495`", ",",
  178. "0.038497594143739`", ",",
  179. RowBox[{"-", "0.0494408800705622`"}], ",", "0.1562561841152657`", ",",
  180. "0.2440810426279506`", ",", "0.738605475021583`", ",",
  181. "0.3388466870335315`", ",", "0.2730058878681247`", ",",
  182. "0.2349466740981531`", ",", "0.0152345391191637`", ",",
  183. RowBox[{"-", "0.1306983645886834`"}], ",", "0.3863126943346241`", ",",
  184. "0.32696785342031`", ",", "0.3960496407131636`", ",", "0.116543550839155`",
  185. ",", "0.3745678322136136`", ",", "0.3902449371047537`", ",",
  186. RowBox[{"-", "0.0224728544974076`"}], ",", "0.3120049574170508`", ",",
  187. "0.140909818171296`", ",", "0.4065884615650837`", ",",
  188. "0.1347990203891564`", ",", "0.1747544412028135`", ",",
  189. "0.8025435019583259`", ",", "0.3424702625117166`", ",",
  190. RowBox[{"-", "0.2576749555237702`"}], ",", "0.2098741187455145`", ",",
  191. "0.1827383448113199`", ",", "0.4344451063845957`", ",",
  192. "0.3628263770555691`", ",", "0.3418422883292066`", ",",
  193. "0.2690071065545839`", ",", "0.3785734614926337`", ",",
  194. "0.2619248908950089`", ",", "0.232085349459071`", ",",
  195. "0.1599028123673964`", ",", "0.5800908847567773`", ",",
  196. "0.208084169807583`", ",",
  197. RowBox[{"-", "0.0239525163747711`"}], ",", "0.2010508033108026`", ",",
  198. "0.4280507666730073`", ",", "0.4184257480672208`", ",",
  199. "0.444582693795233`", ",", "0.2107665896841349`", ",",
  200. "0.3642384221371574`"}], "}"}]], "Output",
  201. CellChangeTimes->{3.9802197180368643`*^9, 3.9802229692825193`*^9},
  202. CellLabel->"Out[59]=",ExpressionUUID->"a7f74a5e-642c-4b21-9dc6-dc4532fcd2dd"],
  203. Cell[BoxData[
  204. RowBox[{"{",
  205. RowBox[{
  206. "1", ",", "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "0", ",", "0", ",",
  207. "0", ",", "0", ",", "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0",
  208. ",", "0", ",", "1", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  209. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0",
  210. ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "0", ",", "0", ",",
  211. "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0",
  212. ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",",
  213. "0", ",", "0", ",", "0", ",", "0"}], "}"}]], "Output",
  214. CellChangeTimes->{3.9802197180368643`*^9, 3.980222969285266*^9},
  215. CellLabel->"Out[60]=",ExpressionUUID->"6fe63fdd-9529-4ff3-95a7-2b315610cc0a"],
  216. Cell[BoxData[
  217. RowBox[{"{",
  218. RowBox[{
  219. RowBox[{"-", "11.319747348643707`"}], ",",
  220. RowBox[{"-", "0.00006531616179258143`"}], ",", "1.6944026199144295`", ",",
  221. "3.935712496356411`"}], "}"}]], "Output",
  222. CellChangeTimes->{3.9802197180368643`*^9, 3.98022296928763*^9},
  223. CellLabel->"Out[61]=",ExpressionUUID->"9174505c-bb9d-4cfc-a204-c6c464fab952"],
  224. Cell[BoxData[
  225. FractionBox["1", "1000"]], "Output",
  226. CellChangeTimes->{3.9802197180368643`*^9, 3.980222969288666*^9},
  227. CellLabel->"Out[62]=",ExpressionUUID->"dfb9c680-45f0-495e-bc68-7c102a014c4a"]
  228. }, Open ]],
  229. Cell[CellGroupData[{
  230. Cell[BoxData[
  231. RowBox[{"Cost", "[",
  232. RowBox[{"p", ",", "lam2", ",", "x", ",", "y"}], "]"}]], "Input",
  233. CellChangeTimes->{{3.9802197403954973`*^9, 3.980219744640079*^9}},
  234. CellLabel->"In[17]:=",ExpressionUUID->"73502887-6057-4d13-881a-8932ae266804"],
  235. Cell[BoxData["2.9061537536536557`"], "Output",
  236. CellChangeTimes->{{3.980219744932208*^9, 3.9802197515000153`*^9}},
  237. CellLabel->"Out[17]=",ExpressionUUID->"603f6210-ea83-425d-9d61-d60dffe5c701"]
  238. }, Open ]],
  239. Cell[BoxData[
  240. RowBox[{"Needs", "[", "\"\<NumericalCalculus`\>\"", "]"}]], "Input",
  241. CellChangeTimes->{{3.9802198372526817`*^9, 3.980219843824862*^9}},
  242. CellLabel->"In[18]:=",ExpressionUUID->"417b4445-9108-40f3-a80b-fda472fd9d54"],
  243. Cell[CellGroupData[{
  244. Cell[BoxData["p"], "Input",
  245. CellChangeTimes->{3.9802203983793707`*^9},
  246. CellLabel->"In[38]:=",ExpressionUUID->"3ca07280-6eb4-41d4-8ab2-dfe9bbf7b8be"],
  247. Cell[BoxData[
  248. RowBox[{"{",
  249. RowBox[{
  250. RowBox[{"-", "11.319747348643707`"}], ",",
  251. RowBox[{"-", "0.00006531616179258143`"}], ",", "1.6944026199144295`", ",",
  252. "3.935712496356411`"}], "}"}]], "Output",
  253. CellChangeTimes->{3.980220398702986*^9},
  254. CellLabel->"Out[38]=",ExpressionUUID->"029d324b-6436-44a3-8803-14c8381b5896"]
  255. }, Open ]],
  256. Cell[CellGroupData[{
  257. Cell[BoxData[
  258. RowBox[{
  259. RowBox[{"(*", "gradient", "*)"}], "\[IndentingNewLine]",
  260. RowBox[{
  261. RowBox[{
  262. RowBox[{
  263. RowBox[{"DCost", "[",
  264. RowBox[{"i_", ",", "p_"}], "]"}], ":=",
  265. RowBox[{"Module", "[",
  266. RowBox[{
  267. RowBox[{"{",
  268. RowBox[{"u", ",", "ii"}], "}"}], ",",
  269. RowBox[{"ND", "[",
  270. RowBox[{
  271. RowBox[{"Cost", "[",
  272. RowBox[{
  273. RowBox[{"Table", "[",
  274. RowBox[{
  275. RowBox[{"If", "[",
  276. RowBox[{
  277. RowBox[{"i", "==", "ii"}], ",", "u", ",",
  278. RowBox[{"p", "[",
  279. RowBox[{"[", "ii", "]"}], "]"}]}], "]"}], ",",
  280. RowBox[{"{",
  281. RowBox[{"ii", ",",
  282. RowBox[{"Length", "[", "p", "]"}]}], "}"}]}], "]"}], ",",
  283. "lam2", ",", "x", ",", "y"}], "]"}], ",", "u", ",",
  284. RowBox[{"p", "[",
  285. RowBox[{"[", "i", "]"}], "]"}], ",",
  286. RowBox[{"Terms", "->", "10"}]}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]",
  287. RowBox[{"Table", "[",
  288. RowBox[{
  289. RowBox[{"DCost", "[",
  290. RowBox[{"i", ",", "p"}], "]"}], ",",
  291. RowBox[{"{",
  292. RowBox[{"i", ",",
  293. RowBox[{"Length", "[", "p", "]"}]}], "}"}]}], "]"}]}]}]], "Input",
  294. CellChangeTimes->{{3.98021979703826*^9, 3.980219827377369*^9}, {
  295. 3.980219863431608*^9, 3.9802198819049683`*^9}, {3.980219995402974*^9,
  296. 3.980219997759408*^9}, {3.980220196481331*^9, 3.980220213434679*^9}, {
  297. 3.980220348281417*^9, 3.980220363235091*^9}, {3.980220425600909*^9,
  298. 3.9802205459722*^9}, {3.980220589175432*^9, 3.980220594692799*^9}, {
  299. 3.9802207059692497`*^9, 3.9802207262248*^9}, {3.9802210428429956`*^9,
  300. 3.980221072838937*^9}, {3.980221280858418*^9, 3.980221289567711*^9}, {
  301. 3.980221422741997*^9,
  302. 3.98022142313131*^9}},ExpressionUUID->"b0ded771-dccd-45f6-a46c-\
  303. 9b2ff466801f"],
  304. Cell[BoxData[
  305. RowBox[{"{",
  306. RowBox[{
  307. RowBox[{"-", "2.02166414330068`*^-6"}], ",",
  308. RowBox[{"-", "3.137769860503177`*^-8"}], ",", "4.938462760785317`*^-7", ",",
  309. RowBox[{"-", "2.546636364252448`*^-6"}]}], "}"}]], "Output",
  310. CellChangeTimes->{{3.980219870760887*^9, 3.9802199094790907`*^9},
  311. 3.980219962691937*^9, {3.980219998174837*^9, 3.9802200191940937`*^9}, {
  312. 3.980220197643147*^9, 3.980220214115034*^9}, 3.980220363622348*^9, {
  313. 3.98022042632763*^9, 3.9802204383576603`*^9}, 3.980220547299224*^9, {
  314. 3.980220712553927*^9, 3.9802207272890863`*^9}, {3.980221066313427*^9,
  315. 3.980221073167602*^9}, 3.980221290310155*^9},
  316. CellLabel->"Out[49]=",ExpressionUUID->"2d1c80cf-dfd3-4a34-8f1d-5ca8d4f13801"]
  317. }, Open ]],
  318. Cell[CellGroupData[{
  319. Cell[BoxData[
  320. RowBox[{
  321. RowBox[{"(*", " ", "Hessian", "*)"}], "\[IndentingNewLine]",
  322. RowBox[{
  323. RowBox[{
  324. RowBox[{
  325. RowBox[{"HCost", "[",
  326. RowBox[{"i_", ",", "j_", ",", "p"}], "]"}], ":=",
  327. RowBox[{"Module", "[",
  328. RowBox[{
  329. RowBox[{"{",
  330. RowBox[{"u", ",", "v", ",", "k", ",", "F", ",", "G"}], "}"}], ",",
  331. "\[IndentingNewLine]",
  332. RowBox[{
  333. RowBox[{
  334. RowBox[{"F", "[", "v_", "]"}], ":=",
  335. RowBox[{"ND", "[",
  336. RowBox[{
  337. RowBox[{"Cost", "[",
  338. RowBox[{
  339. RowBox[{"Table", "[",
  340. RowBox[{
  341. RowBox[{"If", "[",
  342. RowBox[{
  343. RowBox[{"i", "==", "k"}], ",", "u", ",",
  344. RowBox[{"If", "[",
  345. RowBox[{
  346. RowBox[{"j", "==", "k"}], ",", "v", ",",
  347. RowBox[{"p", "[",
  348. RowBox[{"[", "k", "]"}], "]"}]}], "]"}]}], "]"}], ",",
  349. RowBox[{"{",
  350. RowBox[{"k", ",",
  351. RowBox[{"Length", "[", "p", "]"}]}], "}"}]}], "]"}], ",",
  352. "lam2", ",", "x", ",", "y"}], "]"}], ",", "u", ",",
  353. RowBox[{"p", "[",
  354. RowBox[{"[", "i", "]"}], "]"}], ",",
  355. RowBox[{"Terms", "->", "10"}]}], "]"}]}], ";",
  356. "\[IndentingNewLine]",
  357. RowBox[{"G", ":=",
  358. RowBox[{"ND", "[",
  359. RowBox[{
  360. RowBox[{"Cost", "[",
  361. RowBox[{
  362. RowBox[{"Table", "[",
  363. RowBox[{
  364. RowBox[{"If", "[",
  365. RowBox[{
  366. RowBox[{"i", "==", "k"}], ",", "u", ",",
  367. RowBox[{"p", "[",
  368. RowBox[{"[", "k", "]"}], "]"}]}], "]"}], ",",
  369. RowBox[{"{",
  370. RowBox[{"k", ",",
  371. RowBox[{"Length", "[", "p", "]"}]}], "}"}]}], "]"}], ",",
  372. "lam2", ",", "x", ",", "y"}], "]"}], ",",
  373. RowBox[{"{",
  374. RowBox[{"u", ",", "2"}], "}"}], ",",
  375. RowBox[{"p", "[",
  376. RowBox[{"[", "i", "]"}], "]"}], ",",
  377. RowBox[{"Terms", "->", "10"}]}], "]"}]}], ";",
  378. "\[IndentingNewLine]", "\[IndentingNewLine]",
  379. RowBox[{"If", "[",
  380. RowBox[{
  381. RowBox[{"i", "!=", "j"}], ",", "\[IndentingNewLine]",
  382. RowBox[{"ND", "[",
  383. RowBox[{
  384. RowBox[{"F", "[", "v", "]"}], ",", "v", ",",
  385. RowBox[{"p", "[",
  386. RowBox[{"[", "j", "]"}], "]"}]}], "]"}], ",",
  387. "\[IndentingNewLine]", "G"}], "]"}]}]}], "\[IndentingNewLine]",
  388. "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]",
  389. RowBox[{"H0", "=",
  390. RowBox[{"Table", "[",
  391. RowBox[{
  392. RowBox[{"HCost", "[",
  393. RowBox[{"i", ",", "j", ",", "p"}], "]"}], ",",
  394. RowBox[{"{",
  395. RowBox[{"i", ",",
  396. RowBox[{"Length", "[", "p", "]"}]}], "}"}], ",",
  397. RowBox[{"{",
  398. RowBox[{"j", ",",
  399. RowBox[{"Length", "[", "p", "]"}]}], "}"}]}], "]"}]}]}]}]], "Input",
  400. CellChangeTimes->{{3.980220845242152*^9, 3.9802210388102617`*^9}, {
  401. 3.980221083420125*^9, 3.980221210743389*^9}, {3.9802212959394293`*^9,
  402. 3.980221347003302*^9}, {3.9802214368899813`*^9, 3.980221498114513*^9}, {
  403. 3.980221552212894*^9, 3.980221718470955*^9}, {3.980221751831498*^9,
  404. 3.980221754488792*^9}, {3.980222174396463*^9, 3.9802222588377943`*^9}, {
  405. 3.9802223438606653`*^9,
  406. 3.9802223486758127`*^9}},ExpressionUUID->"db853e79-d0e4-4a86-8783-\
  407. 98f6bc5933c4"],
  408. Cell[BoxData[
  409. RowBox[{"{",
  410. RowBox[{
  411. RowBox[{"{",
  412. RowBox[{"0.7673411749127825`", ",",
  413. RowBox[{"-", "0.00004960801306647878`"}], ",", "0.889749135171745`", ",",
  414. "3.3212700921235605`"}], "}"}], ",",
  415. RowBox[{"{",
  416. RowBox[{
  417. RowBox[{"-", "0.0000496078733072483`"}], ",", "0.0004804061483556116`", ",",
  418. RowBox[{"-", "0.0000624478957252519`"}], ",",
  419. RowBox[{"-", "0.00022472631280071956`"}]}], "}"}], ",",
  420. RowBox[{"{",
  421. RowBox[{"0.8897491344529453`", ",",
  422. RowBox[{"-", "0.00006244763646673682`"}], ",", "1.2193302465332434`", ",",
  423. "4.2116021632604665`"}], "}"}], ",",
  424. RowBox[{"{",
  425. RowBox[{"3.3212689431121136`", ",",
  426. RowBox[{"-", "0.0002247255362663118`"}], ",", "4.211598490108457`", ",",
  427. "15.106151994325286`"}], "}"}]}], "}"}]], "Output",
  428. CellChangeTimes->{3.980221740709745*^9, 3.9802217766213427`*^9,
  429. 3.9802222890883713`*^9},
  430. CellLabel->"Out[56]=",ExpressionUUID->"9ac024a3-d751-44de-bc53-6ad3de884f93"]
  431. }, Open ]],
  432. Cell[CellGroupData[{
  433. Cell[BoxData[
  434. RowBox[{"MatrixForm", "[", "H0", "]"}]], "Input",
  435. CellChangeTimes->{{3.980221756962586*^9, 3.980221761796362*^9}, {
  436. 3.9802218237372227`*^9, 3.98022182432813*^9}},
  437. CellLabel->"In[57]:=",ExpressionUUID->"c25363e3-6dd7-423a-81cd-c2c937573e5b"],
  438. Cell[BoxData[
  439. TagBox[
  440. RowBox[{"(", "\[NoBreak]", GridBox[{
  441. {"0.7673411749127825`",
  442. RowBox[{"-", "0.00004960801306647878`"}], "0.889749135171745`",
  443. "3.3212700921235605`"},
  444. {
  445. RowBox[{"-", "0.0000496078733072483`"}], "0.0004804061483556116`",
  446. RowBox[{"-", "0.0000624478957252519`"}],
  447. RowBox[{"-", "0.00022472631280071956`"}]},
  448. {"0.8897491344529453`",
  449. RowBox[{"-", "0.00006244763646673682`"}], "1.2193302465332434`",
  450. "4.2116021632604665`"},
  451. {"3.3212689431121136`",
  452. RowBox[{"-", "0.0002247255362663118`"}], "4.211598490108457`",
  453. "15.106151994325286`"}
  454. },
  455. GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
  456. GridBoxSpacings->{"Columns" -> {
  457. Offset[0.27999999999999997`], {
  458. Offset[0.7]},
  459. Offset[0.27999999999999997`]}, "Rows" -> {
  460. Offset[0.2], {
  461. Offset[0.4]},
  462. Offset[0.2]}}], "\[NoBreak]", ")"}],
  463. Function[BoxForm`e$,
  464. MatrixForm[BoxForm`e$]]]], "Output",
  465. CellChangeTimes->{3.980221824708803*^9, 3.9802222891345053`*^9},
  466. CellLabel->
  467. "Out[57]//MatrixForm=",ExpressionUUID->"60a8e5e9-338f-4169-8f24-\
  468. 577a50a6f32e"]
  469. }, Open ]],
  470. Cell[CellGroupData[{
  471. Cell[BoxData[
  472. RowBox[{"MatrixForm", "[",
  473. RowBox[{"Inverse", "[", "H0", "]"}], "]"}]], "Input",
  474. CellChangeTimes->{{3.980222302130584*^9, 3.980222304864068*^9}},
  475. CellLabel->"In[58]:=",ExpressionUUID->"3c1e775c-af2e-4c18-8894-85a24d299c82"],
  476. Cell[BoxData[
  477. TagBox[
  478. RowBox[{"(", "\[NoBreak]", GridBox[{
  479. {"124.2107378939491`", "0.008819362051593838`", "99.68227366780131`",
  480. RowBox[{"-", "55.10069583812897`"}]},
  481. {"0.008763138449467222`", "2081.5865173231978`",
  482. RowBox[{"-", "0.002461036440763724`"}], "0.029726128780833826`"},
  483. {"99.68361653826865`",
  484. RowBox[{"-", "0.002420312442278083`"}], "102.15456747369905`",
  485. RowBox[{"-", "50.39738859190163`"}]},
  486. {
  487. RowBox[{"-", "55.10103654542312`"}], "0.029702306550748403`",
  488. RowBox[{"-", "50.39706092462403`"}], "26.23155138113158`"}
  489. },
  490. GridBoxAlignment->{"Columns" -> {{Center}}, "Rows" -> {{Baseline}}},
  491. GridBoxSpacings->{"Columns" -> {
  492. Offset[0.27999999999999997`], {
  493. Offset[0.7]},
  494. Offset[0.27999999999999997`]}, "Rows" -> {
  495. Offset[0.2], {
  496. Offset[0.4]},
  497. Offset[0.2]}}], "\[NoBreak]", ")"}],
  498. Function[BoxForm`e$,
  499. MatrixForm[BoxForm`e$]]]], "Output",
  500. CellChangeTimes->{3.98022230519285*^9},
  501. CellLabel->
  502. "Out[58]//MatrixForm=",ExpressionUUID->"635785cc-da30-4ada-b0a8-\
  503. 311ff9635453"]
  504. }, Open ]]
  505. },
  506. WindowSize->{1366.5, 683.25},
  507. WindowMargins->{{7.5, Automatic}, {Automatic, 24}},
  508. FrontEndVersion->"14.3 for Linux x86 (64-bit) (July 8, 2025)",
  509. StyleDefinitions->"Default.nb",
  510. ExpressionUUID->"9ea52935-3f71-45ad-8b9c-8ebfe3a2f1d5"
  511. ]
  512. (* End of Notebook Content *)
  513. (* Internal cache information *)
  514. (*CellTagsOutline
  515. CellTagsIndex->{}
  516. *)
  517. (*CellTagsIndex
  518. CellTagsIndex->{}
  519. *)
  520. (*NotebookFileOutline
  521. Notebook[{
  522. Cell[554, 20, 3290, 81, 413, "Input",ExpressionUUID->"db312a24-878f-40c8-962f-6aedbdf27fe4"],
  523. Cell[CellGroupData[{
  524. Cell[3869, 105, 3458, 67, 258, "Input",ExpressionUUID->"f22ff9ef-193c-434b-91da-e9e8b3175259"],
  525. Cell[7330, 174, 2011, 34, 97, "Output",ExpressionUUID->"a7f74a5e-642c-4b21-9dc6-dc4532fcd2dd"],
  526. Cell[9344, 210, 799, 12, 34, "Output",ExpressionUUID->"6fe63fdd-9529-4ff3-95a7-2b315610cc0a"],
  527. Cell[10146, 224, 354, 7, 34, "Output",ExpressionUUID->"9174505c-bb9d-4cfc-a204-c6c464fab952"],
  528. Cell[10503, 233, 196, 3, 60, "Output",ExpressionUUID->"dfb9c680-45f0-495e-bc68-7c102a014c4a"]
  529. }, Open ]],
  530. Cell[CellGroupData[{
  531. Cell[10736, 241, 250, 4, 30, "Input",ExpressionUUID->"73502887-6057-4d13-881a-8932ae266804"],
  532. Cell[10989, 247, 193, 2, 33, "Output",ExpressionUUID->"603f6210-ea83-425d-9d61-d60dffe5c701"]
  533. }, Open ]],
  534. Cell[11197, 252, 230, 3, 30, "Input",ExpressionUUID->"417b4445-9108-40f3-a80b-fda472fd9d54"],
  535. Cell[CellGroupData[{
  536. Cell[11452, 259, 150, 2, 29, "Input",ExpressionUUID->"3ca07280-6eb4-41d4-8ab2-dfe9bbf7b8be"],
  537. Cell[11605, 263, 331, 7, 34, "Output",ExpressionUUID->"029d324b-6436-44a3-8803-14c8381b5896"]
  538. }, Open ]],
  539. Cell[CellGroupData[{
  540. Cell[11973, 275, 1869, 46, 73, "Input",ExpressionUUID->"b0ded771-dccd-45f6-a46c-9b2ff466801f"],
  541. Cell[13845, 323, 723, 12, 45, "Output",ExpressionUUID->"2d1c80cf-dfd3-4a34-8f1d-5ca8d4f13801"]
  542. }, Open ]],
  543. Cell[CellGroupData[{
  544. Cell[14605, 340, 3534, 88, 247, "Input",ExpressionUUID->"db853e79-d0e4-4a86-8783-98f6bc5933c4"],
  545. Cell[18142, 430, 995, 22, 57, "Output",ExpressionUUID->"9ac024a3-d751-44de-bc53-6ad3de884f93"]
  546. }, Open ]],
  547. Cell[CellGroupData[{
  548. Cell[19174, 457, 259, 4, 30, "Input",ExpressionUUID->"c25363e3-6dd7-423a-81cd-c2c937573e5b"],
  549. Cell[19436, 463, 1181, 30, 111, "Output",ExpressionUUID->"60a8e5e9-338f-4169-8f24-577a50a6f32e"]
  550. }, Open ]],
  551. Cell[CellGroupData[{
  552. Cell[20654, 498, 243, 4, 30, "Input",ExpressionUUID->"3c1e775c-af2e-4c18-8894-85a24d299c82"],
  553. Cell[20900, 504, 1117, 27, 111, "Output",ExpressionUUID->"635785cc-da30-4ada-b0a8-311ff9635453"]
  554. }, Open ]]
  555. }
  556. ]
  557. *)