+{"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}
0 commit comments