Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mikexcohen authored Nov 21, 2023
1 parent 373d224 commit 485d8ac
Show file tree
Hide file tree
Showing 51 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions artFromTrig/mathWithPython_artFromTrig_astroid.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Art from trigonometry\n","# VIDEO: Astroid radial curve\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/artFromTrig/mathWithPython_artFromTrig_astroid.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"Oqc1UXEpJI0D","executionInfo":{"status":"ok","timestamp":1698829876804,"user_tz":-480,"elapsed":6,"user":{"displayName":"Mike X Cohen","userId":"13901636194183843661"}}},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fBCgo5FPJI0F"},"outputs":[],"source":["t = np.linspace(-6*np.pi,6*np.pi,1000)\n","\n","a = t\n","\n","x = a * np.cos(t)**3\n","y = a * np.sin(t)**3\n","\n","plt.plot(x,y,'m',linewidth=3)\n","plt.axis('off')\n","plt.axis('square')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"JEfVrIeZJjt0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"qqM2WYD6JI0F"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"QmqE2cphJI0F"},"outputs":[],"source":["fig,ax = plt.subplots(3,3,figsize=(10,6))\n","row, col = np.indices((3, 3))\n","\n","for i in range(9):\n"," x = t**i * np.cos(t)**3\n"," y = t**i * np.sin(t)**3\n","\n"," r = row.ravel()[i]\n"," c = col.ravel()[i]\n","\n"," ax[r,c].plot(x,y,'k')\n"," ax[r,c].axis('off')\n"," ax[r,c].axis('square')\n"," ax[r,c].set_xlabel('a=t$^%s$'%i)\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"vB1GgGQKJSGt"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions artFromTrig/mathWithPython_artFromTrig_logSpiral.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Art from trigonometry\n","# VIDEO: Logarithmic spiral\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/artFromTrig/mathWithPython_artFromTrig_logSpiral.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oqc1UXEpJI0D"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TYqc7YxZJI0I"},"outputs":[],"source":["t = np.linspace(0,10*np.pi,1000)\n","\n","k = -3\n","\n","x = np.cos(t) * np.exp(t/k)\n","y = np.sin(t) * np.exp(t/k)\n","\n","plt.plot(x,y,'m',linewidth=3)\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"YZWvHYA5KVxv"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"EiQd7Hw_JI0I"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cv3pcNggJI0I"},"outputs":[],"source":["N = 150\n","\n","# eds = exponential decays\n","eds = np.linspace(-6,-2,N)\n","\n","for i in range(N):\n"," x = np.cos(t) * np.exp(t/eds[i])\n"," y = np.sin(t) * np.exp(t/eds[i])\n"," plt.plot(x,y,color=[i/N,0,i/N])\n","\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"vB1GgGQKJSGt"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions artFromTrig/mathWithPython_artFromTrig_logisticMap.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Art from trigonometry\n","# VIDEO: Logistic map\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/artFromTrig/mathWithPython_artFromTrig_logisticMap.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oqc1UXEpJI0D"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"06g3AUYKJI0I"},"outputs":[],"source":["plt.figure(figsize=(10,8))\n","\n","N = 500\n","rs = np.linspace(1,4,1000)\n","endcap = np.arange(round(N*.9),N)\n","\n","for ri in range(len(rs)):\n"," x = np.ones(N)/2\n","\n"," for n in range(N-1):\n"," x[n+1] = rs[ri]*x[n]*(1-x[n]) + .2*np.sin(2*np.pi*x[n])**2\n","\n"," u = np.unique(x[endcap])\n"," r = rs[ri]*np.ones(len(u))\n"," plt.plot(r,u,'.',markersize=1,color=[(np.sin(ri/len(rs)/2)+1)/2,1-ri/len(rs),.5])\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"vB1GgGQKJSGt"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions artFromTrig/mathWithPython_artFromTrig_rose.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Art from trigonometry\n","# VIDEO: Rose curves\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/artFromTrig/mathWithPython_artFromTrig_rose.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oqc1UXEpJI0D"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"POXEiJtsJI0G"},"outputs":[],"source":["k = 2\n","\n","# If k is an integer, the curve will be rose-shaped with\n","# 2k petals if k is even, and\n","# k petals if k is odd.\n","\n","t = np.linspace(0,4*np.pi,1000)\n","\n","x = np.cos(k*t) * np.cos(t)\n","y = np.cos(k*t) * np.sin(t)\n","\n","plt.plot(x,y,'m',linewidth=3)\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"5drmncR0J2fw"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"HfoLV-XtJI0G"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3FLUmirhJI0H"},"outputs":[],"source":["fig,ax = plt.subplots(3,3,figsize=(10,6))\n","row, col = np.indices((3, 3))\n","\n","kk = np.linspace(0,1.5,9)\n","\n","for i in range(9):\n","\n"," k = kk[i]#i/2\n","\n"," x = np.cos(k*t) * np.cos(t)\n"," y = np.cos(k*t) * np.sin(t)\n","\n"," r = row.ravel()[i]\n"," c = col.ravel()[i]\n","\n"," ax[r,c].plot(x,y,'k')\n"," ax[r,c].axis('off')\n"," ax[r,c].axis('square')\n"," ax[r,c].set_title('k=%s'%k)\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"vB1GgGQKJSGt"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions artFromTrig/mathWithPython_artFromTrig_squircle.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Art from trigonometry\n","# VIDEO: Squircle\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/artFromTrig/mathWithPython_artFromTrig_squircle.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oqc1UXEpJI0D"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TJe60VgvJI0H"},"outputs":[],"source":["x = np.linspace(-1,1,2001)\n","\n","y = ( 1 - x**4 )**(1/4)\n","\n","plt.plot(x,y,'k',linewidth=3)\n","plt.plot(x,-y,'k',linewidth=3)\n","\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"vB1GgGQKJSGt"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.3"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions calculus/mathWithPython_calc_BUGHUNT.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Calculus\n","# VIDEO: Calculus BUG HUNT! (This is the file with bugs to find/fix.)\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/calculus/mathWithPython_calc_BUGHUNT.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":1,"metadata":{"id":"KFfqVGpviYuH","executionInfo":{"status":"ok","timestamp":1698836437423,"user_tz":-480,"elapsed":1089,"user":{"displayName":"Mike X Cohen","userId":"13901636194183843661"}}},"outputs":[],"source":["import sympy as sym\n","import numpy as np\n","import matplotlib.pyplot as plt\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7eN_TTBviYuN"},"outputs":[],"source":["# evaluate a function in a range\n","from sympy.abc import x\n","\n","fx = (4*x**3 + 2*x**2 - x) / (-4*x**4 + 2*x**2)\n","\n","xrange = np.linspace(-2,2,200)\n","fxx = sym.lambdify(x,fx)\n","\n","plt.plot(xrange,fxx)\n","plt.ylim([-20,20])\n","plt.xlim(xrange[[0,-1]])\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Ol1zNug9iYuN"},"outputs":[],"source":["# compute the limit\n","x = sym.symbols('x')\n","fx = 1/(x+3)\n","\n","lim_pnt = -3\n","lim = sym.limit(x,fx,lim_pnt,dir='+')\n","\n","display(Math('\\\\lim_{x\\\\to %g^+} %s = %g' %(lim_pnt,sym.latex(fx),sym.latex(lim))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"P7o21pxuiYuO"},"outputs":[],"source":["# piece-wise function\n","from sympy.abc import x\n","\n","piece1 = x**2\n","piece2 = 4*sym.exp(-x**2)\n","\n","# put them together with conditions\n","fx = sym.Piecewise( piece1,x<0 , [piece2,x>=0) )\n","\n","# evaluate the function in a range\n","xx = np.linspace(-2,2,1000)\n","fxx = sym.lambdify(x,fx)\n","\n","# show it in a plot\n","plt.plot(xx,fxx(x),'k')\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_WyVkwakiYuP"},"outputs":[],"source":["# show the first and second derivatives of sin(x)\n","x = np.linspace(-2*np.pi,2*np.pi,200)\n","dt = np.diff(x[0:2])\n","\n","y = np.sin(x)\n","dy = np.diff(y)\n","ddy = np.diff(y,2)\n","\n","plt.plot(x,y,label='y')\n","plt.plot(x,dy,'--',label='dy',alpha=.6)\n","plt.plot(x,ddy,':',label='d$^2$y',alpha=.3)\n","\n","plt.legend(framealpha=1)\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0KAOneROiYuP"},"outputs":[],"source":["# Compute critical points using sympy\n","\n","x = sym.symbols('x')\n","fx = x**2 * sym.exp(-x**2)\n","\n","# derivative in sympy, solve\n","dfx = sym.diff(fx,x)\n","critpoints = sym.solve(fx)\n","print('The critical points are: ' + str(critpoints))\n","\n","\n","# plot the function derivative and its critical points\n","y = sym.lambdify(x,dfx)\n","xx = np.linspace(-3,3,200)\n","\n","plt.plot(xx,y(xx))\n","plt.plot([-3,3],[0,0],'k--')\n","plt.xlim([-3,3])\n","\n","for i in critpoints:\n"," plt.plot(i,0,'ro')\n","\n","plt.title('Function derivative')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"JGSMTOe4iYuQ"},"outputs":[],"source":["# Compute the area between two curves (not the same thing as Between Two Ferns)\n","from matplotlib.patches import Polygon\n","\n","\n","x = sym.symbols('x')\n","f1sym = sym.cos(x)\n","f2sym = x\n","\n","xx = np.linspace(0,np.pi/3,100)\n","f1 = np.cos(xx)\n","f2 = xx\n","\n","fintersect = np.argmin(abs(f1-f2))\n","\n","\n","traceX = np.concatenate((xx[0:fintersect],xx[fintersect:0:-1]))\n","traceY = np.concatenate((f1[0:fintersect],f2[fintersect:0:-1]))\n","\n","points = np.vstack((traceX,traceY)).T\n","p = Polygon(points,facecolor='k',alpha=.3)\n","\n","fig, ax = plt.subplots()\n","ax.add_patch(p)\n","\n","plt.plot(xx,f1, xx,f2)\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"pHw-iRMYildX"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.4"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0}
1 change: 1 addition & 0 deletions calculus/mathWithPython_calc_area.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions calculus/mathWithPython_calc_bugHunt_SOL.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 485d8ac

Please sign in to comment.