{"id":10721,"date":"2026-01-10T05:13:04","date_gmt":"2026-01-10T13:13:04","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=10721"},"modified":"2026-01-10T05:13:07","modified_gmt":"2026-01-10T13:13:07","slug":"467-approximate-solution-of-a-boundary-value-problem-using-the-collocation-method-in-mathematica","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2026\/01\/467-approximate-solution-of-a-boundary-value-problem-using-the-collocation-method-in-mathematica\/","title":{"rendered":"#467 Approximate Solution of a Boundary Value Problem Using the Collocation Method in Mathematica"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2026\/01\/467-approximate-solution-of-a-boundary-value-problem-using-the-collocation-method-in-mathematica\/ex467-3\/\" rel=\"attachment wp-att-10724\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"alignnone size-full wp-image-10724\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2026\/01\/ex467-1.png?resize=750%2C515&#038;ssl=1\" alt=\"\" width=\"750\" height=\"515\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2026\/01\/ex467-1.png 750w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2026\/01\/ex467-1-480x330.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 750px, 100vw\" \/><\/a><\/p>\n<a href='https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2026\/01\/ex467.pdf' class='small-button smallblue' target=\"_blank\">Solution<\/a>\n<p>Mathematica source code:<\/p>\n<pre class=\"lang:matlab decode:true \">ClearAll[\"Global`*\"]\nyN = c1*(1 - x^2) + c2*x^2*(1 - x^2)\nD[yN[x], x]\nD[yN[x], {x, 2}]\nClear[yN]\nyN[x_] := c1*(1 - x^2) + c2*x^2*(1 - x^2)\nyNp = yN'[x];      (*first derivative*)\nyNpp = yN''[x];     (*second derivative*)\nSimplify \/@ {yN[x], yNp, yNpp}\nL[x_] := yNpp + (1 + x^2)*yN[x] + 1 \/\/ Simplify\nL1 = L[x = 0]\nL2 = L[x = 1\/2]\nsol = Solve[{L1 == 0, L2 == 0}, {c1, c2}][[1]];\n{c1, c2} \/. sol\n{c1, c2} \/. sol \/\/ N\nyNsub[x_] := yN[x] \/. sol\nplt = Plot[yNsub[x], {x, -1, 1}, PlotRange -&gt; All, \n  AxesLabel -&gt; {\"x\", \"y_N(x)\"}, \n  PlotLabel -&gt; \"Collocation solution y_N(x)\"]\nSetDirectory[$HomeDirectory]\nExport[FileNameJoin[{NotebookDirectory[], \"ex467.png\"}], plt, \n ImageResolution -&gt; 150]<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mathematica source code: ClearAll[&#8220;Global`*&#8221;] yN = c1*(1 &#8211; x^2) + c2*x^2*(1 &#8211; x^2) D[yN[x], x] D[yN[x], {x, 2}] Clear[yN] yN[x_] := c1*(1 &#8211; x^2) + c2*x^2*(1 &#8211; x^2) yNp = yN'[x]; (*first derivative*) yNpp = yN&#8221;[x]; (*second derivative*) Simplify \/@ {yN[x], yNp, yNpp} L[x_] := yNpp + (1 + x^2)*yN[x] + 1 \/\/ Simplify L1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"no","_lmt_disable":"no","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[111,56,331],"tags":[114,333,332],"class_list":["post-10721","post","type-post","status-publish","format-standard","hentry","category-differential-equations","category-math","category-mathematica","tag-differential-equation","tag-math","tag-mathematica"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-2MV","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1407,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/02\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":10721,"position":0},"title":"#269 Fitting noisy data with a linear equation using python","author":"gantovnik","date":"2022-02-22","format":false,"excerpt":"#269 Fitting noisy data with a linear equation using python","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex269.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex269.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex269.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1410,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/02\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":10721,"position":1},"title":"#270 Fitting noisy data with a Gaussian equation using python","author":"gantovnik","date":"2022-02-22","format":false,"excerpt":"#270 Fitting noisy data with a Gaussian equation using python","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex270.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex270.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/02\/ex270.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":926,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/06\/166-solution-of-a-differential-equation-using-bubnov-galerkin-method-with-sympy-package\/","url_meta":{"origin":10721,"position":2},"title":"#166 Solution of a differential equation using Bubnov-Galerkin method with Sympy package","author":"gantovnik","date":"2021-06-15","format":false,"excerpt":"#166 Solution of a differential equation using Bubnov-Galerkin method with Sympy package The problem and solution in this pdf file: ex166","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1738,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2-2-2\/","url_meta":{"origin":10721,"position":3},"title":"#329 Golden section method using python","author":"gantovnik","date":"2023-01-03","format":false,"excerpt":"golden.py ex329.py","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex329.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1742,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":10721,"position":4},"title":"#330 Gradient method using python","author":"gantovnik","date":"2023-01-03","format":false,"excerpt":"golden.py grad.py ex330.py","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex330.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":143,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/143\/","url_meta":{"origin":10721,"position":5},"title":"#30 Newton&#8217;s Law of Cooling","author":"gantovnik","date":"2019-01-06","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams['text.usetex'] = True import sympy from IPython.display import display sympy.init_printing() #%matplotlib inline #%config InlineBackend.figure_format='retina' os.chdir(r'D:\\projects\\wordpress\\ex30') os.getcwd() #Symbolic ODE solving with SymPy #Newton's law of cooling t, k, T0, Ta = sympy.symbols(\"t, k, T_0, T_a\") T =\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example30","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example30.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example30.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example30.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/10721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=10721"}],"version-history":[{"count":2,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/10721\/revisions"}],"predecessor-version":[{"id":10726,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/10721\/revisions\/10726"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=10721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=10721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=10721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}