├── linearAlgebra ├── einstein.jpg ├── mathWithPython_linalg_correlation.ipynb ├── mathWithPython_linalg_outerProduct.ipynb ├── mathWithPython_linalg_matrixVectMult.ipynb ├── mathWithPython_linalg_matrixMult.ipynb ├── mathWithPython_linalg_dotProduct.ipynb ├── mathWithPython_linalg_transpose.ipynb ├── mathWithPython_linalg_specialMatrices.ipynb ├── mathWithPython_linalg_inverse.ipynb └── mathWithPython_linalg_vectors.ipynb ├── README.md ├── probability ├── data.csv └── mathWithPython_prob_jointPDFs.ipynb ├── artFromTrig ├── mathWithPython_artFromTrig_squircle.ipynb ├── mathWithPython_artFromTrig_logisticMap.ipynb ├── mathWithPython_artFromTrig_logSpiral.ipynb ├── mathWithPython_artFromTrig_astroid.ipynb └── mathWithPython_artFromTrig_rose.ipynb ├── graphing ├── mathWithPython_graph_export.ipynb ├── mathWithPython_graph_coords2.ipynb ├── mathWithPython_graph_rational.ipynb ├── mathWithPython_graph_coords1.ipynb ├── mathWithPython_graph_polygon.ipynb ├── mathWithPython_graph_matrices.ipynb └── mathWithPython_graph_startStopLine.ipynb ├── algebra_1 ├── mathWithPython_algebra1_multTable.ipynb ├── mathWithPython_algebra1_slicing.ipynb ├── mathWithPython_algebra1_primeFactor.ipynb ├── mathWithPython_algebra1_inequalities.ipynb ├── mathWithPython_algebra1_factoringPolys.ipynb ├── mathWithPython_algebra1_BUGHUNT.ipynb ├── mathWithPython_algebra1_matrices.ipynb └── mathWithPython_algebra1_addPolys.ipynb ├── mathWithPython_harmonograph.ipynb ├── arithmetic ├── mathWithPython_arithmetic_functions3.ipynb ├── mathWithPython_arithmetic_forLoops.ipynb ├── mathWithPython_arithmetic_functions2.ipynb ├── mathWithPython_arithmetic_OrderOfOps.ipynb ├── mathWithPython_arithmetic_abs.ipynb ├── mathWithPython_arithmetic_ifLogical.ipynb ├── mathWithPython_arithmetic_remainder.ipynb ├── mathWithPython_arithmetic_boolean.ipynb ├── mathWithPython_arithmetic_powers.ipynb └── mathWithPython_arithmetic_variables.ipynb ├── calculus ├── mathWithPython_calc_partial.ipynb ├── mathWithPython_calc_piecewise.ipynb └── mathWithPython_calc_integrals.ipynb ├── algebra_2 ├── mathWithPython_algebra2_expLog.ipynb ├── mathWithPython_algebra2_complexQuadForm.ipynb ├── mathWithPython_algebra2_diff.ipynb ├── mathWithPython_algebra2_polynomialRoots.ipynb ├── mathWithPython_algebra2_gauss.ipynb ├── mathWithPython_algebra2_evenOddFuns.ipynb ├── mathWithPython_algebra2_complexDivision.ipynb ├── mathWithPython_algebra2_sumProd.ipynb ├── mathWithPython_algebra2_complexMult.ipynb ├── mathWithPython_algebra2_loglin.ipynb ├── mathWithPython_algebra2_sequences.ipynb ├── mathWithPython_algebra2_scienceNot.ipynb ├── mathWithPython_algebra2_unitCircle.ipynb ├── mathWithPython_algebra2_unity.ipynb ├── mathWithPython_algebra2_logprops.ipynb └── mathWithPython_algebra2_minMaxFuns.ipynb ├── sympyLatex ├── mathWithPython_sympyLatex_fstrings.ipynb ├── mathWithPython_sympyLatex_sympy1.ipynb ├── mathWithPython_sympyLatex_bugHunt_SOL.ipynb ├── mathWithPython_sympyLatex_latex.ipynb ├── mathWithPython_sympyLatex_BUGHUNT.ipynb └── mathWithPython_sympyLatex_sympy2.ipynb ├── conics ├── mathWithPython_conics_meshes.ipynb ├── mathWithPython_conics_circles.ipynb ├── mathWithPython_conics_ellipse.ipynb ├── mathWithPython_conics_hyperbolas.ipynb └── mathWithPython_conics_parabola.ipynb ├── trigonometry ├── mathWithPython_trig_pythagorean.ipynb └── mathWithPython_trig_bugHunt.ipynb ├── numberTheory ├── mathWithPython_numTheory_fermat.ipynb ├── mathWithPython_numTheory_perfect.ipynb ├── mathWithPython_numTheory_numberSeqs.ipynb └── mathWithPython_numTheory_EuclidTriplets.ipynb └── dataTypes └── mathWithPython_datatypes_numbersStrings.ipynb /linearAlgebra/einstein.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikexcohen/MasterMathByCodingInPython/HEAD/linearAlgebra/einstein.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Master Math by Coding in Python 2 | Python code accompanying the course "Master Math by Coding in Python" 3 | 4 | 37+ hours of instruction (>60 hours in total, including exercises) on how to use Python as a tool for learning concepts and visualizations in mathematics. 5 | 6 | See https://www.udemy.com/course/math-with-python/?couponCode=202311 for more details, preview videos, and to enroll in the full course. 7 | -------------------------------------------------------------------------------- /probability/data.csv: -------------------------------------------------------------------------------- 1 | 0.1023,0.78202 2 | 0.13482,0.7593 3 | 0.19309,0.7655 4 | 0.23103,0.84814 5 | 0.13889,0.90393 6 | 0.15379,0.82335 7 | 0.16463,0.70971 8 | 0.12263,0.68905 9 | 0.095528,0.7531 10 | 0.15921,0.7655 11 | 0.20664,0.83368 12 | 0.14566,0.875 13 | 0.24458,0.68492 14 | 0.19173,0.59814 15 | 0.13076,0.71178 16 | 0.28252,0.12707 17 | 0.35705,0.12087 18 | 0.35298,0.2469 19 | 0.19851,0.31715 20 | 0.2107,0.17459 21 | 0.30285,0.10227 22 | 0.35569,0.17045 23 | 0.28523,0.18079 24 | 0.27846,0.1312 25 | 0.35434,0.11467 26 | 0.40176,0.29442 27 | 0.43699,0.32748 28 | 0.43564,0.25517 29 | 0.43699,0.19112 30 | 0.49797,0.14979 31 | 0.39499,0.15393 32 | 0.35298,0.25723 33 | 0.23916,0.29236 34 | 0.23916,0.16839 35 | 0.38821,0.14773 36 | 0.36247,0.19938 37 | 0.75542,0.82335 38 | 0.76084,0.74897 39 | 0.77168,0.61674 40 | 0.81369,0.56921 41 | 0.89092,0.66012 42 | 0.88279,0.80062 43 | 0.83808,0.73037 44 | 0.82724,0.65186 45 | 0.79472,0.57748 46 | 0.74051,0.58574 47 | 0.70935,0.64979 48 | 0.6145,0.76963 49 | 0.57791,0.86054 50 | 0.78659,0.80888 51 | 0.79607,0.69938 52 | 0.75407,0.6188 53 | 0.69851,0.56715 54 | 0.62805,0.42665 55 | 0.50745,0.5155 56 | 0.69309,0.68492 57 | 0.73374,0.83781 58 | 0.8435,0.74897 59 | 0.84485,0.65393 60 | 0.74187,0.60227 61 | 0.67954,0.69938 62 | 0.65786,0.85847 63 | 0.77439,0.8564 64 | 0.76897,0.61467 65 | 0.19173,0.76756 66 | 0.20935,0.85227 67 | 0.27168,0.79442 68 | 0.15515,0.72417 69 | 0.23645,0.2407 70 | 0.25813,0.32335 71 | 0.30556,0.24897 72 | 0.31911,0.1188 73 | 0.27168,0.15806 74 | 0.3435,0.28822 75 | 0.3435,0.29029 76 | -------------------------------------------------------------------------------- /artFromTrig/mathWithPython_artFromTrig_squircle.ipynb: -------------------------------------------------------------------------------- 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":["\n"," \"Open\n",""],"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} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_export.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Exporting graphics as pictures\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","source":["C = np.zeros((10,10))\n","\n","for i in range(0,10):\n"," for j in range(0,10):\n"," C[i,j] = (-1)**(i+j)\n","\n","plt.imshow(C)\n","plt.set_cmap('gray')\n","plt.tick_params(axis='both',labelleft=False,labelbottom=False)\n","\n","# save the figure!\n","plt.tight_layout()\n","plt.savefig('NiceFigure.png')\n","plt.show() # make sure this line comes after, not before, the savefig function call"],"metadata":{"id":"ycT-Wv9T8VG4"},"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} -------------------------------------------------------------------------------- /artFromTrig/mathWithPython_artFromTrig_logisticMap.ipynb: -------------------------------------------------------------------------------- 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":["\n"," \"Open\n",""],"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} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_coords2.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Plotting coordinates on a plane\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"markdown","metadata":{"id":"Cka0ahk37bmp"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"kCMU-caZ7bmp"},"outputs":[],"source":["# define a function and then subs\n","import sympy as sym\n","\n","x = sym.symbols('x')\n","y = x**2 - 3*x\n","\n","xrange = range(-10,11)\n","\n","\n","for i in range(0,len(xrange)):\n"," plt.plot(xrange[i],y.subs({x:xrange[i]}),'o')\n","\n","plt.xlabel('x')\n","plt.ylabel('$f(x) = %s$' %sym.latex(y))\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"mTGgRmu-7-u3"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_multTable.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Creating and accessing matrices with numpy\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"markdown","metadata":{"id":"95c2VStQeQ75"},"source":["# Exercise: Create a multiplication table"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"e3JYK52ceQ75"},"outputs":[],"source":["nums = range(1,11)\n","\n","multmat = np.zeros((len(nums),len(nums)),dtype=int)\n","\n","for i in nums:\n"," for j in nums:\n"," multmat[i-1,j-1] = i*j\n","\n","\n","display(Math(sym.latex(sym.sympify(multmat)))) # no display without display\n","\n","x = 3"]},{"cell_type":"code","source":[],"metadata":{"id":"eEiaorcHugG3"},"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} -------------------------------------------------------------------------------- /mathWithPython_harmonograph.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction\n","# VIDEO: Create a beautiful harmonograph!\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"-ybsgr5FbiZA"},"outputs":[],"source":["import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9voiYnfRbiZC"},"outputs":[],"source":["# leave these parameters as-is\n","n = 1000000\n","t = np.logspace(np.log10(10),np.log10(500),n)\n","\n","# try chaning these parameters\n","A = [ 1, 1, 1.5, 1.5 ]\n","d = [ .004, .001, .002, .0015 ]\n","f = [ 3, 1, 2, 2.5 ]\n","\n","# generate XY value pairs\n","x = A[0]*np.sin(t*f[0])*np.exp(-d[0]*t) + A[1]*np.sin(t*f[1])*np.exp(-d[1]*t)\n","y = A[2]*np.sin(t*f[2])*np.exp(-d[2]*t) + A[3]*np.sin(t*f[3])*np.exp(-d[3]*t)\n","\n","# plot them!\n","plt.plot(x,y,'k',linewidth=.1)\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R2v9uaWebiZC"},"outputs":[],"source":["# what are the elementary components of the plots above? Let's have a look!\n","plt.plot(np.sin(t*f[0])*np.exp(-d[0]*5*t),linewidth=.5)\n","plt.show()"]}],"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} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_functions3.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Create interactive math functions, part 3\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"D5XD-6N8qgvA"},"outputs":[],"source":["# guess a number!\n","# write code to generate a random integer and then input user guesses of that integer.\n","# The code should tell the user to guess higher or lower until they get the right answer.\n","\n","from numpy import random\n","\n","def guessTheNumber():\n"," num2guess = random.randint(1,101)\n","\n"," userguess = int( input('Guess a number between 1 and 100 ') )\n"," while userguess!=num2guess:\n"," if userguess>num2guess:\n"," print('Guess lower!')\n"," elif userguess\n"," \"Open\n",""],"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_correlation.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Dot product application: Correlation coefficient\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"inOlqkTK07Yu"},"outputs":[],"source":["# data\n","mikes_courses = [4,5,8,2,9,9,1,3,7]\n","life_happiness = [6,7,9,3,9,3,1,6,7]\n","\n","# mean-center\n","m = mikes_courses - np.mean(mikes_courses)\n","l = life_happiness - np.mean(life_happiness)\n","\n","# compute correlation\n","numer = np.dot(m,l)\n","denom = np.sqrt( np.dot(m,m) ) * np.sqrt(np.dot(l,l))\n","r1 = numer/denom\n","\n","# confirm with numpy function\n","r2 = np.corrcoef(m,l)[1][0]\n","\n","# show the data!\n","plt.plot(mikes_courses,life_happiness,'ms',label='r=%s' %np.round(r1,2))\n","\n","plt.axis([0,10,0,10])\n","plt.gca().set_aspect('equal')\n","plt.xlabel('Number of Mike\\'s courses taken')\n","plt.ylabel('Life happiness')\n","plt.legend()\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_forLoops.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Using for-loops to compute powers\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_J-ZznR_qgu9"},"outputs":[],"source":["# basic for loop construction\n","\n","for i in [0,1,2,3]:\n"," print(i)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"YN4TYTQ7qgu9"},"outputs":[],"source":["# using the range function\n","list( range(0,3) )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"KDVz3mtrqgu9"},"outputs":[],"source":["for i in range(3):\n"," print('This is the %gth element.'%i)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"5J0kNxeCqgu9"},"outputs":[],"source":["for i in range(5):\n"," num = i**2\n"," print(num)"]},{"cell_type":"code","source":[],"metadata":{"id":"NE2mzEXV15bv"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"mtymUt-iqgu-"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9y248rbWqgu-"},"outputs":[],"source":["# write code to print the following:\n","# 2 to the power of 0 is 1\n","# and so on for 2**0 through 2**9\n","\n","base = 2\n","\n","for i in range(10):\n"," print('%g to the power of %g is %g'%(base,i,base**i))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /calculus/mathWithPython_calc_partial.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Calculus\n","# VIDEO: Partial derivatives\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"EqH-SLvsbLCk"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import matplotlib.pyplot as plt\n","import numpy as np\n","from scipy.signal import find_peaks\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oWrjNcf2bLCk"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Cu4Vzo0AbLCw"},"outputs":[],"source":["from sympy.abc import x,y\n","\n","f = x**2 + x*y**2\n","\n","display(Math('\\\\frac{\\\\partial f}{\\\\partial x} = %s' %sym.latex(sym.diff(f,x))))\n","display(Math('\\\\frac{\\\\partial f}{\\\\partial y} = %s' %sym.latex(sym.diff(f,y))))"]},{"cell_type":"code","source":[],"metadata":{"id":"Za3J78G2eCLl"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"95Ieg31CbLCw"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"M5er5FTsbLCw"},"outputs":[],"source":["p = sym.plotting.plot3d(f,(x,-3,3),title='$f(x,y)=%s$' %sym.latex(f))\n","p = sym.plotting.plot3d(sym.diff(f,x),(x,-3,3),(y,-3,3),title='$f_x=%s$' %sym.latex(sym.diff(f,x)))\n","p = sym.plotting.plot3d(sym.diff(f,y),(x,-3,3),(y,-3,3),title='$f_y=%s$' %sym.latex(sym.diff(f,y)))"]},{"cell_type":"code","source":[],"metadata":{"id":"JZzgnF5nbWl-"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_expLog.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Natural exponent and logarithm\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"ePnG-tiYW_Q-"},"outputs":[],"source":["# e^x\n","\n","x = np.linspace(-3,3,100)\n","\n","plt.plot(x,np.exp(x))\n","plt.xlabel('x')\n","plt.ylabel('$e^x$')\n","plt.show()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"8y5QUM4WW_Q-"},"outputs":[],"source":["\n","plt.plot(x,np.log(x))\n","plt.xlabel('x')\n","plt.ylabel('log(x)')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"Q0RkwvvOewvt"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"RS_mdsMVW_Q-"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"aPC3XiAyW_Q-"},"outputs":[],"source":["# visualize that log and e are inverses of each other (positive values only)\n","\n","x = np.linspace(.0001,10,10)\n","\n","# plot it both ways\n","plt.plot(x,np.log(np.exp(x)))\n","plt.plot(x,np.exp(np.log(x)),'o')\n","\n","plt.axis('square')\n","plt.legend({'$\\\\log(e^x)$','$e^{\\\\log(x)}$'})\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_functions2.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Create interactive math functions, part 2\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ESSE9BrQqgvA"},"outputs":[],"source":["# input three numbers from user, x, y, and a switch option\n","# Create two functions that will compute x**y and x/y\n","# call the appropriate function and print the result\n","\n","from IPython.display import display,Math\n","\n","# create functions\n","def powers(x,y):\n"," display(Math('%g^{%g} = %g' %(x,y,x**y)))\n","\n","def division(x,y):\n"," display(Math('\\\\frac{%g}{%g} = %g' %(x,y,x/y)))\n","\n","def mainfunction():\n"," x = int(input('input X: '))\n"," y = int(input('input Y: '))\n"," display(Math('\\\\text{Press \"1\" to compute } %g^{%g} \\\\text{ or \"2\" to compute }\\\\frac{%g}{%g}' %(x,y,x,y)))\n"," which = int(input(' '))\n","\n"," if which==1:\n"," powers(x,y)\n"," elif which==2:\n"," division(x,y)\n"," else:\n"," print('Invalid selection!')\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"b9KT58UbqgvA"},"outputs":[],"source":["# run the main function\n","\n","mainfunction()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eN6ufhGSqgvA"},"outputs":[],"source":["float(input(' '))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /artFromTrig/mathWithPython_artFromTrig_astroid.ipynb: -------------------------------------------------------------------------------- 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":["\n"," \"Open\n",""],"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} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_rational.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Graphing rational functions\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UH_kJh-07bmq"},"outputs":[],"source":["x = range(-3,4)\n","y = np.zeros(len(x))\n","\n","for i in range(0,len(x)):\n"," y[i] = 2 - x[i]**2\n","\n","plt.plot(x,y,'s-')\n","plt.xlabel('x'), plt.ylabel('y')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6CVpETh17bmr"},"outputs":[],"source":["# what if you want more spacing?\n","\n","x = np.linspace(-3,4,14)\n","y = 2 + np.sqrt(abs(x))\n","\n","plt.plot(x,y,'s-')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"BSDsaJVq9KW_"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"OL-x8r4e7bmr"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GEoNkz_97bmr"},"outputs":[],"source":["e = range(-1,4)\n","x = np.linspace(-4,4,300)\n","\n","for i in e:\n"," y = x**i\n"," plt.plot(x,y,label='$y=x^{%s}$'%i,linewidth=4)\n","\n","plt.legend()\n","plt.ylim([-20,20])\n","plt.xlim([x[0],x[-1]])\n","plt.xlabel('x')\n","plt.ylabel('y')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"ycT-Wv9T8VG4"},"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} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_OrderOfOps.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Order of operations\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"scrolled":true,"id":"xN6Rey_Nqgu-"},"source":["## Reminder about order of operations:\n","PEMDAS:\n","\n"," Parentheses\n"," Exponents\n"," Multiplication\n"," Division\n"," Addition\n"," Subtraction\n"," \n","(Please excuse my dear aunt Sally)\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hl11lU_Nqgu-"},"outputs":[],"source":["# examples from slides\n","\n","print( 4 + 3 * 2 - 1 ) # spacing has no effect\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZSkyTgPWqgu-"},"outputs":[],"source":["# will this be 24 or 10?\n","4 + 2 * 3"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"X06ugFZyqgu-"},"outputs":[],"source":["# how about this one? can you make the be 7 or -11?\n","2 - 4 + 9"]},{"cell_type":"code","source":[],"metadata":{"id":"P-K9Ur752ZyL"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"g835zqmTqgu-"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"JTjdTu39qgu-"},"outputs":[],"source":["# add parentheses as needed to make the following equations true\n","\n","# 1)\n","print( 4*5/(7+3) )\n","\n","# 2)\n","print( 9/(3+6)-1 )\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_coords1.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Plotting coordinates on a plane\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DAOK-2Mx7bmo"},"outputs":[],"source":["x = 3\n","y = 5\n","\n","# basic plotting a red dot\n","plt.plot(x,y,'ro')\n","\n","# set axis limits\n","plt.axis('square') # order matters\n","plt.axis([-6,6,-6,6])\n","plt.grid()\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sPX_ghGh7bmo"},"outputs":[],"source":["# a set of coordinates\n","\n","x = [-4,2,5,6,2,-5]\n","y = [5,2,10,-5,4,0]\n","\n","for i in range(0,len(x)):\n"," plt.plot(x[i],y[i],'o',label='point %s'%i)\n","\n","\n","plt.legend()\n","plt.axis('square')\n","plt.grid()\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RQeWPltK7bmo"},"outputs":[],"source":["# getting information from axes\n","\n","plt.plot(4,3,'rs')\n","\n","# get an object for the current axis\n","axis = plt.gca()\n","ylim = axis.get_ylim()\n","print(ylim)\n","\n","# now change only the upper y-axis limit\n","axis.set_ylim([ ylim[0],6 ])\n","\n","plt.xlabel('X axis')\n","plt.ylabel('F(x)')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"5ct74vOT7-V1"},"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} -------------------------------------------------------------------------------- /artFromTrig/mathWithPython_artFromTrig_rose.ipynb: -------------------------------------------------------------------------------- 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":["\n"," \"Open\n",""],"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_complexQuadForm.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Revising the quadratic equation with complex numbers\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","import sympy as sym\n","import numpy as np\n","import matplotlib.pyplot as plt\n","from IPython.display import display, Math\n","\n","from numpy.lib.scimath import sqrt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SMmIZdL-W_Q-"},"outputs":[],"source":["# as a function!\n","\n","def quadeq(a,b,c):\n","\n"," # initialize\n"," out = np.zeros(2,dtype=complex)\n","\n"," # compute\n"," out[0] = ( -b - sqrt(b**2 - 4*a*c) ) / (2*a)\n"," out[1] = ( -b + sqrt(b**2 - 4*a*c) ) / (2*a)\n","\n"," # output\n"," return out"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0DDXXpMUW_Q-"},"outputs":[],"source":["x = 1\n","y = range(-5,6)\n","z = range(-2,11)\n","\n","M = np.zeros((len(y),len(z)),dtype=complex)\n","\n","for i in range(0,len(y)):\n"," for j in range(0,len(z)):\n"," M[i,j] = quadeq(1,y[i],z[j])[0]\n","\n","\n","plt.subplot(1,3,1)\n","plt.imshow(np.real(M))\n","plt.axis('off'), plt.title('real part')\n","\n","plt.subplot(132)\n","plt.imshow(np.imag(M))\n","plt.axis('off'), plt.title('imaginary part')\n","\n","plt.subplot(133)\n","plt.imshow(np.abs(M))\n","plt.axis('off'), plt.title('magnitude')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_abs.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Absolute value\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":["from IPython.display import display,Math"],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"LMtFQ2yq57lz"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7NOAmxO6qgu_"},"outputs":[],"source":["a = -4\n","abs(a)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0vlOgwl4qgu_"},"outputs":[],"source":["b = abs(a)\n","a,b"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"2xXuVGKoqgu_"},"outputs":[],"source":["# printing out with latex\n","x = -4.3\n","\n","# If the following line crashes, you need to import the display and Math functions as shown earlier\n","display(Math('|%g| = %g' %(x,abs(x)) ))"]},{"cell_type":"code","source":[],"metadata":{"id":"PiU2oDeL5u9O"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"qOTap7S-qgu_"},"source":["# Exercise\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"tnKlbqodqgu_"},"outputs":[],"source":["# report the absolute value of a set of numbers only if they are less than -5 or greater than +2\n","numbers = [-4,6,-1,43,-18,2,0]\n","\n","# for-loop\n","for i in numbers:\n"," if i<-5 or i>2:\n"," print( 'Absolute value of %g is %g.' %(i,abs(i)) )\n"," else:\n"," print( str(i) + ' was not tested.' )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_ifLogical.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Using if-statements and logical operators\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UWKdpYEIqgu-"},"outputs":[],"source":["# start with basics:\n","if 4+2 == 6:\n"," print('True!')\n","else:\n"," print('Nope!')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"i3YYarbfqgu_"},"outputs":[],"source":["# using variables\n","\n","x1 = 3\n","x2 = 4\n","\n","if x1>x2:\n"," print('%g is greater than %g' %(x1,x2))\n","elif x1y:\n"," print('Yeah, the first thing.')\n","elif 2*x+y>z and 2*z-x>y:\n"," print('the second thing')\n"]},{"cell_type":"code","source":[],"metadata":{"id":"VkU5gQ5c5NuQ"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"YV74gEt3qgu_"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wAxflFadqgu_"},"outputs":[],"source":["from IPython.display import display, Math\n","\n","for i in range(0,4):\n"," for j in range(0,5):\n"," if j>0 and i>0:\n"," display(Math('%g^{-%g} = %g' %(i,j,i**-j)))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /probability/mathWithPython_prob_jointPDFs.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Probability theory\n","# VIDEO: Joint probability distributions\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"EITFOSJNcr2N"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"n7MrOyGbcr2N"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LCJifUe-cr2Q"},"outputs":[],"source":["n = 1000\n","\n","x = np.random.randn(n)\n","y = np.random.randn(n)**2\n","\n","plt.hist2d(x,y,30,vmax=10)\n","plt.xlabel('$x$')\n","plt.ylabel('$x^2$')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"2xLHEve3cr2Q"},"outputs":[],"source":["sns.jointplot(x=x,y=y,kind='scatter',color=[.8,.3,.9]).plot_joint(sns.kdeplot)\n","plt.xlabel('$x$')\n","plt.ylabel('$x^2$')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"FcPuJ8IxUrSY"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"g8OrYPXVcr2R"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"t0WhqQp4cr2R"},"outputs":[],"source":["# import data with pandas, name variables x and y, determine (visually) how many clusters are in the data\n","\n","import pandas as pd\n","data = pd.read_csv('data.csv',header=None,names=['x','y'])\n","data\n","\n","sns.jointplot(x=data['x'],y=data['y'],kind='kde',levels=5).plot_joint(sns.scatterplot)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"PqK-8-E-dnu8"},"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_outerProduct.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: The outer product\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fMWU1cey07Yu"},"outputs":[],"source":["v1 = np.random.randn(50)\n","v2 = np.random.randn(80)\n","\n","np.dot(v1,v2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"i1BBGp8E07Yu"},"outputs":[],"source":["op = np.outer(v1,v2)\n","# display(Math(sym.latex(sym.sympify(op))))\n","\n","plt.imshow(op)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"s2R3gJ7I27Qv"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"IsCatHuS07Yv"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"QUibLU1C07Yv"},"outputs":[],"source":["v = np.arange(1,10)\n","w = np.arange(1,5)\n","\n","print(np.outer(v,w))\n","print(np.outer(w,v))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"l-Dep88H07Yv"},"outputs":[],"source":["# show that svw=vsw=vws\n","s = 4\n","\n","left = s*np.outer(v,w)\n","middle = np.outer(v*s,w)\n","right = np.outer(v,w)*s\n","\n","print(left-middle)\n","print(middle-right)\n","print(left-right)"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_diff.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Differences (discrete derivative)\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","import sympy as sym\n","import numpy as np\n","import scipy as sp\n","import matplotlib.pyplot as plt\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rKr4u_i2W_Qx"},"outputs":[],"source":["print(2-1)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UEMpB7SQW_Qx"},"outputs":[],"source":["v = [1,2]\n","np.diff(v)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"o9S5vu8gW_Qx"},"outputs":[],"source":["v = [1,2,4,-10]\n","np.diff(v)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NM5GbljYW_Qy"},"outputs":[],"source":["v = np.arange(0,11)\n","print(v)\n","print(np.diff(v))\n","print(np.diff(v,2))\n","print(np.diff(np.diff(v)))"]},{"cell_type":"code","source":[],"metadata":{"id":"v01R0vcIYISt"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"JqAXWGb3W_Qy"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"VzhSuW1sW_Qy"},"outputs":[],"source":["# plot x^2 and its derivative\n","x = np.linspace(-2,2,1021)\n","f = x**2\n","df = np.diff(f)\n","dx = np.diff(x)\n","\n","plt.plot(x,f,label='f')\n","plt.plot(x[0:-1],df/dx,'r',label='df/dx')\n","\n","plt.axis([-2,2,-1,2])\n","plt.grid()\n","plt.legend()\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_polygon.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Drawing patches with polygons\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eJPiOtrD7bms"},"outputs":[],"source":["from matplotlib.patches import Polygon\n","\n","x = np.linspace(0,1,100)\n","y = np.array([ [1,1],[2,3],[3,1] ])\n","p = Polygon(y,facecolor='m',alpha=.3)\n","\n","# extend with two polygons\n","y1 = np.array([ [2,2],[2.5,4],[3.5,1] ])\n","p1 = Polygon(y1,alpha=.2,edgecolor='k')\n","\n","fig, ax = plt.subplots()\n","ax.add_patch(p1)\n","ax.add_patch(p)\n","ax.set_ylim([0,4])\n","ax.set_xlim([0,4])\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"PlljF7va_nkm"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["# Exercise"],"metadata":{"id":"hoV1dS_J_n6z"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"62J4t_NJ7bmt"},"outputs":[],"source":["x = np.linspace(-2,2,101)\n","f = -x**2\n","\n","y = np.vstack((x,f)).T\n","p = Polygon(y,facecolor='g',alpha=.2,edgecolor='k')\n","\n","p1 = Polygon(np.array([ [-.5,-4],[-.5,-2.5],[.5,-2.5],[.5,-4] ]),facecolor='k')\n","\n","fig, ax = plt.subplots()\n","ax.add_patch(p)\n","ax.add_patch(p1)\n","\n","plt.plot(x,f,'k')\n","plt.plot(x[[0,-1]],[-4,-4],'k')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"ycT-Wv9T8VG4"},"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} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_remainder.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Remainder after division (modulus)\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GwozHzD-qgu_"},"outputs":[],"source":["# pick some numbers\n","a = 10\n","b = 3\n","\n","# division\n","a/b"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TKrv0_oYqgu_"},"outputs":[],"source":["# integer division\n","int(a/b)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sG3VFTvEqgu_"},"outputs":[],"source":["# with a remainder!\n","a%b"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TvqxEAGIqgu_"},"outputs":[],"source":["# now for a nicer printing\n","# set variables for outputs\n","divis = int(a/b)\n","remainder = a%b\n","\n","print(\"%g goes into %g, %g times with a remainder of %g.\" %(b,a,divis,remainder))"]},{"cell_type":"code","source":[],"metadata":{"id":"bdqKzCZy6WTa"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"VYyl5BGKqgu_"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"5--_TYIyqgu_"},"outputs":[],"source":["# determining whether a number is odd or even\n","\n","nums = range(-5,6)\n","\n","for i in nums:\n","\n"," # check for first character spacing\n"," firstchar = '' if i<0 else ' '\n","\n"," # test and report\n"," if i%2 == 0:\n"," print('%s%g is an even number' %(firstchar,i))\n"," else:\n"," print('%s%g is an odd number' %(firstchar,i))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_matrixVectMult.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Visualizing matrix-vector multiplication\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"uXXaU94H07Y4"},"outputs":[],"source":["M = np.array([ [.5,1],\n"," [1,.5] ])\n","\n","v = np.array([1,2])\n","v = np.random.randn(2)\n","# v = np.array([1,1])\n","# v = np.array([1,-1])\n","\n","Mv = M@v\n","\n","plt.plot([0,v[0]],[0,v[1]],'b',label='v',linewidth=2)\n","plt.plot([0,Mv[0]],[0,Mv[1]],'r',label='Mv',linewidth=2)\n","\n","plt.axis('square')\n","plt.axis([-5,5,-5,5])\n","plt.legend()\n","plt.grid()\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"LNnFdGyG-EM0"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"H5Adl6RT07Y4"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7-LLMEl607Y4"},"outputs":[],"source":["v1 = np.linspace(-2,2,40)\n","\n","for i in v1:\n","\n"," v = np.array([1,i])\n"," Mv = M@v\n"," plt.plot([0,v[0]],[0,v[1]],color=[1-abs(i)/4,.5,abs(i)/2],alpha=.8)\n"," plt.plot([0,Mv[0]],[0,Mv[1]],color=[1-abs(i)/2,abs(i)/4,.5])\n","\n","\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_fstrings.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Printing with f-strings\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","source":[],"metadata":{"id":"vQ2nUkjKF1d5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# import libraries\n","import sympy as sym\n","from IPython.display import display,Math"],"metadata":{"id":"VKPWtkpnF1bl"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"yPBGjEPgDqJz"},"outputs":[],"source":["# basic intro to f-strings\n","\n","svar = 'Mike'\n","nvar = 7\n","\n","print(f'Hi my name is {svar} and I eat {nvar} chocolates every day.')\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WCcXzq1CDqJz"},"outputs":[],"source":["# now with latex integration\n","\n","x,y = sym.symbols('x,y')\n","expr = 3/x\n","\n","\n","# trying to print using symbolic variables\n","display(Math(f'\\\\frac{x}{y}'))\n","display(Math(f'\\\\frac{{sym.latex(expr)}}{{y}}'))\n","display(Math(f'\\\\frac{{{x}}}{{{y}}}'))\n","display(Math(f'\\\\frac{{{sym.latex(expr)}}}{{{y}}}'))\n","\n","\n","# my preference for mixing replacements with latex\n","display(Math('\\\\frac{%s}{%s}'%(sym.latex(expr),y)))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_0aK4d2KDqJz"},"outputs":[],"source":["# print using numeric variables\n","u,w = 504,438\n","\n","display(Math(f'\\\\frac{u}{w}'))\n","display(Math(f'\\\\frac{{u}}{{w}}'))\n","display(Math(f'\\\\frac{{{u}}}{{{w}}}'))\n","\n","# my preference for mixing replacements with latex\n","display(Math('\\\\frac{%g}{%g}'%(u,w)))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"v36VOPzODqJ6"},"outputs":[],"source":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_polynomialRoots.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Roots of polynomials\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","import sympy as sym\n","import numpy as np\n","import scipy as sp\n","import matplotlib.pyplot as plt\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MKyDRSwQW_Qy"},"outputs":[],"source":["### the equation:\n","# 3x^2 + 2x - 1\n","\n","# define the coefficients\n","coefs = [3,2,-1]\n","\n","# and solve\n","roots = np.roots(coefs)\n","\n","print(roots)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fyW3AVt8W_Qy"},"outputs":[],"source":["# solve\n","from sympy.abc import x\n","\n","eq = 3*x**2 + 2*x - 1\n","\n","for i in roots:\n"," display(Math('\\\\text{At x=}%g\\\\text{, }%s = %g' %(i,sym.latex(eq),eq.subs(x,i))))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Xv4Z-Tn2W_Qz"},"outputs":[],"source":["# zero-degree polynomial\n","np.roots(8)"]},{"cell_type":"code","source":[],"metadata":{"id":"Zqi3X8ClYoMr"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"USNktW8uW_Qz"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"id":"ev3RmV2dW_Qz"},"outputs":[],"source":["# for different polynomial degrees, count the number of roots\n","\n","for i in range(1,11):\n"," coefs = np.arange(1,i+1)\n"," print('A degree-%s polynomial has %s roots' %(len(coefs)-1,len(np.roots(coefs))))"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_matrixMult.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Matrix multiplication\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bUjIFyme07Yv"},"outputs":[],"source":["A = np.random.randn(14,10)\n","B = np.random.randn(14,10)\n","C = np.random.randn(10,14)\n","\n","# print(A@B)\n","print(A@C)\n","print(C@A)"]},{"cell_type":"code","source":[],"metadata":{"id":"c5Ib6EbB3QF5"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"g4IEvV3g07Yv"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DsO5msvD07Yv"},"outputs":[],"source":["def matrixMultiplication(A,B):\n","\n"," # get matrix sizes\n"," szA = np.shape(A)\n"," szB = np.shape(B)\n","\n"," # give error if sizes don't match\n"," if szA[1]!=szB[0]:\n"," raise ValueError('\"Inner\" dimensions don''t match!')\n","\n"," # initialize\n"," C = np.zeros((szA[0],szB[1]))\n","\n"," # compute!\n"," for i in range(szA[0]):\n"," for j in range(szB[1]):\n"," C[i,j] = np.dot(A[i,:],B[:,j])\n","\n"," return C"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"an78gykO07Yv"},"outputs":[],"source":["A = np.random.randn(4,6)\n","B = np.random.randn(5,2)\n","\n","C1 = matrixMultiplication(A,B)\n","C2 = A@B\n","\n","print(C1-C2)"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_sympy1.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Intro to sympy, part 1\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","source":[],"metadata":{"id":"MQqthdMaEOqK"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fCjwXeVPDqJu"},"outputs":[],"source":["# import the sympy package\n","import sympy as sym\n","\n","# import additional functions for nice printing\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"jzC3xa6NDqJv"},"outputs":[],"source":["# create symbolic variables\n","x,y,z = sym.symbols('x,y,z')\n","\n","x\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LRU6BuiJDqJv"},"outputs":[],"source":["# x doesn't have a value; it's just a symbol\n","x + 4"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UdoBkpC4DqJv"},"outputs":[],"source":["# more fun...\n","display( x**y )\n","display( y/z )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"76lhx0a3DqJw"},"outputs":[],"source":["# let's compare with numpy\n","import numpy as np\n","\n","display(sym.sqrt(2)) # square root in symbolic math\n","display(np.sqrt(2)) # square root in numeric/precision math\n"]},{"cell_type":"code","source":[],"metadata":{"id":"aBrsAJpRETPl"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"nCJixHyxDqJw"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"OCgxBaCnDqJw"},"outputs":[],"source":["# 1)\n","display(y*x**2)\n","\n","# 2)\n","display( sym.sqrt(4)*x )\n","\n","# 3)\n","display( sym.sqrt(x)*sym.sqrt(x) )"]},{"cell_type":"code","source":[],"metadata":{"id":"LLq6pIneESiR"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_boolean.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Testing inequalities and Boolean data type\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"BWB-QU9-qgu-"},"outputs":[],"source":["# The result of the below expression can only be True or False\n","4>5"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wcAUvktjqgu-"},"outputs":[],"source":["print(5<5.1)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"P8LmK2ifqgu-"},"outputs":[],"source":["b = 10 > 3*3.33334\n","\n","print(b)\n","print(type(b)) # the variable class is boolean"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"dgOFPBvZqgu-"},"outputs":[],"source":["4 >= 2+2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"aqIM8Qs0qgu-"},"outputs":[],"source":["5 <= 3*2-1.00000000001"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"4IbYTeA7qgu-"},"outputs":[],"source":["# testing for equalities requires two equals signs\n","\n","# 4 = 4\n","4 == 4\n","\n","test = 4 == 5\n","print(test)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"nYuNPWi93G46"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"gB-6r0v8qgu-"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"p9bLX62iqgu-"},"outputs":[],"source":["# which variable value(s) will make the following inequalities true?\n","# comment out the incorrect answers!\n","x = 2\n","x = 3\n","x = 4\n","\n","# 1)\n","print( 4*x+3 < 17-x**2 )\n","\n","# 2)\n","print( 8*x - 2 <= -3*x + 42 )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /conics/mathWithPython_conics_meshes.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing conic sections\n","# VIDEO: Creating contours from meshes in Python\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"rWqnHoXtmREZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rCvqcvyUmREZ"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import sympy as sym\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6rO1CzkDmREc"},"outputs":[],"source":["X,Y = np.meshgrid(range(0,10),range(0,15))\n","\n","plt.subplot(121)\n","plt.pcolormesh(X,edgecolors='k',linewidth=.1)\n","# plt.gca().set_aspect('equal')\n","plt.title('X')\n","\n","plt.subplot(122)\n","plt.pcolormesh(Y,edgecolors='k',linewidth=.1)\n","plt.gca().set_aspect('equal')\n","plt.title('Y')\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"id":"mjiEbboSmREc"},"outputs":[],"source":["x = np.linspace(0,2*np.pi,50)\n","y = np.linspace(0,4*np.pi,50)\n","\n","X,Y = np.meshgrid(x,y)\n","\n","F = np.cos(X) + np.sin(Y)\n","plt.imshow(F,extent=[x[0],x[-1],y[0],y[-1]])\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"I870X057nAKJ"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"7U3DiMl0mREc"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"J6DH4Od_mREd"},"outputs":[],"source":["# Make a gaussian\n","x = np.linspace(-2,2,100)\n","s = 2\n","\n","# create the gaussian\n","X,Y = np.meshgrid(x,x)\n","gauss2d = np.exp( -(X**2+Y**2)/s )\n","\n","# and plot\n","plt.imshow(gauss2d,extent=[x[0],x[-1],x[0],x[-1]])\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"dYWZu_u7mytI"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_gauss.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Find a specific point on a Gaussian\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"2CAmOls6W_Q-"},"outputs":[],"source":["# the key parameter (FWHM - full width at half-maximum)\n","h = 1\n","\n","# \"Time\" variable\n","t = np.linspace(-3,3,1001)\n","\n","# gaussian\n","g = np.exp( -4*np.log(2)*t**2 / h**2 )\n","\n","# and plot\n","plt.plot(t,g)\n","plt.xlabel('t')\n","plt.ylabel('y')\n","plt.title('Gaussian with FWHM=' + str(h))\n","plt.show()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"auNC8tWuW_Q_"},"outputs":[],"source":["# find the x-axis value (here variable 't') for a given function value\n","\n","yVal2find = .5\n","\n","# apply the formula shown in the slides\n","tvals = h*np.sqrt( np.log(yVal2find)/(-4*np.log(2)) )\n","\n","# print out the results\n","print(tvals,-tvals)"]},{"cell_type":"code","source":[],"metadata":{"id":"7S6PzNPjfFZk"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"bZQVmwoaW_Q_"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"VNu1-VWNW_Q_"},"outputs":[],"source":["N = 100 # number of Gaussians\n","h = np.zeros(N)\n","\n","G = np.zeros((N,len(t)))\n","\n","for i in range(N):\n"," h[i] = (i+1)/N\n"," G[i,:] = np.exp( -4*np.log(2)*t**2 / h[i]**2 )\n","\n","plt.pcolormesh(t,h,G)\n","plt.xlabel('t')\n","plt.ylabel('h')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_evenOddFuns.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Even and odd functions\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"zvT21iA2W_RB"},"outputs":[],"source":["# create an even function\n","x = np.linspace(-5,5,20)\n","\n","fEven = x**2\n","\n","fEvenNegative = (-x)**2\n","\n","plt.plot(x,fEven)\n","plt.plot(x,fEvenNegative,'ro')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-KyEAUUwW_RB"},"outputs":[],"source":["# create an odd function\n","x = np.linspace(-5,5,20)\n","\n","fOdd = x**3\n","\n","fOddNegative = (-x)**3\n","\n","plt.plot(x,fOdd)\n","plt.plot(x,fOddNegative,'ro')\n","plt.plot(x,-fOddNegative,'gs')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"3fmGgHO0hvmM"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"MZej25UGW_RB"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DvlGEGxLW_RB"},"outputs":[],"source":["# using graphing to infer whether cos and sine are even or odd functions\n","\n","theta = np.linspace(-2*np.pi,2*np.pi,40)\n","\n","cosfun = np.cos(theta)\n","cosfunN = np.cos(-theta)\n","\n","plt.plot(theta,cosfun)\n","plt.plot(theta,cosfunN,'ro')\n","plt.show()\n","\n","\n","# repeat for sin\n","sinfun = np.sin(theta)\n","sinfunN = np.sin(-theta)\n","\n","plt.plot(theta,sinfun)\n","plt.plot(theta,sinfunN,'ro')\n","plt.plot(theta,-sinfunN,'ys')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_complexDivision.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Complex numbers: division\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"7cF8KgVAW_Q9"},"outputs":[],"source":["# create a complex number\n","z1 = complex(4,2)\n","z2 = complex(3,-5)\n","\n","display(Math('\\\\frac{%s}{2} = %s' %(z1,z1/2) ))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"vIS9hf3rW_Q9"},"outputs":[],"source":["display(Math('\\\\frac{%s \\\\times %s}{%s \\\\times %s} = \\\\frac{%s}{%s} = %s' # sometimes you need \\\n"," %(z1,np.conj(z2), z2, np.conj(z2),\n"," z1*np.conj(z2), z2*np.conj(z2), sym.latex(sym.sympify(z1/z2)) )))"]},{"cell_type":"code","source":[],"metadata":{"id":"A3XzZTD4b6p2"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"nK-kGxC3W_Q9"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_PncDuA2W_Q9"},"outputs":[],"source":["# create two numbers\n","z = complex(4,2)\n","w = complex(3,5)\n","\n","# the parts related to the left multiplicand\n","left_numer = (z-1) * (z*w+w)\n","left_denom = w*z-w\n","left_part = left_numer / left_denom\n","\n","# the parts related to the right multiplicand\n","right_numer = (w-1) * (1-w)\n","right_denom = -w**2*z - w**2 + 2*w*z + 2*w - z - 1\n","right_part = right_numer / right_denom\n","\n","# put them together\n","solution = left_part * right_part\n","\n","# and print!\n","print(solution)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_sumProd.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Summation and products\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","import sympy as sym\n","import numpy as np\n","import scipy as sp\n","import matplotlib.pyplot as plt\n","from IPython.display import display, Math"]},{"cell_type":"markdown","metadata":{"id":"e_4DG5tsW_Qu"},"source":["# VIDEO: Summation and products"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eF7BrYt9W_Qu"},"outputs":[],"source":["lst = [1,3,4,1,6]\n","\n","print( sum(lst) )\n","print( np.sum(lst) )\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WEQYlAOHW_Qv"},"outputs":[],"source":["np.prod(lst)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"B3ZT_IegW_Qv"},"outputs":[],"source":["# cumulative summation\n","np.cumsum(lst)\n","\n","plt.plot(lst,'rs-')\n","plt.plot(np.cumsum(lst),'bo-')\n","plt.legend({'list','cumsum'})\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"sUxXiHsqXwip"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"chiER-6SW_Qv"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"l5vPyEHFW_Qw"},"outputs":[],"source":["# generate numerator\n","num = np.arange(1,6)\n","den = num**2\n","\n","ans1 = np.sum(num) / np.sum(den)\n","ans2 = 1 / np.sum(num)\n","\n","print('Option 1 = %s\\nOption 2 = %s' %(ans1,ans2))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"BFIcvSGEW_Qw"},"outputs":[],"source":["# then repeat with prod\n","ans1 = np.prod(num) / np.prod(den)\n","ans2 = 1 / np.prod(num)\n","\n","print('Option 1 = %s\\nOption 2 = %s' %(ans1,ans2))"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /conics/mathWithPython_conics_circles.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing conic sections\n","# VIDEO: Graphing circles\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"rWqnHoXtmREZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rCvqcvyUmREZ"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import sympy as sym\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7PnuySe3mREd"},"outputs":[],"source":["# circle parameters\n","a = 2\n","b = -3\n","r = 3\n","\n","# grid space\n","axlim = r + np.max((abs(a),abs(b)))\n","x = np.linspace(-axlim,axlim,100)\n","y = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,y)\n","\n","# create the function\n","Fxy = (X-a)**2 + (Y-b)**2 - r**2\n","\n","# draw it as a contour\n","plt.contour(X,Y,Fxy,0)\n","\n","# draw a dot in the center\n","plt.plot(a,b,'go')\n","\n","# draw guide lines\n","plt.plot([-axlim,axlim],[0,0],'k--')\n","plt.plot([0,0],[-axlim,axlim],'k--')\n","\n","plt.gca().set_aspect('equal')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"lC8ma6XYnT8T"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"yiWBNeSEmREd"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"e6-hRndwmREd"},"outputs":[],"source":["# circle parameters\n","a = [-1.5,1.5]\n","\n","# grid space\n","axlim = 5\n","x = np.linspace(-axlim,axlim,100)\n","y = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,y)\n","\n","for r in np.linspace(.5,3,15):\n"," for ai in a:\n"," Fxy = (X-ai)**2 + Y**2 - r**2\n"," plt.contour(X,Y,Fxy,0,colors=[(r/3,r/3,r/3)])\n","\n","plt.gca().set_aspect('equal')\n","plt.plot(a,[0,0],'k',linewidth=3)\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"dYWZu_u7mytI"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_slicing.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: More on \"slicing\" in Python\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# It's generally good practice to import all required modules at the top of the script!\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_PjuJJkneQ8E"},"outputs":[],"source":["# create an array (vector) of numbers\n","vec = [10,11,12,13,14,15,16,17,18,19,20]\n","# or\n","vec = list(range(10,21))\n","\n","print(vec)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"jZxpHjHkeQ8E"},"outputs":[],"source":["# indexing a single item\n","vec[2]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HbiNd1x4eQ8E"},"outputs":[],"source":["# indexing multiple items (aka slicing)\n","vec[2:4]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"n07GC7lPeQ8E"},"outputs":[],"source":["# from one element to the end\n","vec[4:]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ya-qAjVDeQ8E"},"outputs":[],"source":["# from the first element to a specific element\n","vec[:3]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"O1a03pQ8eQ8E"},"outputs":[],"source":["# the last element\n","vec[-1]\n","\n","# penultimate element\n","vec[-2]\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZusrnFO-eQ8E"},"outputs":[],"source":["# from the end to the beginning\n","vec[::-1]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"012XsBkfeQ8E"},"outputs":[],"source":["# with non-1 stepping\n","vec[0:5:2]"]},{"cell_type":"code","source":[],"metadata":{"id":"WMihzKQgwzFO"},"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} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_bugHunt_SOL.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Sympy/latex bug hunt!\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"v36VOPzODqJ6"},"outputs":[],"source":["import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7xpN1lvlDqJ7"},"outputs":[],"source":["mu,alpha = sym.symbols('mu,alpha')\n","\n","expr = 2*sym.exp(mu**2/alpha)\n","\n","display(Math( sym.latex(expr) ))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MMJYKCthDqJ7"},"outputs":[],"source":["Math('1234 + \\\\frac{3x}{\\sin(2\\pi t+\\\\theta)}')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fZ4Ju3nnDqJ7"},"outputs":[],"source":["a = '3'\n","b = '4'\n","\n","# answer should be 7\n","print(sym.sympify(a)+sym.sympify(b))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Q6V7KWYZDqJ7"},"outputs":[],"source":["x = sym.symbols('x')\n","sym.solve( 4*x - 2 )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oz7ssl6SDqJ7"},"outputs":[],"source":["# part 1 of 2\n","\n","q = x**2\n","r = x**2\n","\n","display(q)\n","display(r)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"a9ezp0O9DqJ7"},"outputs":[],"source":["# part 2 of 2\n","\n","q,r = sym.symbols('q,r')\n","\n","q = sym.sympify('x^2')\n","r = sym.sympify('x**2')\n","\n","display(Math(sym.latex(q)))\n","display(r)\n","\n","sym.Eq(q,r)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"8LfqtgLGDqJ7"},"outputs":[],"source":["x = sym.symbols('x')\n","\n","equation = (4*x**2 - 5*x + 10)**(1/2)\n","display(equation)\n","equation.subs(x,3)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RsNeBdcBDqJ7"},"outputs":[],"source":["x,y = sym.symbols('x,y')\n","\n","equation = 1/4*x*y**2 - x*(5*x + 10*y**2)**(3)\n","display(equation)"]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /trigonometry/mathWithPython_trig_pythagorean.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Trigonometry\n","# VIDEO: The Pythagorean theorem\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"944eNrsrEBjZ"},"outputs":[],"source":["# import libraries\n","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":"2ceoWVZcEBjZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9EA3oPmCEBjc"},"outputs":[],"source":["a = 8\n","b = 4\n","\n","# compute c\n","c = np.sqrt(a**2 + b**2)\n","\n","# draw the triangle\n","plt.plot([0,a],[0,0],'k',linewidth=2)\n","plt.plot([0,0],[0,b],'k')\n","plt.plot([0,a],[b,0],'k')\n","\n","# plot right-angle\n","plt.plot([.3,.3],[0,.3],'k',linewidth=1)\n","plt.plot([0,.3],[.3,.3],'k',linewidth=1)\n","\n","plt.text(a/3,.25,'a='+str(a),fontsize=15)\n","plt.text(.1,b/3,'b='+str(b),fontsize=15)\n","plt.text(a/2+.1,b/2,'c='+str(np.round(c,3)),fontsize=15)\n","\n","axlim = np.max((a,b))+.5\n","plt.axis('square')\n","plt.axis([-.5,axlim,-.5,axlim])\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"H_6AjCHWHd8k"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"mJnTkIijEBjc"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cOZ9glJCEBjc"},"outputs":[],"source":["# compute magnitude and angle of complex number\n","\n","z = np.complex(3,4)\n","\n","mag1 = np.sqrt( np.real(z)**2 + np.imag(z)**2 )\n","mag2 = np.abs(z)\n","print(mag1,mag2)\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NkDr75SQEBjc"},"outputs":[],"source":["ang1 = np.arctan2(np.imag(z),np.real(z))\n","ang2 = np.angle(z)\n","\n","print(ang1,ang2)"]},{"cell_type":"code","source":[],"metadata":{"id":"-kLWEO4hEOJa"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_primeFactor.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Prime factorization\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"JUv7RozYeQ8G"},"outputs":[],"source":["# factor an integer into the product of prime numbers\n","number = 48\n","\n","# Use the sympy function factorint. The output is a dictionary!\n","fact_dict = sym.factorint(number)\n","print(fact_dict)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cnLx2qgVeQ8G"},"outputs":[],"source":["# just print the prime numbers\n","primenumbers = list( fact_dict.keys() )\n","\n","print('The prime factors of ' + str(number) + ' are ' + str(primenumbers))\n","\n","fact_dict[primenumbers[1]]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"nvmH5Xi6eQ8H"},"outputs":[],"source":["# test on prime number\n","sym.factorint(4)"]},{"cell_type":"code","source":[],"metadata":{"id":"btwP-V8h1xwo"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"-9cI45NGeQ8H"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"jIRiIwPQeQ8H"},"outputs":[],"source":["# loop through numbers and report whether each number is composite or prime\n","\n","nums = range(2,51)\n","for i in nums:\n"," di = sym.factorint(i)\n"," ks = list(di.keys())\n"," if len(di)==1 and di[ks[0]]==1:\n"," print('%s is a prime number' %i)\n"," else:\n"," print('%s is a composite number with prime factors %s' %(i,list(di.keys())))\n"]},{"cell_type":"code","source":[],"metadata":{"id":"mqUm9TjZ14xe"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_complexMult.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Complex numbers: conjugate and multiplication\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"s8JMNUzhW_Q8"},"outputs":[],"source":["# create complex numbers\n","z1 = complex(4,5)\n","z2 = complex(6,-2)\n","\n","# multiplication the \"manual\" way\n","w = np.real(z1)*np.real(z2) + np.real(z1)*np.imag(z2)*1j + np.imag(z1)*np.real(z2)*1j + np.imag(z1)*np.imag(z2)*1j*1j\n","\n","print(w)\n","sym.sympify(w)\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"haBAlG9NW_Q8"},"outputs":[],"source":["# or let Python do the hard work ;)\n","sym.sympify(z1*z2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sDnTGE_2W_Q8"},"outputs":[],"source":["# complex conjugate\n","\n","z1 = complex(4,3)\n","z2 = complex(4,-3)\n","\n","print( np.conj(z1) )\n","print( np.conj(z2) )\n"]},{"cell_type":"code","source":[],"metadata":{"id":"DsbsW6S5biQI"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"iv7fh49QW_Q8"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZpduYEoSW_Q8"},"outputs":[],"source":["a,b = sym.symbols('a,b')#,real=True)\n","\n","z = a + b*sym.I\n","\n","sym.simplify( sym.expand( z*sym.conjugate(z) ) )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ooj_QOFKW_Q8"},"outputs":[],"source":["# with nicer printing\n","\n","result = sym.simplify( sym.expand( z*sym.conjugate(z) ) )\n","display(Math('z\\\\times z^* = %s' %sym.latex(result)))"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_loglin.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Log-spaced and linearly spaced numbers\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"9kcB30wMW_Q_"},"outputs":[],"source":["# you've already seen linearly spaced numbers...\n","\n","np.linspace(-2,4,10)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AQUVOx3kW_Q_"},"outputs":[],"source":["# log-spaced\n","np.logspace(1,2,10)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"2ZxpGyilW_Q_"},"outputs":[],"source":["# the way you'd probably expect them to be\n","a = np.log10(2.3)\n","b = np.log10(14.3)\n","n = 14\n","\n","np.logspace(a,b,n)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9FKKzDWrW_Q_"},"outputs":[],"source":["# the way you'd probably expect them to be\n","a = np.log10(1)\n","b = np.log10(5)\n","n = 5\n","\n","np.logspace(a,b,n)"]},{"cell_type":"code","source":[],"metadata":{"id":"vE_NQJwAf_Z1"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"-De_BFwTW_RA"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9-9Q130AW_RA"},"outputs":[],"source":["# show that at small scales, lin and log are close.\n","# this is why local linear approximations to nonlinear functions are so useful\n","\n","a = 2\n","b = 100\n","n = 50\n","\n","lo = np.logspace(np.log10(a),np.log10(b),n)\n","li = np.linspace(a,b,n)\n","\n","plt.plot(li,lo,label='log')\n","plt.plot(li,li,label='linear')\n","\n","plt.legend()\n","plt.axis('square')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_dotProduct.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: The dot product\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hdE0WON_07Yu"},"outputs":[],"source":["v = np.arange(10,20,3)\n","w = np.arange(5,14,3)\n","print(w)\n","dp1 = 0\n","\n","for i in range(0,len(v)):\n"," dp1 = dp1 + v[i]*w[i]\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"uX4NisPS07Yu"},"outputs":[],"source":["dp2 = np.sum( np.multiply(v,w) )\n","dp3 = np.dot(v,w)\n","print(dp,dp2,dp3)"]},{"cell_type":"code","source":[],"metadata":{"id":"t-EOOZAP2Ta4"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"J_niTxA007Yu"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wkwB_3xc07Yu"},"outputs":[],"source":["# write a function that takes two vectors, tests whether the dot product is valid between them, and returns the dot product or gives an error message\n","\n","def mydotproduct(v,w):\n","\n"," # squeeze out singleton dimensions\n"," v = np.squeeze(v)\n"," w = np.squeeze(w)\n","\n"," # check whether they are the same size\n"," if len(v)!=len(w):\n"," raise ValueError('Vectors must have the same length!')\n","\n"," display(Math('v^Tw = %s' %np.dot(v,w)))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ecLONqU807Yu"},"outputs":[],"source":["v1 = np.random.randn(1,10)\n","v2 = np.random.randn(10,1)\n","\n","# np.shape(np.squeeze(v2))\n","\n","mydotproduct(v1,v2)"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_matrices.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Making images from matrices\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rDOK_NWA7bms"},"outputs":[],"source":["# create a matrix\n","A = [ [1,2],[1,4] ]\n","\n","# show it (yikes! many functions!)\n","display(Math(sym.latex(sym.sympify(np.array(A)))))\n","\n","# now image it\n","plt.imshow(A)\n","\n","plt.xticks([0,1])\n","plt.yticks([.85,1])\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"x753kkhL7bms"},"outputs":[],"source":["A = np.zeros((10,14))\n","\n","print( np.shape(A) )\n","\n","for i in range(0,np.shape(A)[0]):\n"," for j in range(0,np.shape(A)[1]):\n","\n"," # populate the matrix\n"," A[i,j] = 3*i-4*j\n","\n","print(A)\n","plt.imshow(A)\n","plt.plot([0,3],[8,2],'r',linewidth=4)\n","plt.set_cmap('Purples')\n","\n","for i in range(0,np.shape(A)[0]):\n"," for j in range(0,np.shape(A)[1]):\n"," plt.text(j,i,int(A[i,j]),horizontalalignment='center',verticalalignment='center')\n","\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"kA0lxqWq-Oaa"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"-J02X5cr7bms"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Qwz3vCJE7bms"},"outputs":[],"source":["# make a checkerboard\n","\n","C = np.zeros((10,10))\n","\n","for i in range(0,10):\n"," for j in range(0,10):\n"," C[i,j] = (-1)**(i+j)\n","\n","plt.imshow(C)\n","plt.set_cmap('gray')\n","plt.tick_params(labelleft=False,labelbottom=False)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"ycT-Wv9T8VG4"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_sequences.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Arithmetic and geometric sequences\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"NEfIpKqgW_RB"},"outputs":[],"source":["# arithmetic sequence\n","\n","a = 2\n","d = 3\n","maxn = 6\n","\n","ariseq = a + d*np.arange(0,maxn)\n","print(ariseq)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DhmDp2UxW_RB"},"outputs":[],"source":["# geometric sequence\n","a = 2\n","r = 3\n","\n","geoseq = a * r**np.arange(0,maxn)\n","print(geoseq)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"tauvWz6aW_RB"},"outputs":[],"source":["plt.plot(ariseq,'ks',label='arithmetic')\n","plt.plot(geoseq,'ro',label='geometric')\n","\n","plt.xlim([-.5,maxn-.5])\n","plt.legend()\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"40K8P0fJg3SG"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"3dBELZO5W_RB"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hNhLHdbXW_RB"},"outputs":[],"source":["# confirm that nth term is a+(n-1)*d and a*r**(n-1) by indexing and direct computation\n","\n","# parameters\n","a = 2\n","d = 3\n","maxn = 10\n","\n","# compute sequences\n","ariseq = a + d*np.arange(0,maxn)\n","geoseq = a * d**np.arange(0,maxn)\n","\n","# which element to find?\n","nth = 6\n","\n","# find by direct computation\n","ariDirect = a + (nth-1)*d\n","geoDirect = a * d**(nth-1)\n","\n","# compare against order in sequence\n","print(ariseq[nth-1],ariDirect)\n","print(geoseq[nth-1],geoDirect)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /conics/mathWithPython_conics_ellipse.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing conic sections\n","# VIDEO: Graphing ellipses\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"rWqnHoXtmREZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rCvqcvyUmREZ"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import sympy as sym\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"W8Z2u-n9mREd"},"outputs":[],"source":["# parameters\n","a = 2\n","b = 3\n","h = 1\n","k = 2\n","\n","# grid space\n","axlim = np.max((a,b)) + np.max((abs(h),abs(k)))\n","x = np.linspace(-axlim,axlim,100)\n","y = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,y)\n","\n","# create the function\n","Fxy = (X-h)**2/a**2 + (Y-k)**2/b**2 - 1\n","\n","# draw it as a contour\n","plt.contour(X,Y,Fxy,0)\n","\n","# draw a dot in the center\n","plt.plot(h,k,'go')\n","\n","# draw guide lines\n","plt.plot([-axlim,axlim],[0,0],'--',color=[.8,.8,.8])\n","plt.plot([0,0],[-axlim,axlim],'k--',color=[.8,.8,.8]) # color overwrites k\n","\n","plt.gca().set_aspect('equal')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"jUXN0UdunpVL"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"cVTBuQhImREd"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Zn_XiFxPmREd"},"outputs":[],"source":["# parameters\n","n = 16\n","a = abs(np.linspace(4,-4,n))\n","b = 4\n","h = 0\n","k = np.linspace(-4,4,n)\n","\n","# grid space\n","axlim = 8\n","x = np.linspace(-axlim,axlim,100)\n","y = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,y)\n","\n","for i in range(0,n):\n"," Fxy = (X-h)**2/a[i]**2 + (Y-k[i])**2/b**2 - 1\n"," plt.contour(X,Y,Fxy,0,colors=[(i/n,0,i/n)])\n","\n","\n","plt.gca().set_aspect('equal')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"dYWZu_u7mytI"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_inequalities.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Solving inequalities\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MDqj9iz7eQ8H"},"outputs":[],"source":["x = sym.symbols('x')\n","\n","expr = 4*x > 8\n","sym.solve(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"uCExk9D8eQ8H"},"outputs":[],"source":["display(Math(sym.latex(sym.solve(expr))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"D8b2m46OeQ8H"},"outputs":[],"source":["sym.oo > 10000093847529345"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"nFbnt0UHeQ8H"},"outputs":[],"source":["expr = (x-1)*(x+3) > 0\n","\n","display(Math(sym.latex(sym.solve(expr))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MNeYBJT5eQ8H"},"outputs":[],"source":["# sym.solve will return the expression if not enough information\n","\n","a,b,c = sym.symbols('a,b,c')\n","\n","expr = a*x > b**2/c\n","display(Math(sym.latex(expr)))\n","\n","sym.solve(expr)#,x)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cxYUDIRQeQ8H"},"outputs":[],"source":["# a slightly richer problem\n","sym.solve( 2*x**2>8 )"]},{"cell_type":"code","source":[],"metadata":{"id":"cs41YxKx2Lwt"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"PskDAFSIeQ8H"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"T0HvcvBteQ8I"},"outputs":[],"source":["expr = (3*x/2) + (4-5*x)/3 <= 2 - (5*(2-x))/4\n","\n","display(Math(sym.latex(expr)))\n","sym.solve(expr)"]},{"cell_type":"code","source":[],"metadata":{"id":"91sr0AlE2MEf"},"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} -------------------------------------------------------------------------------- /numberTheory/mathWithPython_numTheory_fermat.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Number theory\n","# VIDEO: Fermat's theorem\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"JL_0UKJOj1YP"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym"]},{"cell_type":"markdown","metadata":{"id":"LV4pVB6l9g1N"},"source":["There are no integer solutions to $x^3+y^3=z^3$"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Rrj_sFXQDqJN"},"outputs":[],"source":["ints = np.arange(1,101)\n","\n","z = np.zeros((len(ints),len(ints)))\n","\n","# run the simulation\n","for x in ints:\n"," for y in ints:\n"," z[x-1,y-1] = (x**3 + y**3)**(1/3)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AEFlPR729_1x"},"outputs":[],"source":["# check for integers\n","zInts = z%1 == 0\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FDE9IN_r-FhI"},"outputs":[],"source":["\n","# now visualize\n","fig,ax = plt.subplots(1,2,figsize=(12,6))\n","fig.tight_layout(pad=5)\n","\n","# show the resulting z-values\n","h = ax[0].imshow(z)\n","fig.colorbar(h,ax=ax[0],fraction=.045)\n","ax[0].set_xlabel('y')\n","ax[0].set_ylabel('x')\n","ax[0].set_title('$z=\\sqrt[3]{x^3+y^3}$',fontsize=16)\n","\n","# show the boolean integer map\n","h = ax[1].imshow(zInts,vmin=0,vmax=1)\n","fig.colorbar(h,ax=ax[1],fraction=.045)\n","ax[1].set_xlabel('y')\n","ax[1].set_ylabel('x')\n","ax[1].set_title('Whether $z$ is int',fontsize=16)\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"WjMxi6rnoZuX"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"XiR9JHTk-GrY"},"source":["# Exercise: \"Fermat's stairway to heaven\""]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ANkgxgp4HtgQ"},"outputs":[],"source":["# Modify the code to create a map of integer Pythagorean triplets"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PYS-dL_s3zFT"},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"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"}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_scienceNot.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Orders of magnitude and scientific notation\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"uBgH7gI7W_RA"},"outputs":[],"source":["# write the following number in scientific notation\n","x = 2938429348\n","\n","'{:,e}'.format(x)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iLsolDmzW_RA"},"outputs":[],"source":["# numbers are easier to read with commas!\n","\n","# or f\n","'{:,d}'.format(x)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"osHV9pTcW_RA"},"outputs":[],"source":["# another way...\n","'%.2e' %(x)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"5UfQeetIW_RA"},"outputs":[],"source":["# notice this is a string\n","\n","s = '%.3e' %(x)\n","print(s)\n","print( type(s) )\n","\n","# so you can index or slice parts of it\n","s[2:4]"]},{"cell_type":"code","source":[],"metadata":{"id":"tyFTJatwhNeC"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"vwQWL5pVW_RA"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fuCg55loW_RA"},"outputs":[],"source":["# list the number\n","num = 2342\n","\n","# order of magnitude\n","orderOfMag = int(np.floor(np.log10(abs(num))))\n","\n","# convert to scientific notation and get the characters before the period\n","numstr = '{:,e}'.format(num)\n","wheredot = numstr.find('.')\n","scinot = numstr[:wheredot]\n","\n","display(Math( '%s\\\\text{ is }%s\\\\text{ orders of magnitude, }\\\\approx %s\\\\times10^{%g}' \\\n"," %(num,orderOfMag,scinot,orderOfMag) ))"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /calculus/mathWithPython_calc_piecewise.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Calculus\n","# VIDEO: Piecewise functions\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"EqH-SLvsbLCk"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import matplotlib.pyplot as plt\n","import numpy as np\n","from scipy.signal import find_peaks\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oWrjNcf2bLCk"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"2Xx13TTGbLCo"},"outputs":[],"source":["# list function pieces\n","from sympy.abc import x\n","piece1 = 0\n","piece2 = -2*x\n","piece3 = x**3/10\n","\n","# put them together with conditions\n","fx = sym.Piecewise( (piece1,x<0),(piece2,(x>=0) & (x<3)),(piece3,x>=3) )\n","\n","# evaluate the function in a range\n","xx = np.linspace(-3,5,1000)\n","fxx = sym.lambdify(x,fx)\n","\n","# show it in a plot\n","plt.plot(xx,fxx(xx),'k')\n","\n","# make the plot look a bit nicer\n","plt.xlabel('x')\n","plt.ylabel('f(x)')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"2a8_CgZAcQji"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"AEAQQ8C6bLCo"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"maKh55p9bLCo"},"outputs":[],"source":["# function pieces\n","x = sym.symbols('x')\n","\n","f = x**3\n","g = sym.log(x,2)\n","\n","fx = sym.Piecewise( (f,x<=0),(g,x>0) )\n","\n","# print out the function definition\n","display(Math('f(x) = ' + sym.latex(fx)))\n","\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","with plt.xkcd():\n"," plt.plot(xx,fxx(xx),'k')\n","\n","# make the plot look a bit nicer\n","plt.xlim([-2,2])\n","plt.ylim([-10,3])\n","plt.xlabel('x')\n","plt.ylabel('y')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"JZzgnF5nbWl-"},"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} -------------------------------------------------------------------------------- /graphing/mathWithPython_graph_startStopLine.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing\n","# VIDEO: Graphing lines part 1: start/stop notation\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"wBVucbKz7bmm"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eGwirhuq7bmp"},"outputs":[],"source":["# drawing lines\n","\n","p1 = [-3,-1]\n","p2 = [4,4]\n","\n","# nice try, but wrong code :(\n","plt.plot(p1,p2)\n","plt.plot([p1[0],p2[0]],[p1[1],p2[1]],color=[.7,.3,.8],linewidth=5)\n","\n","plt.axis('square')\n","plt.axis([-6,6,-6,6])\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"W7bRMya37bmp"},"outputs":[],"source":["x = 3\n","y = 5\n","\n","# basic plotting a red dot\n","plt.plot(x,y,'ro')\n","plt.plot([0,x],[0,y],'r')\n","\n","# set axis limits\n","plt.axis('square') # order matters\n","plt.axis([-6,6,-6,6])\n","plt.grid()\n","\n","# now add lines\n","plt.plot([-6,6],[0,0],'k')\n","plt.plot([0,0],[-6,6],'k')\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SvTjnEoK7bmp"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":{"id":"E92vnR4v7bmp"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fEepkiC57bmq"},"outputs":[],"source":["x = range(-20,20)\n","\n","for i in range(0,len(x)):\n"," plt.plot([0,x[i]],[0,abs(x[i])**(1/2)])\n","\n","plt.xlabel('x')\n","plt.ylabel('y')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RCcETrU07bmq"},"outputs":[],"source":["# draw a square\n","plt.plot([0,2],[2,2],'r')\n","plt.plot([0,2],[0,0],'k')\n","plt.plot([0,0],[0,2],'g')\n","plt.plot([2,2],[0,2],'m')\n","\n","plt.axis('square')\n","plt.axis([-3,5,-3,5])\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"ycT-Wv9T8VG4"},"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} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_latex.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Intro to LaTeX\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","source":[],"metadata":{"id":"oam9xPYUE_PH"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# import libraries and functions\n","from IPython.display import display,Math"],"metadata":{"id":"wGqBnSO4Ep85"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"qrUd8zubDqJw"},"outputs":[],"source":["# basic latex coding is easy:\n","display(Math('4+5=9'))"]},{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"id":"aSM5LacLDqJw"},"outputs":[],"source":["# special characters are indicated using \\\\\n","display(Math('\\\\sigma = \\\\mu \\\\times \\\\sqrt{5}'))\n","\n","# outside Python, use one \\\n","display(Math('\\\\sigma = \\\\mu \\times \\\\sqrt{5}'))\n","\n","# subscripts and superscripts\n","display(Math('x_n + y^m - z^{m+n}'))\n","\n","# fractions\n","display(Math('\\\\frac{1+x}{2e^{\\pi}}'))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"mOxIWn4zDqJx"},"outputs":[],"source":["# regular text requires a special tag\n","f = 4\n","display(Math('Set x equal to %g'%f))\n","\n","display(Math('\\\\text{Set x equal to %g}'%f))"]},{"cell_type":"markdown","metadata":{"id":"_c_hvVHlDqJx"},"source":["### Latex code in a markdown cell\n","\n","Note: this is not for evaluating variables or other numerical code!\n","\n","\n","$$ \\frac{1+\\sqrt{2x}}{e^{i\\pi}} $$"]},{"cell_type":"code","source":[],"metadata":{"id":"qbRB6HOuEtNo"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"wYA_kJziDqJx"},"source":["# Exercises\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R4u7UpwoDqJx"},"outputs":[],"source":["# 1)\n","display(Math('4x+5y-8z=17'))\n","\n","# 2)\n","display(Math('\\\\sin(2\\\\pi f t+\\\\theta)'))\n","\n","# 3)\n","display(Math('e=mc^2'))\n","\n","# 4)\n","display(Math('\\\\frac{4+5x^2}{(1+x)(1-x)}'))"]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /conics/mathWithPython_conics_hyperbolas.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing conic sections\n","# VIDEO: Graphing hyperbolas\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"rWqnHoXtmREZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rCvqcvyUmREZ"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import sympy as sym\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hCV-phjMmREe"},"outputs":[],"source":["# parameters\n","a = 1\n","b = .5\n","h = 1\n","k = 2\n","\n","# grid space\n","axlim = 2* (np.max((a,b)) + np.max((abs(h),abs(k))))\n","x = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,x)\n","\n","# create the function\n","Fxy = (X-h)**2/a**2 - (Y-k)**2/b**2 - 1\n","\n","# draw it as a contour\n","plt.contour(X,Y,Fxy,0)\n","\n","# draw a dot in the center\n","plt.plot(h,k,'go')\n","\n","# draw guide lines\n","plt.plot([-axlim,axlim],[0,0],'--',color=[.8,.8,.8])\n","plt.plot([0,0],[-axlim,axlim],'k--',color=[.8,.8,.8]) # color overwrites k\n","\n","plt.gca().set_aspect('equal')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"2HsvbSRrn7wi"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Hlc5upETmREe"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"M1XnD_JBmREe"},"outputs":[],"source":["# parameters\n","n = 16\n","a = np.linspace(1,5,n)\n","b = np.linspace(1,5,n)\n","\n","# grid space\n","axlim = 8\n","x = np.linspace(-axlim,axlim,100)\n","y = np.linspace(-axlim,axlim,100)\n","X,Y = np.meshgrid(x,y)\n","\n","for i in range(0,n):\n"," Fxy = X**2/a[i]**2 - Y**2/b[i]**2 - 1\n"," plt.contour(X,Y,Fxy,0,colors=[(i/n,0,i/n)])\n","\n"," Fxy = -X**2/a[i]**2 + Y**2/b[i]**2 - 1\n"," plt.contour(X,Y,Fxy,0,colors=[(0,i/n,i/n)])\n","\n","plt.gca().set_aspect('equal')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"dYWZu_u7mytI"},"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_transpose.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Transposing vectors and matrices\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Zqdzsz9607Yv"},"outputs":[],"source":["r = np.random.randn(1,10)\n","c = np.random.randn(10,1)\n","\n","print(np.shape(r))\n","print(np.shape(c))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"veIzLqPA07Yv"},"outputs":[],"source":["r_flip1 = np.transpose(r)\n","r_flip2 = r.T\n","print(np.shape(r_flip2))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"jc6WZuPD07Yw"},"outputs":[],"source":["# matrix and image\n","mat = np.random.randn(8,4)\n","matT = mat.T\n","\n","fig,ax = plt.subplots(1,2)\n","ax[0].imshow(mat)\n","ax[0].set_title('M')\n","\n","ax[1].imshow(matT)\n","ax[1].set_title('M$^T$')\n","\n","# set common properties\n","for i in ax:\n"," i.set_yticks([])\n"," i.set_xticks([])\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"_d39zidZ3oGF"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"uWSYwjnY07Y2"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Yqk67YGf07Y2"},"outputs":[],"source":["# show that a matrix times its transpose is square-symmetric\n","\n","# sizes\n","m = 10\n","n = 14\n","\n","amat = np.random.randn(m,n)\n","\n","# palindromic variables! (literal and referent!)\n","amatama = amat@amat.T\n","\n","# show it's square\n","print(np.shape(amatama))\n","\n","# show it's symmetric\n","amatama - amatama.T\n","\n","np.is"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_BUGHUNT.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Sympy/latex bug hunt!\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","source":[],"metadata":{"id":"h94PoGWHHRob"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["import sympy\n","import display,Math from IPython.display"],"metadata":{"id":"vTvIXeXvHRin"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7XmAXgHNHKIZ"},"outputs":[],"source":["mu,alpha = sym.symbols('mu,alpha')\n","\n","expr = 2*sym.exp(mu**2/alpha)\n","\n","display(Math( expr ))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"69TNQruQHKIa"},"outputs":[],"source":["Math('1234 + \\frac{3x}{\\sin(2\\pi t+\\theta)}')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3Z8zDvu6HKIa"},"outputs":[],"source":["a = '3'\n","b = '4'\n","\n","# answer should be 7\n","print(sym.sympify(a+b))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NwNjl4wVHKIa"},"outputs":[],"source":["sym.Eq( 4*x = 2 )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Eu42_BPhHKIb"},"outputs":[],"source":["# part 1 of 2\n","\n","q = x^2\n","r = x**2\n","\n","display(q)\n","display(r)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"1rjVfkC6HKIb"},"outputs":[],"source":["# part 2 of 2\n","\n","q,r = sym.symbols('q,r')\n","\n","q = sym.sympify('x^2')\n","r = sym.sympify('x**2')\n","\n","display(q)\n","display(r)\n","\n","sym.Eq(q,r)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HK8JmpraHKIb"},"outputs":[],"source":["x = sym.symbols('x')\n","\n","equation = (4*x**2 - 5*x + 10)**(1/2)\n","display(equation)\n","sym.subs(equation,x,3)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WH5lrsJUHKIb"},"outputs":[],"source":["x,y = sym.symbols('x,y')\n","\n","equation = 1/4*x*y**2 - x*(5*x + 10*Y**2)**(3)\n","display(equation)"]},{"cell_type":"code","source":[],"metadata":{"id":"SiKAZxIZHdXM"},"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} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_unitCircle.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: The unit circle\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"CkKxYUSDW_Q-"},"outputs":[],"source":["# create a unit circle via trigonometry\n","\n","# define the phase angles\n","x = np.linspace(0,2*np.pi,100)\n","\n","# generate the plot\n","plt.plot(np.cos(x),np.sin(x),'k')\n","\n","# draw axis lines\n","plt.plot([-1.3,1.3],[0,0],'--',color=[.8,.8,.8])\n","plt.plot([0,0],[-1.3,1.3],'--',color=[.8,.8,.8])\n","\n","# make it look nicer\n","plt.axis('square')\n","plt.axis([-1.3,1.3,-1.3,1.3])\n","plt.xlabel('cosine(x)')\n","plt.ylabel('sine(x)')\n","plt.plot()\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"q7qSgWI6W_Q-"},"outputs":[],"source":["# draw the circle again\n","plt.plot(np.cos(x),np.sin(x),'k')\n","\n","# now draw a vector\n","angle = np.pi/4\n","plt.plot([0,np.cos(angle)],[0,np.sin(angle)],'r',linewidth=3)\n","\n","# make it look nicer\n","plt.axis('square')\n","plt.xlabel('cosine(x)')\n","plt.ylabel('sine(x)')\n","plt.axis([-1.3,1.3,-1.3,1.3])\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"6GM8ZC6beYMo"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"WeJg5v68W_Q-"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"OgIThtvuW_Q-"},"outputs":[],"source":["# something with log-space increases in angle\n","x = np.linspace(-3,1.83,50)\n","a = np.exp(x)\n","\n","for i in a:\n"," plt.plot([0,np.cos(i)],[0,np.sin(i)])\n","\n","\n","# make it look nicer\n","plt.axis('square')\n","plt.axis('off')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /dataTypes/mathWithPython_datatypes_numbersStrings.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Data types\n","# VIDEO: Numbers and strings\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"VImTkYhdcyD3"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"akAUrrHZcyD4"},"outputs":[],"source":["# libraries\n","import numpy as np"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"BUGh4H9ucyD4"},"outputs":[],"source":["# ints vs. floats\n","\n","c = 7\n","d = 7.0\n","\n","print(c,d)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bXlcPgZTcyD4"},"outputs":[],"source":["print( type(c) )\n","print( type(d) )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FvQJzT3gcyD4"},"outputs":[],"source":["# implication of datatype for functions loops\n","\n","for i in range(c): # vs d\n"," print(i)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TrDxrBUQcyD4"},"outputs":[],"source":["# we can add numbers; can we \"add\" strings??\n","firstName = 'Mike'\n","lastName = 'Cohen'\n","\n","print( firstName + lastName )\n","print( firstName + ' ' + lastName )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_hzu-QZ5cyD4"},"outputs":[],"source":["firstName * 3"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"d7TjCbnVcyD4"},"outputs":[],"source":["%whos"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Y78PZBjncyD4"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":{"id":"C3YY5T1bcyD4"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"IYO8pNHWcyD5"},"outputs":[],"source":["### converting across datatypes\n","\n","s1 = '4'\n","s2 = '4.7'\n","n1 = 5\n","n2 = 5.8\n","\n","## convert strings to integers\n","print( int(s1) )\n","# print( int(s2) )\n","\n","\n","## string to floating-point\n","print( float(s1) )\n","print( float(s2) )\n","\n","\n","## number to string\n","print( str(n1) )\n","print( str(n2) )\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"66YxWjdbcyD6"},"outputs":[],"source":[]}],"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_specialMatrices.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Various special matrices\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6wCxAYO307Y2"},"outputs":[],"source":["# identity\n","I = np.eye(4)\n","print(I)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"91gnGpNw07Y2"},"outputs":[],"source":["# zeros\n","Z = np.zeros((5,5))\n","print(Z)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"E8P562Nt07Y3"},"outputs":[],"source":["# diagonal\n","D = np.diag([1,3,2,4,5])\n","print(D)\n","d = np.diagonal(D)\n","print(d)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GbaW1nnD07Y3"},"outputs":[],"source":["# triangular matrix\n","T = np.random.randn(15,15)\n","\n","plt.imshow(np.triu(T))\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"rHsjZ3zv4P7x"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"SOR5APGC07Y3"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RBfawuT207Y3"},"outputs":[],"source":["# matrix of random integers\n","intmat = np.random.randint(-4,5,(4,4))\n","I4 = np.eye(4)\n","upper4 = np.triu(np.random.randn(4,4))\n","\n","print(intmat.dtype)\n","print('\\n\\n')\n","print((intmat@I4).dtype)\n","print('\\n\\n')\n","print(intmat@upper4)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R9u_CxYa07Y3"},"outputs":[],"source":["# figure out what a Toeplitz matrix is\n","from scipy.linalg import toeplitz\n","\n","v = np.arange(1,6)\n","toe = toeplitz(v)\n","\n","print(toe)\n","\n","plt.imshow(toe)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_inverse.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Matrix inverse\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"zYRTmPTr07Y3"},"outputs":[],"source":["# random matrices are nearly always invertible\n","\n","m = 5\n","\n","A = np.random.randint(-5,6,(m,m))\n","Ainv = np.linalg.inv(A)\n","\n","fig,ax = plt.subplots(1,3)\n","\n","ax[0].imshow(A)\n","ax[0].set_title('A')\n","\n","ax[1].imshow(Ainv)\n","ax[1].set_title('A$^{-1}$')\n","\n","ax[2].imshow(A@Ainv)\n","ax[2].set_title('AA$^{-1}$')\n","\n","for i in ax:\n"," i.axis('off')\n","\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"qSIwN8su07Y3"},"outputs":[],"source":["# also no inverse for square matrix with repeated columns\n","\n","A = np.random.randint(-5,6,(m,m))\n","A[:,0] = A[:,1]\n","print(A)\n","\n","Ainv = np.linalg.inv(A)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"St-YN6QX4ehm"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Meufd7O607Y3"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"KVJT2WsQ07Y3"},"outputs":[],"source":["# pinv with repeated column in square matrix, and with non-square matrix\n","m = 5\n","A = np.random.randint(-5,6,(m,m))\n","A[:,0] = A[:,1]\n","print(A)\n","\n","# A = np.random.randn(m,m+2)\n","\n","# compute pseudo-inverse\n","Ainv = np.linalg.pinv(A)\n","\n","fig,ax = plt.subplots(1,3)\n","\n","ax[0].imshow(A)\n","ax[0].set_title('A')\n","\n","ax[1].imshow(Ainv)\n","ax[1].set_title('A$^{*}$')\n","\n","ax[2].imshow(A@Ainv)\n","ax[2].set_title('AA$^{*}$')\n","\n","for i in ax:\n"," i.axis('off')\n","\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /numberTheory/mathWithPython_numTheory_perfect.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Number theory\n","# VIDEO: Counting perfect numbers\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"JL_0UKJOj1YP"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NYtF0SBKRXBE"},"outputs":[],"source":["# From https://en.wikipedia.org/wiki/Perfect_number:\n","# \"A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself.\"\n","\n","\n","# create a function that tests whether the input is a perfect number\n","def test4perfect(number):\n","\n"," # initialize\n"," divisors = []\n","\n"," # find integer divisors\n"," for d in range(1,number):\n"," if number%d == 0:\n"," divisors.append(d)\n","\n"," # test for equality\n"," return sum(divisors)==number"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"1K1V4k58uRBp"},"outputs":[],"source":["test4perfect(30)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3GshFtY1uGUS"},"outputs":[],"source":["perfect = []\n","\n","for number in range(2,10001):\n"," if test4perfect(number):\n"," perfect.append(number)\n","\n","print(perfect)"]},{"cell_type":"code","source":[],"metadata":{"id":"qZ7jqqU-ndQV"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"S7MsydfFJHhG"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"M1l1tkTrHtgO"},"outputs":[],"source":["# implement the function as a list-comprehension\n","\n","def test4perfect(number):\n"," return number == sum([d for d in range (1,number) if number%d==0])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"vb2bWZUhHtgO"},"outputs":[],"source":["## list comprehension intro\n","\n","# as a loop\n","lst = []\n","for i in range(10):\n"," lst.append(i**2)\n","\n","# as list comprehension\n","lst2 = [i**2 for i in range(10)]\n","\n","print(lst)\n","print(lst2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PYS-dL_s3zFT"},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"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"}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_factoringPolys.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Factoring polynomials\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"B3urVuF1eQ8K"},"outputs":[],"source":["x,y = sym.symbols('x,y')\n","\n","po = x**2 + 4*x + 3\n","sym.factor(po)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6e5fa5RBeQ8K"},"outputs":[],"source":["# with output\n","\n","fac = sym.factor(po)\n","print(fac)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GQBY8oc_eQ8K"},"outputs":[],"source":["# not every polynomial can be factored!\n","po = x**2 + 4*x - 3\n","\n","sym.factor(po)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"v-_6BeGGeQ8K"},"outputs":[],"source":["expr = 2*y**3 - 2*y**2 - 18*y + 18\n","sym.factor(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"51OMm-fheQ8K"},"outputs":[],"source":["# multiple variables\n","expr = 2*x**3*y - 2*x**2*y**2 + 2*x**2*y + 6*x**2 - 6*x*y + 6*x\n","sym.factor(expr)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"6dOM9ErP3keR"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"QcVGgtpheQ8K"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ahMGuSCxeQ8K"},"outputs":[],"source":["# test whether factorable, print if so.\n","\n","exprs = [ x**2+4*x+3 , 2*y**2-1 , 3*y**2+12*y ]\n","\n","for expri in exprs:\n"," tmp = str( sym.factor(expri) )\n","\n"," if tmp.find('(')!=-1:\n"," display(Math('%s \\\\quad\\\\Rightarrow\\\\quad %s' %(sym.latex(sym.expand(expri)),sym.latex(sym.factor(expri)))))\n"," else:\n"," display(Math('%s \\\\quad\\\\Rightarrow\\\\quad\\\\text{ not factorable!}' %sym.latex(sym.expand(expri))))\n"]},{"cell_type":"code","source":[],"metadata":{"id":"p9cemxf72v0q"},"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} -------------------------------------------------------------------------------- /calculus/mathWithPython_calc_integrals.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Calculus\n","# VIDEO: Indefinite and definite integrals\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"EqH-SLvsbLCk"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import matplotlib.pyplot as plt\n","import numpy as np\n","from scipy.signal import find_peaks\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oWrjNcf2bLCk"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"R9taEoGdbLCw"},"outputs":[],"source":["x = sym.symbols('x')\n","\n","# a simple function\n","f = x\n","\n","# indefinite integration\n","sym.integrate(f) # notice no constant term"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7qH6pxX_bLCx"},"outputs":[],"source":["# definite integation (within bounds)\n","sym.integrate(f,(x,0,1))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"XNyqMkPYbLCx"},"outputs":[],"source":["# plotting...\n","\n","lowbnd = 2 # add later\n","\n","f = x**3 / (x-lowbnd)\n","intf = sym.integrate(f)\n","p = sym.plotting.plot(f,show=False)\n","p.extend( sym.plotting.plot(intf,(x,2.1,10),show=False,line_color='r') )\n","\n","p.xlim = [-10,10]\n","p.ylim = [-200,200]\n","\n","p[0].label = '$f(x)$'\n","p[1].label = '$\\\\int f(x)dx$'\n","p.legend = True\n","p.show()\n","\n","display(Math('f(x) = %s' %sym.latex(f)))\n","display(Math('\\\\int f(x) dx = %s' %sym.latex(intf)))"]},{"cell_type":"code","source":[],"metadata":{"id":"uo6klg-eeQdM"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"PNeaaY8SbLCx"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"mZ9aTzy7bLCx"},"outputs":[],"source":["# show that the antiderivative (indefinite integral) of the derivative is the original function\n","\n","f = 2*x**3 + sym.sin(x)\n","\n","df = sym.diff(f)\n","idf = sym.integrate(df)\n","\n","display(Math('f(x)=%s' %sym.latex(f)))\n","display(Math('f\\'=%s' %sym.latex(df)))\n","display(Math('\\\\int (f\\')dx=%s' %sym.latex(idf)))"]},{"cell_type":"code","source":[],"metadata":{"id":"JZzgnF5nbWl-"},"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} -------------------------------------------------------------------------------- /conics/mathWithPython_conics_parabola.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Graphing conic sections\n","# VIDEO: Graphing parabolas\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"rWqnHoXtmREZ"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rCvqcvyUmREZ"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import sympy as sym\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fsf1NqhomREa"},"outputs":[],"source":["# parameters\n","n = 100\n","a = 1\n","h = 1\n","k = -2\n","\n","# x-axis points to evaluate the function\n","x = np.linspace(-2,4,n)\n","\n","# create the function\n","y = a*(x-h)**2 + k\n","\n","# and plot it!\n","plt.plot(x,y)\n","plt.grid()\n","plt.axis('square')\n","plt.show()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3n0girh2mREa"},"outputs":[],"source":["# parameters\n","n = 100\n","a = 1\n","h = 1\n","k = -2\n","\n","# x-axis points to evaluate the function\n","x = np.linspace(-2,4,n)\n","\n","# create the function\n","y = a*(x-h)**2 + k\n","\n","# and plot it!\n","plt.plot(y,x)\n","\n","plt.grid()\n","plt.axis('square')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"tZ47v-p8mrhT"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"J7xBUCSBmREa"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DXdOrEB_mREb"},"outputs":[],"source":["# draw the vertex, focus, and directrix\n","\n","x = np.linspace(-6,6,40)\n","y = (x-2)**2/2 + 1\n","\n","# 1) convert to standard parabola equation\n","# 4*p*(y-k) = (x-h)**2\n","# 2) write standard equation\n","h = 2\n","k = 1\n","p = 1/2 # 2=4p\n","\n","\n","# plot the parabola\n","plt.plot(x,y,label='Parabola')\n","\n","# plot the vertex\n","plt.plot(h,k,'ro',label='Vertex')\n","\n","# plot the focus\n","plt.plot(h,k+p,'go',label='focus')\n","\n","# plot the directrix\n","d = k-p\n","plt.plot(x[[0,-1]],[d,d],label='directrix')\n","\n","plt.legend()\n","plt.axis('square')\n","plt.axis([x[0],x[-1],d-.5,10])\n","plt.grid()\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"ogdFue1LmumV"},"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} -------------------------------------------------------------------------------- /numberTheory/mathWithPython_numTheory_numberSeqs.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Number theory\n","# VIDEO: Plotting number sequences\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"JL_0UKJOj1YP"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"II1kBlVORp9M"},"outputs":[],"source":["# initialize\n","s1 = np.array([])\n","s2 = np.array([])\n","s3 = np.array([])\n","s4 = np.array([])\n","xx = np.arange(1,81)\n","\n","\n","# generate the sequences\n","for n in xx:\n"," s1 = np.append(s1,n/(n+1))\n"," s2 = np.append(s2,(n+1)/n)\n"," s3 = np.append(s3,n/sum(np.arange(1,n+1)))\n"," s4 = np.append(s4,(-1)**n/np.sqrt(n))\n","\n","\n","# plotting\n","fig,ax = plt.subplots(1,figsize=(10,7))\n","plt.plot(xx,s1,label='$a/(a+1)$')\n","plt.plot(xx,s2,label='$(a+1)/a$')\n","plt.plot(xx,s3,label='$a/\\Sigma(a)$')\n","plt.plot(xx,s4,label='$-1^a/\\sqrt{a}$')\n","plt.legend(loc='upper right',fontsize=16)\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"utMhyJh-zNFz"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":{"id":"JtQstBsu0xZT"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"kqtdrJReHtgR"},"outputs":[],"source":["# The series above are all convergent. Create a divergent series."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-Mc7_vRxHtgR"},"outputs":[],"source":["# repeat without a for-loop!\n","\n","# the a's\n","aSeq = np.arange(1,N)\n","\n","# the sequences\n","s1 = aSeq/(aSeq+1)\n","s2 = (aSeq+1)/aSeq\n","s3 = aSeq/np.cumsum(aSeq)\n","s4 = (-1)**aSeq/np.sqrt(aSeq)\n","\n","# examples of divergent sequences\n","# s3 = np.cumsum(aSeq)/aSeq\n","# s4 = np.sqrt(aSeq)/(-1)**aSeq\n","\n","# plotting\n","fig,ax = plt.subplots(1,figsize=(10,7))\n","plt.plot(xx,s1,label='$a/(a+1)$')\n","plt.plot(xx,s2,label='$(a+1)/a$')\n","plt.plot(xx,s3,label='$a/\\Sigma(a)$')\n","plt.plot(xx,s4,label='$-1^a/\\sqrt{a}$')\n","plt.legend(loc='upper right',fontsize=16)\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PYS-dL_s3zFT"},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"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"}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_BUGHUNT.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Algebra 1 bug hunt!\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"Cpw7Jeuj31m6"},"outputs":[],"source":["from sympy.abc import x2\n","\n","x2 = 4\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"CESOUkmv31m7"},"outputs":[],"source":["a,b,c = sym.symbols('a,b,c')\n","\n","expr = 4*b + 5*a*a - c**3 + 5*d\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"mEA2gMc231m7"},"outputs":[],"source":["import math\n","gcd(30,50)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cQqbp0aO31m7"},"outputs":[],"source":["expr = 4*x - 8\n","solve(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"kSGSbcd431m7"},"outputs":[],"source":["import numpy as np\n","\n","A = np.array( [ [1,2],[3,4] ] )\n","# make it look nice\n","A"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"IERHa59i31m7"},"outputs":[],"source":["fact_dict = sym.factorint(44)\n","allkeys = fact_dict.keys()\n","\n","for i in range(0,len(allkeys)):\n","print('%g was present %g times.' %(i,allkeys[i]))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"npoGOsUt31m7"},"outputs":[],"source":["x,y = sym.symbols('x,y')\n","\n","expr = 4*x - 5*y**2\n","\n","expr.subs({x=5})\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iIJbtLZw31m7"},"outputs":[],"source":["# goal is to show a fraction\n","\n","f = 5/9\n","\n","display(Math(sym.latex(f)))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"eoTNxKvV31m7"},"outputs":[],"source":["# print the last 3 items from a list\n","lst = [1,3,2,5,4,6,7,5,3,7]\n","lst[-3:-1]\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"McsL65rR31m7"},"outputs":[],"source":["from sympy.abc import x,y\n","\n","expr = 2*x + 4*y\n","\n","# solve for y\n","sym.solve(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ebQ2ko8k31m7"},"outputs":[],"source":["import numpy as np\n","\n","A = np.array( [ [1,2],[3,4] ] )\n","\n","# set the element in the second row, second column to 9\n","A[2,2] = 9\n","print(A)"]},{"cell_type":"code","source":[],"metadata":{"id":"R0Mb_kvm4C4g"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_matrices.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Creating and accessing matrices with numpy\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RwUSDJIQeQ75"},"outputs":[],"source":["A = np.array( [ [1,2],[3,4] ] )\n","print(A)\n","\n","# make it look nicer\n","display(Math(sym.latex(sym.sympify(A))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"BGX8-8woeQ75"},"outputs":[],"source":["# initializing a matrix with zeros\n","\n","numrange = range(0,5)\n","\n","mat = np.zeros([len(numrange),len(numrange)])\n","print(mat)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6aeNpJTleQ75"},"outputs":[],"source":["# populating matrices using row-col indexing\n","\n","mat[0,1] = 1\n","# mat[5,8] = 4\n","mat"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6OHgTjxkeQ75"},"outputs":[],"source":["# can also use variables for indices\n","i = 2\n","j = 1\n","mat[i,j] = 4.5\n","\n","display(Math(sym.latex(sym.sympify(mat))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7fQxHxQ7eQ75"},"outputs":[],"source":["# now use a for-loop\n","\n","numrange = range(0,3)\n","for i in numrange:\n"," for j in numrange:\n"," mat[i][j] = (-1)**(i+j)\n","\n","mat"]},{"cell_type":"code","source":[],"metadata":{"id":"LsGVBDPtuYla"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"almJ3hlXeQ75"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LqL_qOvbeQ75"},"outputs":[],"source":["x,y = sym.symbols('x y')\n","Fxy = (4+x)*(2-y)\n","\n","numrange = range(0,3)\n","\n","funout = np.zeros((len(numrange),len(numrange)))\n","\n","for i in numrange:\n"," for j in numrange:\n"," funout[i,j] = Fxy.subs({x:i,y:j})\n","\n","display(Math(sym.latex(sym.sympify(funout))))"]},{"cell_type":"code","source":[],"metadata":{"id":"2cwjGqBUuhxQ"},"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} -------------------------------------------------------------------------------- /algebra_1/mathWithPython_algebra1_addPolys.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Adding polynomials\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"LEQYG7eGeQ70"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AsnYF03SeQ71"},"outputs":[],"source":["# import libraries\n","import sympy as sym\n","import numpy as np\n","from IPython.display import display, Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UhinVt6reQ8I"},"outputs":[],"source":["from sympy.abc import x\n","\n","# straight-forward version\n","p1 = 2*x**3 + x**2 - x\n","p2 = x**3 - x**4 - 4*x**2\n","print( p1+p2 )\n","\n","display(Math('(%s) + (%s) \\quad=\\quad (%s)' %(sym.latex(p1),sym.latex(p2),sym.latex(p1+p2) )))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"2XocdVBWeQ8I"},"outputs":[],"source":["# Using the Poly class\n","p1 = sym.Poly(2*x**6 + x**2 - x)\n","\n","p1"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oEtBQWUfeQ8I"},"outputs":[],"source":["# can implement several methods on the polynomial object\n","print( p1.eval(10) )\n","\n","print( p1.degree() )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"tGn2O5W8eQ8I"},"outputs":[],"source":["# create a second polynomial\n","p2 = sym.Poly(x**3 - x**4 - .4*x**2)\n","print( p1-p2 )\n","\n","# can also call the add method on the polynomial objects\n","p1.add(p2)\n","p1.sub(p2)\n","print(p1.sub(p2))\n","print(p1)\n"]},{"cell_type":"code","source":[],"metadata":{"id":"d-Fvdyw22n23"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Jqlims2aeQ8I"},"source":[" Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"T1A1LNIJeQ8I"},"outputs":[],"source":["# create a list of polynomials\n","# loop through. if order is even, sum the coeffs. if order is odd, count the number of coeffs\n","\n","polys = [ sym.Poly(2*x + x**2), sym.Poly(-x**3 + 4*x), sym.Poly(x**5-x**4+1/4*x+4) ]\n","\n","for poli in polys:\n"," if poli.degree()%2==0:\n"," print('The degree of %s is even, and the coefficients sum to %s.' %(poli.as_expr(),sum(poli.coeffs())))\n"," else:\n"," print('The degree of %s is odd, and there are %s coefficients.' %(poli.as_expr(),len(poli.coeffs())))"]}],"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} -------------------------------------------------------------------------------- /numberTheory/mathWithPython_numTheory_EuclidTriplets.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Number theory\n","# VIDEO: Euclid's Pythagorean triplets\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"JL_0UKJOj1YP"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym"]},{"cell_type":"markdown","metadata":{"id":"qCq5Dnp_Rnvm"},"source":["# Euclid's Pythagorean triplets\n","\n","$a=m^{2}-n^{2}\\\\\n","b=2mn\\\\\n","c=m^{2}+n^{2}\\\\\n","m>n$\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"qkkTllfibgom"},"outputs":[],"source":["# specify range of numbers\n","numberrange = np.arange(2,51)\n","\n","# initialize empty lists\n","a = []\n","b = []\n","c = []\n","\n","for m in numberrange:\n"," for n in numberrange:\n"," a.append( m**2 - n**2 )\n"," b.append( 2*m*n )\n"," c.append( m**2 + n**2 )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"tSYcX3G_o1Dz"},"outputs":[],"source":["fig,ax = plt.subplots(1,figsize=(10,7))\n","plt.scatter(a,b,c=c, marker='o',alpha=.5,linewidths=.5,edgecolors='k')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_lePYQjFwkPM"},"outputs":[],"source":["check = np.array(a)**2 + np.array(b)**2 - np.array(c)**2\n","\n","plt.plot(check,'o')\n","plt.ylabel('$y \\quad = \\quad a^2+b^2-c^2$')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"p3D0pJBFzFFv"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":{"id":"h62n_sWCAlZR"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9x7cpwVnHtgP"},"outputs":[],"source":["# the code written above does not strictly conform to the equations. Find what's wrong and fix it!"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"EtUzR2cWHtgP"},"outputs":[],"source":["# initialize empty lists\n","a = []\n","b = []\n","c = []\n","\n","for m in numberrange:\n"," for n in range(numberrange[0],m):\n"," a.append( m**2 - n**2 )\n"," b.append( 2*m*n )\n"," c.append( m**2 + n**2 )\n","\n","fig,ax = plt.subplots(1,figsize=(7,7))\n","plt.scatter(a,b,c=c, marker='o',alpha=.5,linewidths=.5,edgecolors='k')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PYS-dL_s3zFT"},"outputs":[],"source":[]}],"metadata":{"colab":{"provenance":[]},"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"}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_unity.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Graphing the complex roots of unity\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"A4WKF4x6W_Q_"},"outputs":[],"source":["# confirm that the roots of unity produce 1\n","\n","n = 5\n","for k in range(n):\n"," root = sym.exp( (2*k*sym.pi*sym.I)/n )\n"," display(Math('%s \\\\Rightarrow %s' %(sym.latex(root),sym.latex(root**n) )))\n","\n","\n","# print(roots)\n","# print(np.real(np.prod(roots)))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"xEn3vFu6W_Q_"},"outputs":[],"source":["# parameter for number of roots to show\n","n = 6\n","\n","for k in range(n):\n","\n"," # compute this root\n"," root = np.exp( (2*k*np.pi*1j)/n )\n","\n"," # plot it\n"," plt.plot([0,np.real(root)],[0,np.imag(root)],linewidth=3)\n","\n","\n","# generate the plot with the unit circle on top\n","x = np.linspace(0,2*np.pi,100) # copied from previous lecture!\n","plt.plot(np.cos(x),np.sin(x),color='gray')\n","\n","# draw axis lines\n","plt.plot([-1.3,1.3],[0,0],'--',color='gray')\n","plt.plot([0,0],[-1.3,1.3],'--',color='gray')\n","\n","\n","# make the plot look nicer\n","plt.axis([-1.3,1.3,-1.3,1.3])\n","plt.axis('square')\n","plt.axis('off')\n","plt.title('The %g %gth roots of 1' %(n,n))\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"Yli-cSiGfeva"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Gy7giQk-W_Q_"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"MIiWYo4EW_Q_"},"outputs":[],"source":["# parameter for number of roots to show\n","n = 200\n","\n","color = np.linspace(0,.9,n)\n","\n","for k in range(0,n):\n","\n"," # compute this root\n"," root = k*np.exp( (2*k*np.pi*1j)/n )\n","\n"," # plot it\n"," plt.plot([0,np.real(root)],[0,np.imag(root)],linewidth=2,color=[color[k],color[k],color[k]])\n","\n","# make the plot look nicer\n","plt.axis('square')\n","plt.axis('off')\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_powers.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Exponents (powers)\n","# VIDEO: Addition, subtraction, multiplication, division\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","source":[],"metadata":{"id":"L1AfFfpIxwcm"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"VygXElpHqgu9"},"outputs":[],"source":["# use **\n","3**2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"3drcpuTxqgu9"},"outputs":[],"source":["# careful not to confuse with ^\n","3^1\n","# this is actually the symbol for the XOR logical problem"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iZYz0KMzqgu9"},"outputs":[],"source":["# variables can also be useful\n","x = 2\n","3**x"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bsC02V-nqgu9"},"outputs":[],"source":["# Note about importing functions or modules: You need to do this only once per session.\n","# Thus, you don't need the following line if you've already imported these functions.\n","# On the other hand, it doesn't hurt to import multiple times ;)\n","from IPython.display import display, Math\n","\n","\n","# using the print function\n","print( 2**x )\n","\n","# print out the whole equation\n","display(Math('x^%g = %g'%(x,2**x)))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"9a_bWJj1qgu9"},"outputs":[],"source":["# the law of exponents\n","print(3**3)\n","print(3*3*3)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"92cxzu8Rqgu9"},"outputs":[],"source":["print( 3**2 * 3**4 )\n","print( 3**(2+4) )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cr-bEq8xqgu9"},"outputs":[],"source":["# square root as fractional power\n","x**(1/2)"]},{"cell_type":"code","source":[],"metadata":{"id":"M_Q_SJba1GuI"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"WosHgonzqgu9"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZAdrc7APqgu9"},"outputs":[],"source":["x = 5\n","y = 5.1\n","\n","# 1)\n","ans = x**(3/4) * 4**y\n","display(Math('x^{3/4}\\\\times 4^y = %g'%ans))\n","\n","# 2)\n","solution = (3**3) / (x**y)\n","display(Math('\\\\frac{3^3}{x^y} = %g'%solution))\n","\n","# 3)\n","ans = 10**(x-4)\n","display(Math('10^{x-4} = %g'%ans))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /trigonometry/mathWithPython_trig_bugHunt.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Trigonometry\n","# VIDEO: Trigonometry BUG HUNT! (This is the file with bugs to 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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"jsDZ0OvmIdl4"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"oU50WzZcIdl9"},"outputs":[],"source":["# plot a series of random numbers\n","s = np.randn(100,1)\n","plt.imshow(s)\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"J07f34A5Idl-"},"outputs":[],"source":["# create and image a matrix of random integers between (and including) 3 and 20\n","\n","mat = np.random.randint(3,20,30,20)\n","\n","plt.imshow(mat)\n","plt.colorbar()\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-KBqoOcoIdl-"},"outputs":[],"source":["# create 100 random phase angles [0,2pi] and show unit vectors with those angles\n","\n","n = 100\n","\n","randphases = np.random.rand(n)+2*pi\n","\n","for i in range(0,n):\n"," plt.polar(randphases[i],1,'o',color=np.random.rand(3),markersize=20,alpha=.3)\n","\n","plt.show()\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Jfec_Bp4Idl_"},"outputs":[],"source":["# create an outwards spiral using phase angles and amplitudes\n","\n","n = 100\n","a = np.linspace(0,1,n)\n","p = np.linspace(0,4*np.pi,n)\n","\n","plt.plot(p,A);"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HBeRaNLAIdl_"},"outputs":[],"source":["# convert radians to degrees\n","\n","n = 10\n","rad = np.logspace(np.log10(1),np.log10(360),n)\n","\n","print(np.rad2deg(rad))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DC47AjA-IdmA"},"outputs":[],"source":["# famous equality in trigonometry\n","\n","ang = np.logspace(np.log10(0),np.log10(2*np.pi),10)\n","np.cos(ang)*2 + np.sin(ang)*2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"CspikT63IdmA"},"outputs":[],"source":["# create euler's number\n","p = np.pi/4\n","m = .5\n","\n","eulr = 1j*np.exp(m*p)\n","\n","# now extract magnitude and phase\n","mag = np.abs(eulr)\n","ang = np.angle(eulr)\n","\n","# then plot\n","plt.polar([0,mag],[0,ang],'b',linewidth=3)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"LZKqdcY-IzAW"},"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} -------------------------------------------------------------------------------- /linearAlgebra/mathWithPython_linalg_vectors.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Linear algebra\n","# VIDEO: Row and column vectors\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"6AEPghK807Yo"},"outputs":[],"source":["# import libraries\n","import numpy as np\n","import matplotlib.pyplot as plt\n","import sympy as sym\n","from IPython.display import display,Math"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"rvbcAgx807Yn"},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"77wLf8iO07Yq"},"outputs":[],"source":["row_vec = np.array([4,2])\n","col_vec = np.array([ [-2], [3] ])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6H1ZCKOt07Yq"},"outputs":[],"source":["display(Math(sym.latex(sym.sympify(row_vec))))\n","display(Math(sym.latex(sym.sympify(col_vec))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"W3xtQPQB07Yq"},"outputs":[],"source":["# check out the sizes\n","print(np.shape(row_vec))\n","print(np.shape(col_vec))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"reMgKsjy07Yr"},"outputs":[],"source":["plt.plot([0,row_vec[0]],[0,row_vec[1]],'r',label='row vector')\n","plt.plot([0,col_vec[0]],[0,col_vec[1]],'b',label='column vector')\n","\n","plt.axis('square')\n","plt.axis([-5,5,-5,5])\n","plt.grid()\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"F6uKBm1K1kTJ"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"T52T-Fp-07Ys"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RCoSv_xf07Ys"},"outputs":[],"source":["# import 3d plotting tools\n","from mpl_toolkits.mplot3d import Axes3D\n","\n","\n","v3_1 = np.array([3,0,-4])\n","v3_2 = np.array([-1,1,3])\n","\n","fig = plt.figure(figsize=plt.figaspect(1))\n","ax = fig.add_subplot(111, projection='3d')\n","\n","# draw vectors\n","ax.plot([0,v3_1[0]],[0,v3_1[1]],[0,v3_1[2]],'b',linewidth=3)\n","ax.plot([0,v3_2[0]],[0,v3_2[1]],[0,v3_2[2]],'r',linewidth=3)\n","\n","# guidelines\n","ax.plot([-5,5],[0,0],[0,0],'--',color=[.7,.7,.7])\n","ax.plot([0,0],[-5,5],[0,0],'--',color=[.7,.7,.7])\n","ax.plot([0,0],[0,0],[-5,5],'--',color=[.7,.7,.7])\n","\n","ax.set_xlim3d(-5,5)\n","ax.set_ylim3d(-5,5)\n","ax.set_zlim3d(-5,5)\n","plt.show()"]},{"cell_type":"code","source":[],"metadata":{"id":"xUZs3qV81HJv"},"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} -------------------------------------------------------------------------------- /arithmetic/mathWithPython_arithmetic_variables.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Arithmetic\n","# VIDEO: Using variables in place of numbers\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":["\n"," \"Open\n",""],"metadata":{"id":"QRoA_ygRwI5_"}},{"cell_type":"code","source":[],"metadata":{"id":"pJ8Flm61vlHq"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["# Basic variable usage"],"metadata":{"id":"6Ia-TZ9Mvlti"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"gOzJOsppqgu5"},"outputs":[],"source":["# create a variable by assigning a number to it\n","x = 17"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HjsRaecKqgu5"},"outputs":[],"source":["# then use that variable in place of a number\n","x - 2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fXlVIPPgqgu5"},"outputs":[],"source":["# you can re-assign variables whenever you need to\n","x = 10\n","# note that nothing prints out to the screen here.\n","# We didn't ask Python to compute anything, just to set a variable."]},{"cell_type":"code","execution_count":null,"metadata":{"id":"gz-0r34Fqgu5"},"outputs":[],"source":["# you can even use a variable to reassign itself!\n","x = x-2*5\n","x"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ngNNaOZRqgu5"},"outputs":[],"source":["# multiple variables can be really useful\n","x = 10\n","y = 20\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cCT9UXCBqgu5"},"outputs":[],"source":["x + y*z # can't use a variable before it's created!"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"1KftWStHqgu5"},"outputs":[],"source":["z = 30\n","x + y*z"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"BAVszNfKqgu5"},"outputs":[],"source":["# only the final line of code will print out an answer;\n","# otherwise, you can use the print() function\n","\n","40+10\n","\n","50+3\n","\n","print(40+3)\n","print(10+6)"]},{"cell_type":"code","source":[],"metadata":{"id":"_tRP9RP0vn3G"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"YfGPixtDqgu5"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"mt6n_CGmqgu5"},"outputs":[],"source":["# 1)\n","x = 7\n","y = -2\n","z = 5\n","\n","# 1)\n","3*x*(4+y)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Or7z5rTOqgu5"},"outputs":[],"source":["# 2)\n","-y - (x+3)/z"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SoO689fhqgvB"},"outputs":[],"source":[]}],"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.0"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_logprops.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Logarithm properties: Multiplication and division\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"3PT2TFxnW_RA"},"outputs":[],"source":["a = 3\n","b = 4\n","\n","# test the multiplication rule\n","\n","res1 = np.log(a*b)\n","res2 = np.log(a) * np.log(b)\n","res3 = np.log(a) + np.log(b)\n","\n","display(Math('\\\\log(%g\\\\times%g) = %g' %(a,b,res1)))\n","display(Math('\\\\log(%g)\\\\times\\\\log(%g) = %g' %(a,b,res2)))\n","display(Math('\\\\log(%g)+\\\\log(%g) = %g' %(a,b,res3)))\n","\n","display(Math('\\\\log(%g\\\\times%g) \\\\neq \\\\log(%g)\\\\times\\\\log(%g)' %(a,b,a,b)))\n","display(Math('\\\\log(%g\\\\times%g) = \\\\log(%g)+\\\\log(%g)' %(a,b,a,b)))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cMJ7lGJVW_RA"},"outputs":[],"source":["# repeat for division\n","\n","res1 = np.log(a/b)\n","res2 = np.log(a) / np.log(b)\n","res3 = np.log(a) - np.log(b)\n","\n","display(Math('\\\\log(\\\\frac{%g}{%g}) = %g' %(a,b,res1)))\n","display(Math('\\\\log(%g)/\\\\log(%g) = %g' %(a,b,res2)))\n","display(Math('\\\\log(%g)-\\\\log(%g) = %g' %(a,b,res3)))\n","\n","display(Math('\\\\log{\\\\left(\\\\frac{%g}{%g}\\\\right)} \\\\neq \\\\frac{\\\\log(%g)}{\\\\log(%g)}' %(a,b,a,b)))\n","display(Math('\\\\log{\\\\left(\\\\frac{%g}{%g}\\\\right)} = \\\\log(%g)-\\\\log(%g)' %(a,b,a,b)))\n"]},{"cell_type":"code","source":[],"metadata":{"id":"lKGy0P31gQzC"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"RMdPAq2SW_RA"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"yBjTGne8W_RA"},"outputs":[],"source":["# exponential rule\n","\n","expr1 = np.log(a**b)\n","expr2 = b*np.log(a)\n","\n","print(expr1-expr2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"feMEsDbzW_RA"},"outputs":[],"source":["expr1 = np.log(3**3)\n","expr2 = 3*np.log(3)\n","expr3 = np.log(3) + np.log(3) + np.log(3)\n","\n","print(expr1,expr1-expr2,expr1-expr3)"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /sympyLatex/mathWithPython_sympyLatex_sympy2.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"dHFgBhPpsNGI"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Introduction to Sympy and Latex\n","# VIDEO: Intro to sympy, part 2\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":["\n"," \"Open\n",""],"metadata":{"id":"knNYsQTDx0V0"}},{"cell_type":"code","source":[],"metadata":{"id":"KlYyRsU1FNOo"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["# import libraries\n","import sympy as sym\n","from IPython.display import display,Math"],"metadata":{"id":"I4C34qT7FMw7"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-RfLBY5iDqJx"},"outputs":[],"source":["# using Greek characters as variable names\n","\n","mu,alpha,sigma = sym.symbols('mu,alpha,sigma')\n","\n","expr = sym.exp( (mu-alpha)**2/ (2*sigma**2) )\n","\n","display(expr)\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ooprfWt3DqJx"},"outputs":[],"source":["# can also use longer and more informative variable names\n","hello = sym.symbols('hello')\n","\n","hello/3\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DX0iTjpwDqJx"},"outputs":[],"source":["# substituting numbers for variables\n","\n","# don't forget to define variables before using them!\n","display(x+4)\n","\n","(x+4).subs(x,3)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GZsJOS4xDqJx"},"outputs":[],"source":["# substituting multiple variables\n","\n","x,y = sym.symbols('x,y') # can create multiple variables in one line\n","expr = x+y+5\n","\n","# substituting one variable\n","print( expr.subs(x,5) )\n","\n","# substituting multiple variables\n","print( expr.subs({x:5,y:4}) )\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Cj_Tc5waDqJx"},"outputs":[],"source":["# using sympy to print latex code\n","expr = 3/x\n","\n","print( sym.latex(expr) )\n","\n","# notice:\n","print( sym.latex(3/4) )\n","print( sym.latex('3/4') )\n","# but\n","print( sym.latex(sym.sympify('3/4')) )\n"]},{"cell_type":"code","source":[],"metadata":{"id":"IHT0HhFXFVVR"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"sXEYdgt7DqJy"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"13fxGKHxDqJy"},"outputs":[],"source":["for i in range(-2,3):\n"," ans = (x+4).subs(x,i**2)\n"," display(Math('\\\\text{With }x=%g:\\; x^2+4 \\\\quad \\\\Rightarrow \\\\quad %g^2+4 =%g' %(i,i,ans)))"]},{"cell_type":"code","source":[],"metadata":{"id":"ORNLuhjuFXSP"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} -------------------------------------------------------------------------------- /algebra_2/mathWithPython_algebra2_minMaxFuns.ipynb: -------------------------------------------------------------------------------- 1 | {"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 2\n","# VIDEO: Maxima and minima of functions\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":["\n"," \"Open\n",""],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"G84akzicW_Qt"},"outputs":[],"source":["# import libraries and functions\n","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":"bzjofjasW_RA"},"outputs":[],"source":["# max and argmax\n","lst = [-4,5.5,3,2]\n","\n","print(np.max(lst))\n","print(np.argmax(lst))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Y1xxYjBLW_RA"},"outputs":[],"source":["# method: evaluate specific points in the function\n","\n","# x range\n","x = np.linspace(0,2*np.pi,20)\n","\n","# the function f(x)\n","fx = -( np.cos(x) + x**(1/2) )\n","\n","# find the maximum value of this function\n","fmax = np.max(fx)\n","print(fmax)\n","\n","# but we also need to know the location where this maximum is obtained\n","fmaxidx = np.argmax(fx)\n","print(fmaxidx)\n","\n","# draw the function\n","plt.plot(x,fx,'bo-')\n","plt.plot(x[fmaxidx],fmax,'rs')\n","\n","plt.xlabel('radians')\n","plt.xticks(np.round(np.arange(0,2*np.pi,np.pi/4),2))\n","plt.show()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"SJeYT8jGW_RB"},"outputs":[],"source":["# minimum\n","\n","# the range and the function\n","x = np.linspace(-2,2,50)\n","fx = x**3 + x**4\n","\n","# find the minimum\n","fminidx = np.argmin(fx)\n","\n","# draw the function\n","plt.plot(x,fx,'bo-')\n","plt.plot(x[fminidx],fx[fminidx],'ms',markersize=10)\n","\n","plt.ylim([-.2,.2])\n","plt.xlim([-1.2,.5])\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"Lq3ue2iyhdyk"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"8VPW1UzVW_RB"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"YDmwLAIxW_RB"},"outputs":[],"source":["from scipy.signal import find_peaks\n","\n","# x range\n","x = np.linspace(0,12*np.pi,200)\n","\n","# the function f(x)\n","fx = -( np.cos(x) + x**(1/2) )\n","\n","# find peaks\n","peeks = find_peaks(fx)\n","print(peeks)\n","\n","# draw the function\n","plt.plot(x,fx)\n","plt.plot(x[peeks[0]],fx[peeks[0]],'o')\n","plt.show()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"S7WIrjaWXS2p"},"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","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.9.7"},"colab":{"provenance":[]}},"nbformat":4,"nbformat_minor":0} --------------------------------------------------------------------------------