Skip to content

Commit 373d224

Browse files
authored
Add files via upload
1 parent 0546312 commit 373d224

File tree

53 files changed

+53
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+53
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Associative, commutative, and distributive properties\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/algebra1/mathWithPython_algebra1_ACDprops.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"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":"markdown","metadata":{"id":"H6M_BXA1eQ76"},"source":["### Associative"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"w3Mbc-7ZeQ76"},"outputs":[],"source":["from sympy.abc import x,y\n","\n","expr1 = x*(4*y)\n","expr2 = (x*4)*y\n","\n","# show that two equations are equal by subtracting them!\n","expr1 - expr2"]},{"cell_type":"markdown","metadata":{"id":"Y_jxeKyueQ76"},"source":["### Commutative"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"TXkWoVfveQ8B"},"outputs":[],"source":["# create three expressions\n","e1 = x*4*y\n","e2 = 4*x*y\n","e3 = y*x*4"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"8zZURHtdeQ8B"},"outputs":[],"source":["# quick reminder about substitution in sympy\n","display( e1.subs(x,3) )\n","\n","# multiple subsitutions\n","e3.subs({x:2,y:3})"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"UsRcuifjeQ8B"},"outputs":[],"source":["# now back to the task!\n","print( e1.subs({x:3,y:4}) )\n","print( e2.subs({x:3,y:4}) )\n","print( e3.subs({x:3,y:4}) )"]},{"cell_type":"markdown","metadata":{"id":"pOpMox_neQ8B"},"source":["### Distributive"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WYyAWOYOeQ8B"},"outputs":[],"source":["# another way of creating symbolic variables\n","from sympy.abc import a, b, c, d\n","\n","expr = (a+b)*(c+d)\n","expr"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"gJRch3rjeQ8B"},"outputs":[],"source":["sym.expand(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"c7EyJ-7OeQ8B"},"outputs":[],"source":["sym.expand( (a+d)*(a-d) )"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"RoR1FUCWeQ8C"},"outputs":[],"source":["# embedding expressions\n","a,x,y,z = sym.symbols('a,x,y,z')\n","\n","x = 3*y + z\n","a = 4*x\n","\n","display(a)"]},{"cell_type":"code","source":[],"metadata":{"id":"2npv9Tqdv3N_"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"pN4iaH0yeQ8C"},"source":["# Exercises"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"7vGMs2YgeQ8C"},"outputs":[],"source":["# with these two expressions, show that the commutative rule applies\n","\n","w,x,y,z = sym.symbols('w,x,y,z')\n","\n","x = w*(4-w)+1/w**2*(1+w)\n","expr1 = x*(y+z)\n","expr2 = 3/x+x**2\n","\n","display(Math(sym.latex(expr1*expr2)))\n","display(Math(sym.latex(sym.simplify(expr1*expr2))))\n","display(Math(sym.latex(expr2*expr1 - expr1*expr2)))"]}],"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}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/algebra1/mathWithPython_algebra1_BUGHUNT.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":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}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/algebra1/mathWithPython_algebra1_addPolys.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"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}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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! (solutions)\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/algebra1/mathWithPython_algebra1_bugHunt_SOL.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"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":"enilBFUxeQ8K"},"outputs":[],"source":["# from sympy.abc import x2\n","x2 = sym.symbols('x2')\n","\n","x2 = 4"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LGV9-9zseQ8K"},"outputs":[],"source":["a,b,c,d = sym.symbols('a,b,c,d')\n","\n","expr = 4*b + 5*a*a - c**3 + 5*d\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Gd3IEFCveQ8K"},"outputs":[],"source":["import math\n","math.gcd(30,50)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-c0hybO0eQ8K"},"outputs":[],"source":["from sympy.abc import x\n","\n","expr = 4*x - 8\n","sym.solve(expr)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"o7gIKwUzeQ8K"},"outputs":[],"source":["import numpy as np\n","\n","A = np.array( [ [1,2],[3,4] ] )\n","# make it look nice\n","display(Math(sym.latex(sym.sympify(A))))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"H5ouypPreQ8L"},"outputs":[],"source":["fact_dict = sym.factorint(44)\n","allkeys = fact_dict.keys()\n","\n","for i in fact_dict:\n"," print('%g was present %g times.' %(i,fact_dict[i]))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"hqOJf0VLeQ8L"},"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":"jQOv1yoZeQ8L"},"outputs":[],"source":["# goal is to show a fraction\n","\n","f = sym.sympify(5)/9\n","\n","display(Math(sym.latex(f)))\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"CMqyJTPHeQ8L"},"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:]\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LQlT6SRseQ8L"},"outputs":[],"source":["from sympy.abc import x,y\n","\n","expr = 2*x + 4*y\n","\n","# solve for y\n","sym.solve(expr,y)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"AJzvEK7XeQ8L"},"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[1,1] = 9\n","print(A)"]},{"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}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cells":[{"cell_type":"markdown","metadata":{"id":"Brtl6ZgJqgu2"},"source":["# COURSE: Master math by coding in Python\n","# SECTION: Algebra 1\n","# VIDEO: Introduction to dictionaries\n","\n","\n","### https://www.udemy.com/course/math-with-python/?couponCode=202312\n","#### INSTRUCTOR: Mike X Cohen (http://sincxpress.com)\n","\n","This code roughly matches the code shown in the live recording: variable names, order of lines, and parameter settings may be slightly different."]},{"cell_type":"markdown","source":["<a target=\"_blank\" href=\"https://colab.research.google.com/github/mikexcohen/MathWithPython/blob/main/algebra1/mathWithPython_algebra1_dictionaries.ipynb\">\n"," <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n","</a>"],"metadata":{"id":"JZhUk_36xwBy"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"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":"wdAiyKRBeQ8F"},"outputs":[],"source":["# create a dictionary\n","D = dict(fruit=['banana','apple'],numbers=[1,3,4,2,5])\n","\n","print(D)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iw0Ee803eQ8F"},"outputs":[],"source":["# list the \"keys\"\n","D.keys()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"GnmgKwCGeQ8G"},"outputs":[],"source":["# get the information from the numbers\n","D['numbers']"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"gVYDUfcUeQ8G"},"outputs":[],"source":["# or this way\n","D.get('fruit')[0]"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pFmRZcs-eQ8G"},"outputs":[],"source":["len(D)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WRrtIJV5eQ8G"},"outputs":[],"source":["# print out all information in a loop!\n","for items in D.keys(): # .keys() is implied!\n"," print(D[items])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WehirgJ1eQ8G"},"outputs":[],"source":["# make a dictionary of equations\n","x,y = sym.symbols('x,y')\n","\n","D = dict(eqsWithX=[x/3-6,x*2+3],eqsWithY=[y-y/4,y-5])\n","D.keys()\n","\n","Dkeys = list(D)\n","\n","# access individual keys\n","D[Dkeys[0]]\n"]},{"cell_type":"code","source":[],"metadata":{"id":"_e80bGwY1Md3"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"N57dkTx0eQ8G"},"source":["# Exercise"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"gqgw0ylyeQ8G"},"outputs":[],"source":["# let's make a new dictionary\n","x,y = sym.symbols('x,y')\n","\n","# count number of x's and y's in the equation\n","D = dict(eqsWithX=[4*x-6,x**2-9],eqsWithY=[sym.sin(y)])\n","\n","# solve them in a loop\n","for keyi in D:\n","\n"," print('Equations solving for ' + keyi[-1] + ':')\n","\n"," for i in D[keyi]:\n","\n"," fullEQ = sym.latex(sym.sympify(i)) + ' = 0'\n"," middlepart = '\\\\quad\\\\quad \\\\Rightarrow\\\\quad\\\\quad ' + keyi[-1] + ' = '\n"," soln = sym.latex(sym.solve(i))\n","\n"," display(Math( '\\\\quad\\\\quad ' + fullEQ + middlepart + soln ))"]}],"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}

0 commit comments

Comments
 (0)