#!/usr/bin/env python # coding: utf-8 # # Homework 21 # ## Symbolic math # # ### Problem 1 # #### Part a # # Import the library needed for using symbolic math in python. Also setup the notebook for printing. # In[ ]: # #### Part b # Set variables x, y, z, and function f, and g. # In[ ]: # #### Part c # # Set an expression for the following: $$x^2+2x-5.$$ # # In[ ]: # #### Part d # # Evaluate the expression for $x=1.5$. Also, make a variable substitution: $z$ for $x$. Do a variable substitution $y^2$ for x. # In[ ]: # ### Problem 2 # #### Part a # # Simplify the following expression: # $$\frac{x^2 - x - 6}{x^2-3x}.$$ # In[ ]: # #### Part b # # Expand the following expression symbolically: $$(x+1)^3(x-2)^2.$$ # In[ ]: # #### Part c # Factor the following expression: $$3x^4 - 36x^3+99x^2-6x-144.$$ # In[ ]: # ### Problem 3 # #### Part a # Compute the symbolic derivative: $$\frac{d}{dx}\sin^2(x)e^{2x}.$$ # Then evaluate the resulting expression for $x=3.3.$ # In[ ]: # #### Part b # Create a sympy expression representing the following integral: # $$\int_0^5x^2\sin(x^2)dx.$$ # # Then evaluate the integral symbolically. # In[ ]: # ### Problem 4 # #### Part a # Solve for the roots of the following equation: $$x^3+15x^2=3x-10.$$ # Use the ```Eq``` and ```solve``` functions and save as an expression. Show the expression (it will be a list). Then find the numerical value of each root using the evalf function. You can use evalf on some expression using ```my_expression.evalf()```. # In[ ]: # #### Part b # Solve the system of three equations in three unknowns symbolically: # # $$x+y+z=0,$$ # # $$2x-y-z=10,$$ # # $$y+2z=5.$$ # # Compare the result to the answer computed with fsolve from scipy.optimize. # In[ ]: # #### Part c # Solve the following differential equation symbolically using the ```dsolve``` function: # $$\frac{df(x)}{dx} = x\cos(x).$$ # In[ ]: # ### Problem 5 # #### Part a # For the system $Ax=b$ with # $$ A = \left[\begin{matrix} # 1 & 2 & 5 \\ # 3 & 4 & 6 \\ # -1 & 0 & 3 # \end{matrix}\right],$$ # $$b = \left[\begin{matrix} # 1 \\ # 0 \\ # -2 # \end{matrix}\right].$$ # Setup the matrices $A$ and $b$ # # In[ ]: # #### Part b # For the system in Part a, solve for matrix $x$ by matrix algebra. # In[ ]: # #### Part c # # For matrix A above, return the middle row, and the middle column. # In[ ]: