{"id":171,"date":"2014-10-30T10:10:15","date_gmt":"2014-10-30T15:10:15","guid":{"rendered":"http:\/\/charles-oneill.com\/blog\/?p=171"},"modified":"2014-10-30T10:12:59","modified_gmt":"2014-10-30T15:12:59","slug":"consulting-spline-roots","status":"publish","type":"post","link":"https:\/\/charles-oneill.com\/blog\/consulting-spline-roots\/","title":{"rendered":"Consulting: Spline Roots"},"content":{"rendered":"<p>A need exists for determining a solution to the following cubic spline \\(\\) $$f(x)=a_{i}\\left(x-x_{i}\\right)^{3}+b_{i}\\left(x-x_{i}\\right)^{3}+c_{i}\\left(x-x_{i}\\right)^{3}+d_{i}=V$$<\/p>\n<p>The full consulting report is available at <a href=\"http:\/\/charles-oneill.com\/blog\/wp-content\/uploads\/2014\/10\/SplineRoots.pdf\">SplineRoots<\/a><\/p>\n<p><!--more--><\/p>\n<p style=\"text-align: center;\"><strong>Part I: Analytical Methods<\/strong><\/p>\n<p>One-step analytical solutions exist for a cubic polynomial (See <a title=\"Cubic Formula\" href=\"http:\/\/mathworld.wolfram.com\/CubicFormula.html\">http:\/\/mathworld.wolfram.com\/CubicFormula.html<\/a>). The history behind this solution is quite interesting and only a few hundred years old. Given an arbitrary cubic polynomial, $$f(x)=a_{i}\\left(x-x_{i}\\right)^{3}+b_{i}\\left(x-x_{i}\\right)^{3}+c_{i}\\left(x-x_{i}\\right)^{3}+d_{i}$$<br \/>\nthe polynomial is non-dimensionalized by \\[a_{i}\\]<br \/>\nto give $$F(x)=\\left(x-x_{i}\\right)^{3}+a_{2}\\left(x-x_{i}\\right)^{3}+a_{1}\\left(x-x_{i}\\right)^{3}+a_{0}$$<br \/>\nThree intermediate terms are calculated $$Q=\\frac{3a_{1}-a_{2}^{2}}{9}$$<br \/>\n$$R=\\frac{9a_{2}a_{1}-27a_{0}-2a_{2}^{3}}{54}$$<br \/>\n$$\\theta=\\arccos\\left(\\frac{R}{\\sqrt{-Q^{3}}}\\right)$$<br \/>\nThe real solutions are $$z_{1}=2\\sqrt{-Q}\\,\\cos\\left(\\frac{\\theta}{3}\\right)-\\frac{a_{2}}{3}$$<br \/>\n$$z_{2}=2\\sqrt{-Q}\\,\\cos\\left(\\frac{\\theta+2\\pi}{3}\\right)-\\frac{a_{2}}{3}$$<br \/>\n$$z_{3}=2\\sqrt{-Q}\\,\\cos\\left(\\frac{\\theta+4\\pi}{3}\\right)-\\frac{a_{2}}{3}$$<br \/>\nThe roots are selected from the z<br \/>\nvalue calculated above $$x=\\left\\{ z_{1},z_{2},z_{3}\\right\\} $$<\/p>\n<p>There are several issues associated with this method.<br \/>\n\u2022 Out of Range: Intermediate terms may not be real if the search value is outside the range of possible function values f(x)<br \/>\n\u2022 Picking the correct solution: multiple solutions may exist, you must ensure the calculated x\u00a0 lies in the correct domain.<\/p>\n<p style=\"text-align: center;\"><strong>Part II: Numerical Methods<\/strong><\/p>\n<p>\u2022 Suggested to avoid Newton-Raphson iterative root finding since division by a near zero derivative causes problems. N-R is however excellent for polishing a root after a prior routine gets \u201cclose\u201d.<\/p>\n<p>\u2022 Simple bisection would likely be the most robust especially if a human can identify a known upper and lower bound.<\/p>\n<p><strong>Bisection Method<\/strong><\/p>\n<p>See the attached pdf (<a href=\"http:\/\/charles-oneill.com\/blog\/wp-content\/uploads\/2014\/10\/SplineRoots.pdf\">SplineRoots<\/a>) for an explanation and examples of bisection root finding.<\/p>\n<p><strong>Newton-Raphson Root Finding<\/strong><\/p>\n<p>The definition of N-R for a given function f\u00a0 and desired value V<br \/>\nis $$x_{new}=x_{old}-\\frac{f(x_{old})-V}{f^{\\prime}(x_{old})}$$<br \/>\nwhere$$\\hat{x}=x-x_{i}$$<br \/>\n$$ f(x)=a_{i}\\hat{x}^{3}+b_{i}\\hat{x}^{2}+c_{i}\\hat{x}+d_{i}<br \/>\nf^{\\prime}(x)=3a_{i}\\hat{x}^{2}+2b_{i}\\hat{x}+c_{i}$$<br \/>\nSee the attached pdf (<a href=\"http:\/\/charles-oneill.com\/blog\/wp-content\/uploads\/2014\/10\/SplineRoots.pdf\">SplineRoots<\/a>) for an explanation and examples of NR root finding.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A need exists for determining a solution to the following cubic spline $$f(x)=a_{i}\\left(x-x_{i}\\right)^{3}+b_{i}\\left(x-x_{i}\\right)^{3}+c_{i}\\left(x-x_{i}\\right)^{3}+d_{i}=V$$ The full consulting report is available at SplineRoots<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/posts\/171"}],"collection":[{"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":9,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/posts\/171\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charles-oneill.com\/blog\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}