{"id":1440,"date":"2022-04-14T10:20:36","date_gmt":"2022-04-14T17:20:36","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1440"},"modified":"2022-04-14T10:21:59","modified_gmt":"2022-04-14T17:21:59","slug":"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-3-2","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2022\/04\/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-3-2\/","title":{"rendered":"#277 Plot in R"},"content":{"rendered":"<p>#277 Plot in R<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\npng(file=&quot;D:\/projects\/wordpress\/ex277\/ex277.png&quot;,width=600, height=350)\r\nf=function(x){x^2*sin(x)}\r\ncurve(f,-5,5)\r\ndev.off()\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\/04\/ex277.png?resize=600%2C350&#038;ssl=1\" alt=\"\" width=\"600\" height=\"350\" class=\"alignnone size-full wp-image-1441\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex277.png 600w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex277-480x280.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 600px, 100vw\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#277 Plot in R png(file=&quot;D:\/projects\/wordpress\/ex277\/ex277.png&quot;,width=600, height=350) f=function(x){x^2*sin(x)} curve(f,-5,5) dev.off()<\/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":[29],"tags":[],"class_list":["post-1440","post","type-post","status-publish","format-standard","hentry","category-r"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-ne","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1437,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/04\/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-3\/","url_meta":{"origin":1440,"position":0},"title":"#276 Plot in R","author":"gantovnik","date":"2022-04-14","format":false,"excerpt":"#276 Plot in R [code language=\"python\"] png(file=\"D:\/projects\/wordpress\/ex276\/ex276.png\",width=600, height=350) f=function(x){x^3-3*x^2-9*x+2} curve(f,-4,6,lwd=2,col=\"red\") grid(NULL,NULL,col=\"black\") dev.off() [\/code]","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/gantovnik.com\/bio-tips\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/04\/ex276.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":82,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/plot-with-an-inset\/","url_meta":{"origin":1440,"position":1},"title":"#12: Plot with an inset in python","author":"gantovnik","date":"2018-12-29","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex12') os.getcwd() fig = plt.figure(figsize=(10,8)) def f(x): return 1\/(1+x**2) + 0.1\/(1+((3-x)\/0.1)**2) def plot_and_format_axes(ax,x,f,fontsize): ax.plot(x,f(x),linewidth=2) ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(5)) ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(4)) ax.set_xlabel(r\"$x$\",fontsize=fontsize) ax.set_ylabel(r\"$f(x)$\",fontsize=fontsize) ax=fig.add_axes([0.1,0.15,0.8,0.8],facecolor=\"#f5f5f5\") x = np.linspace(-4,14,1000) plot_and_format_axes(ax,x,f,18) plt.title('Plot with inset') x0,x1=2.5,3.5 ax.axvline(x0,ymax=0.3,color=\"grey\",linestyle=\":\") ax.axvline(x1,ymax=0.3,color=\"grey\",linestyle=\":\") ax_insert=fig.add_axes([0.5,0.5,0.38,0.42],facecolor='none') x=np.linspace(x0,x1,1000) plot_and_format_axes(ax_insert,x,f,14) plt.savefig(\"example12.png\", dpi=100)\u2026","rel":"","context":"In &quot;matplotlib&quot;","block_context":{"text":"matplotlib","link":"https:\/\/gantovnik.com\/bio-tips\/category\/matplotlib\/"},"img":{"alt_text":"example12","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example12.png?resize=525%2C300 1.5x"},"classes":[]},{"id":93,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/plots-of-nonlinear-functions\/","url_meta":{"origin":1440,"position":2},"title":"Plots of nonlinear functions","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np os.chdir('\/home\/vg\/Downloads\/projects\/ex15') os.getcwd() #define model parameters x=np.linspace(-2,2,1000) #examples of nonlinear functions f1=x**2-x-1 f2=x**3-3*np.sin(x) f3=np.exp(x)-2 f4=1-x**2+np.sin(50\/(1+x**2)) fig,axes=plt.subplots(1,4,figsize=(12,3),sharey=True) for n,f in enumerate([f1,f2,f3,f4]): axes[n].plot(x,f,lw=1.5) axes[n].axhline(0,ls=':',color='k') axes[n].set_ylim(-5,5) axes[n].set_xticks([-2,-1,0,1,2]) axes[n].set_xlabel(r'$x$',fontsize=18) axes[0].set_ylabel(r'$f(x)$',fontsize=18) titles=[r'$f(x)=x^2-x-1$',r'$f(x)=x^3-3\\sin(x)$',r'$f(x)=\\exp(x)-2$', r'$f(x)=\\sin\\left(50\/(1+x^2)\\right)+1-x^2$'] for n,title in enumerate(titles): axes[n].set_title(title) plt.savefig(\"example15.png\", dpi=100) plt.show() plt.close()","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example15","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example15.png?resize=525%2C300 1.5x"},"classes":[]},{"id":117,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/optimization-with-contraints\/","url_meta":{"origin":1440,"position":3},"title":"#22: Optimization with constraints using SciPy in python","author":"gantovnik","date":"2019-01-03","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np from scipy.optimize import minimize os.chdir(r'D:\\data\\scripts\\web1\\ex22') os.getcwd() def f(X): return (X[0]-1)2 + (X[1]-1)2 def g(X): return X[1]-1.75-(X[0]-0.75)**4 def func_X_Y_to_XY(f, X, Y): s = np.shape(X) return f(np.vstack([X.ravel(), Y.ravel()])).reshape(*s) x_opt=minimize(f,(0,0),method='BFGS').x print(x_opt) constraints = [dict(type='ineq', fun=g)] x_cons_opt = minimize(f, (0, 0), method='SLSQP',\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\/2019\/01\/example22.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example22.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example22.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":154,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/inexact-solutions-to-odes\/","url_meta":{"origin":1440,"position":4},"title":"Inexact solutions to ODEs","author":"gantovnik","date":"2019-01-08","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import sympy from IPython.display import display sympy.init_printing() mpl.rcParams['text.usetex'] = True import sympy os.chdir(r'D:\\projects\\wordpress\\ex33') os.getcwd() def plot_direction_field(x, y_x, f_xy, x_lim=(-5, 5), y_lim=(-5, 5), ax=None): f_np = sympy.lambdify((x, y_x), f_xy, 'numpy') x_vec = np.linspace(x_lim[0], x_lim[1], 20) y_vec\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example33","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example33.png?resize=525%2C300 1.5x"},"classes":[]},{"id":166,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/lotka-volterra-equations-for-predator-pray-populations\/","url_meta":{"origin":1440,"position":5},"title":"Lotka-Volterra equations for predator\/pray populations","author":"gantovnik","date":"2019-01-09","format":false,"excerpt":"import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate os.chdir(r'D:\\projects\\wordpress\\ex34') os.getcwd() a, b, c, d = 0.4, 0.002, 0.001, 0.7 def f(xy, t): x, y = xy return [a * x - b * x * y, c * x * y - d *\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example34","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example34.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1440","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=1440"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1440\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}