{"id":1570,"date":"2022-10-07T17:28:26","date_gmt":"2022-10-08T00:28:26","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1570"},"modified":"2022-10-07T17:28:26","modified_gmt":"2022-10-08T00:28:26","slug":"210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-3-2-2-3-2-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2022\/10\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-3-2-2-3-2-2\/","title":{"rendered":"#302 Pythagorean triples in python"},"content":{"rendered":"<p>Scatter plot of the legs (a, b) of the Pythagorean triples.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport matplotlib.pyplot as plt\r\nx=&#x5B;]\r\ny=&#x5B;]\r\nn=2 # power\r\npmax=10000 # number of points\r\nfor a in range(2,pmax):\r\n    for b in range(2,pmax):\r\n        c = (a**n + b**n)**(1\/n)\r\n        if( c - int(c) == 0 ):\r\n            x.append(a)\r\n            y.append(b)\r\n            print(&quot;a=&quot;,a,&quot; b=&quot;,b,&quot; c=&quot;,int(c))\r\n\r\nfig1, ax = plt.subplots()            \r\nfig1.set_size_inches(18.5, 10.5)\r\nax.set_box_aspect(1)            \r\nplt.scatter(x,y,s=1)   \r\nplt.savefig('ex302.png', dpi=72)\r\nplt.show()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/10\/ex302.png?resize=1080%2C613&#038;ssl=1\" alt=\"\" width=\"1080\" height=\"613\" class=\"alignnone size-full wp-image-1571\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/10\/ex302.png 1332w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/10\/ex302-1280x726.png 1280w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/10\/ex302-980x556.png 980w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/10\/ex302-480x272.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1332px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scatter plot of the legs (a, b) of the Pythagorean triples. import matplotlib.pyplot as plt x=&#x5B;] y=&#x5B;] n=2 # power pmax=10000 # number of points for a in range(2,pmax): for b in range(2,pmax): c = (a**n + b**n)**(1\/n) if( c &#8211; int(c) == 0 ): x.append(a) y.append(b) print(&quot;a=&quot;,a,&quot; b=&quot;,b,&quot; c=&quot;,int(c)) fig1, ax = plt.subplots() fig1.set_size_inches(18.5, [&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":"yes","_lmt_disable":"","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":[2],"tags":[],"class_list":["post-1570","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-pk","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1746,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1570,"position":0},"title":"#331 Interpolation with Newton&#8217;s polynomial using python","author":"gantovnik","date":"2023-01-04","format":false,"excerpt":"interpolation.py [code language=\"python\"] def interpolation(c,x,x0): # Evaluate Newton's polynomial at x0. # Degree of polynomial n = len(x) - 1 y0 = c[n] for k in range(1,n+1): y0 = c[n-k] + (x0 - x[n-k]) * y0 return y0 def coef(x,y): # Computes the coefficients of Newton's polynomial. # Number of\u2026","rel":"","context":"In &quot;interpolation&quot;","block_context":{"text":"interpolation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/interpolation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex331.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":220,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/2nd-order-runge-kutta-type-c\/","url_meta":{"origin":1570,"position":1},"title":"#46 2nd-order Runge-Kutta type C using python","author":"gantovnik","date":"2019-01-12","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex46') os.getcwd() #2nd-order Runge-Kutta methods with A=1\/3 (type C) # dy\/dx=exp(-2x)-2y # y(0)=0.1, interval x=[0,2], step size = h=0.2 def feval(funcName, *args): return eval(funcName)(*args) def RK2C(func, yinit, x_range, h): m = len(yinit) n = int((x_range[-1] - x_range[0])\/h) x = x_range[0]\u2026","rel":"","context":"In &quot;numerical&quot;","block_context":{"text":"numerical","link":"https:\/\/gantovnik.com\/bio-tips\/category\/numerical\/"},"img":{"alt_text":"example46","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example46.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example46.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example46.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1929,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/08\/379-joint-and-marginal-histograms-using-seaborn-library\/","url_meta":{"origin":1570,"position":2},"title":"#379 Joint and marginal histograms using seaborn library","author":"gantovnik","date":"2023-08-10","format":false,"excerpt":"[code language=\"python\"] #Joint and marginal histograms using seaborn library import matplotlib.pyplot as plt #conda install -c anaconda seaborn import seaborn as sns sns.set_theme(style=\"ticks\") def main(): # Load the planets dataset and initialize the figure planets = sns.load_dataset(\"planets\") g = sns.JointGrid(data=planets, x=\"year\", y=\"distance\", marginal_ticks=True) # Set a log scaling on the\u2026","rel":"","context":"In &quot;plot&quot;","block_context":{"text":"plot","link":"https:\/\/gantovnik.com\/bio-tips\/category\/plot\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/08\/ex379.png?resize=525%2C300&ssl=1 1.5x"},"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":1570,"position":3},"title":"#329 Golden section method using python","author":"gantovnik","date":"2023-01-03","format":false,"excerpt":"golden.py [code language=\"python\"] import math as mt def golden(f,a,b,tol=1.0e-10): # Golden section method for determining x # that minimizes the scalar function f(x). # The minimum must be bracketed in (a,b). c1 = (mt.sqrt(5.0)-1.0)\/2.0 c2 = 1.0 - c1 nIt = int(mt.ceil(mt.log(tol\/abs(a-b))\/mt.log(c1))) # first step x1 = c1*a + c2*b\u2026","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":217,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/2nd-order-runge-kutta-type-b\/","url_meta":{"origin":1570,"position":4},"title":"#45  2nd-order Runge-Kutta type B using python","author":"gantovnik","date":"2019-01-12","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt os.chdir(r'D:\\projects\\wordpress\\ex45') os.getcwd() #2nd-order Runge-Kutta methods with A=0 (type B) # dy\/dx=exp(-2x)-2y # y(0)=0.1, interval x=[0,2], step size = h=0.2 def feval(funcName, *args): return eval(funcName)(*args) def RK2B(func, yinit, x_range, h): m = len(yinit) n = int((x_range[-1] - x_range[0])\/h) x = x_range[0]\u2026","rel":"","context":"In &quot;differential equations&quot;","block_context":{"text":"differential equations","link":"https:\/\/gantovnik.com\/bio-tips\/category\/differential-equations\/"},"img":{"alt_text":"example45","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example45.png?resize=525%2C300 1.5x"},"classes":[]},{"id":88,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/linear-least-square-fit\/","url_meta":{"origin":1570,"position":5},"title":"#14 Linear least square fit using python","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np import scipy.linalg as la os.chdir('\/home\/vg\/Downloads\/projects\/ex14') os.getcwd() #define model parameters x=np.linspace(-1,1,200) a,b,c=1,2,3 y_exact=a+b*x+c*x**2 #simulate noisy data m=200 X=1-2*np.random.rand(m) Y=a+b*X+c*X**2+np.random.randn(m) #linear least square fit A=np.vstack([X**0,X**1,X**2]) sol,r,rank,sv=la.lstsq(A.T,Y) y_fit=sol[0]+sol[1]*x+sol[2]*x**2 fig,ax=plt.subplots(figsize=(12,4)) ax.plot(X,Y,'go',alpha=0.5,label='simulated data') ax.plot(x,y_exact,'k',lw=2,label='true value $y=1+2x+3x^2$') ax.plot(x,y_fit,'b',lw=2,label='least square fit') #1st order polynomial A=np.vstack([X**n\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"example13","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example13-1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1570","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=1570"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1570\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}