Lab 03 - The u-Substitution Method - Jupyter Notebook

pdf

School

University of South Carolina *

*We aren’t endorsed by this school

Course

142

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

9

Uploaded by ChancellorWorld13288

Report
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 1 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…books/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# Lab 03 - The u-Substitution Method Overview In this lab, we will use SageMath to perform u-substitutions for both indefinite and definite integrals. Important SageMath Commands Introduced in this Lab Related Course Material Section 5.5 Command from   package   import   function eqn .rhs() solve(eqn, var) expr .substitute(x = expr2) Description Imports the   function   from the   package. Returns the right hand side of the equations Solves an equation for the given variable Substitutes   expr2   in for   x   in   expr ( x == solve( ( x + 1 Example 1 We will calculate the indefinite integral by using u-substitution. First, we must decide what substitution to make. Since is the inside function and its derivate appears in the integrand, up to a constant multiple, we should let We can use SageMath to handle the u-substitution for us. We start by defining as our integrand and as and then calculating .   dx x 2 e x 3 x 3 3 x 2 u = . x 3 f ( x ) u x 3 du In [1]: u = var('u') ## This is to define u as a variable assume(u > 0) ## This is to avoid any problems with the solve comma def f(x): return x ^ 2 * e ^ (x ^ 3) sub = u == x ^ 3 ## We write u == x^3 in order to tell SageMath that du = diff(sub.rhs(),x) ## This defines du as the derivative of the ri
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 2 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# Now, we need to substitute both and into our original integral. In order to do this, we first need to solve for in terms of . In this example, it can easily be done by hand to obtain We can also use SageMath to obtain the same result using the command. u du u x x = . u 1/3 solve In [2]: Note that SageMath returns both real and complex solutions to the equation when solving for . The function in the package will return the expected solution when solving the equation for . To access this function, we must import it from the package by using the command . u = x 3 x solve_for_x uofsc_calculus_labs x from   package   import   function In [4]: If SageMath returns the error stating that there is no module named , then you will first need to install the package using . This can be done in SageMath by running the command below. If you are using a lab computer or the Binder server, then you will not be able to use ; however, should already be installed. uofsc_caluculus_labs pip Note:   %pip uofsc_calculus_labs In [5]: Out[2]: [x == 1/2*u^(1/3)*(I*sqrt(3) - 1), x == -1/2*u^(1/3)*(I*sqrt(3) + 1), x == u^(1/3)] Requirement already satisfied: uofsc_calculus_labs in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (0.3) Requirement already satisfied: sphinx in /usr/local/sage/local/var/li b/sage/venv-python3.8/lib/python3.8/site-packages (from uofsc_calculu s_labs) (4.4.0) Requirement already satisfied: sage-package in /usr/local/sage/local/ var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from uofsc_c alculus_labs) (0.0.7) Requirement already satisfied: docutils<0.18,>=0.14 in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->uofsc_calculus_labs) (0.17.1) Requirement already satisfied: snowballstemmer>=1.1 in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->uofsc_calculus_labs) (2.1.0) Requirement already satisfied: Jinja2>=2.3 in /usr/local/sage/local/v ar/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx-> uofsc_calculus_labs) (2.11.2) Requirement already satisfied: Pygments>=2.0 in /usr/local/sage/loca l/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphin x->uofsc_calculus_labs) (2.10.0) solve(sub, x) from uofsc_calculus_labs import solve_for_x % pip install uofsc_calculus_labs
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 3 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# Requirement already satisfied: importlib-metadata>=4.4 in /usr/local/ sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (f rom sphinx->uofsc_calculus_labs) (4.8.2) Requirement already satisfied: sphinxcontrib-devhelp in /usr/local/sa ge/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (fro m sphinx->uofsc_calculus_labs) (1.0.2) Requirement already satisfied: sphinxcontrib-jsmath in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->uofsc_calculus_labs) (1.0.1) Requirement already satisfied: sphinxcontrib-serializinghtml>=1.1.5 i n /usr/local/sage/local/var/lib/sage/venv-python3.8/lib/python3.8/sit e-packages (from sphinx->uofsc_calculus_labs) (1.1.5) Requirement already satisfied: sphinxcontrib-applehelp in /usr/local/ sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (f rom sphinx->uofsc_calculus_labs) (1.0.2) Requirement already satisfied: sphinxcontrib-qthelp in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->uofsc_calculus_labs) (1.0.3) Requirement already satisfied: sphinxcontrib-htmlhelp>=2.0.0 in /usr/ local/sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packa ges (from sphinx->uofsc_calculus_labs) (2.0.0) Requirement already satisfied: packaging in /usr/local/sage/local/va r/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->u ofsc_calculus_labs) (21.3) Requirement already satisfied: imagesize in /usr/local/sage/local/va r/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->u ofsc_calculus_labs) (1.2.0) Requirement already satisfied: requests>=2.5.0 in /usr/local/sage/loc al/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphi nx->uofsc_calculus_labs) (2.26.0) Requirement already satisfied: babel>=1.3 in /usr/local/sage/local/va r/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->u ofsc_calculus_labs) (2.9.1) Requirement already satisfied: alabaster<0.8,>=0.7 in /usr/local/sag e/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from sphinx->uofsc_calculus_labs) (0.7.12) Requirement already satisfied: pytz>=2015.7 in /usr/local/sage/local/ var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from babel>= 1.3->sphinx->uofsc_calculus_labs) (2021.3) Requirement already satisfied: zipp>=0.5 in /usr/local/sage/local/va r/lib/sage/venv-python3.8/lib/python3.8/site-packages (from importlib -metadata>=4.4->sphinx->uofsc_calculus_labs) (3.5.0) Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/sage/lo cal/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from Jin ja2>=2.3->sphinx->uofsc_calculus_labs) (1.1.1) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/sa ge/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (fro m requests>=2.5.0->sphinx->uofsc_calculus_labs) (1.26.6) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/loca l/sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 4 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# In [6]: Once we have imported the function , we use it to solve the equation for . solve_for_x x In [7]: SageMath returns as desired. Now we can use SageMath to substitute both and into our original integral. x = u 1/3 u du In [8]: Therfore, our new integrand is . We can have SageMath display the new integral by using the command along with the parameter which will keep SageMath from evaluating the integral. 1 3 e u integrate hold = true In [9]: (from requests>=2.5.0->sphinx->uofsc_calculus_labs) (2.0.4) Requirement already satisfied: idna<4,>=2.5 in /usr/local/sage/local/ var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from request s>=2.5.0->sphinx->uofsc_calculus_labs) (3.2) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/sage/ local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from r equests>=2.5.0->sphinx->uofsc_calculus_labs) (2021.10.8) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/loca l/sage/local/var/lib/sage/venv-python3.8/lib/python3.8/site-packages (from packaging->sphinx->uofsc_calculus_labs) (3.0.6) WARNING: You are using pip version 22.0.2; however, version 23.3.2 is available. You should consider upgrading via the '/usr/local/sage/local/var/lib/ sage/venv-python3.8/bin/python3 -m pip install --upgrade pip' comman d. Note: you may need to restart the kernel to use updated packages. Out[7]: x == u^(1/3) Out[8]: 1/3*e^u du 1 3 e u from uofsc_calculus_labs import solve_for_x solve_for_x(sub,x) g(u) = (f(x) / du).substitute(solve_for_x(sub,x)) g(u) show(integrate(g(u),u,hold = true))
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 5 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# It follows that under the u-substitution , we have Now, we can integrate the right integral easily by hand. We see that Finally, we write our final answer back in terms of since that was our starting variable. Hence, we have that u = x 3   dx =   du . x 2 e x 3 1 3 e u   du = + C . 1 3 e u 1 3 e u x   dx = + C . x 2 e x 3 1 3 e x 3 Example 2 Let us use u-substitition to evalaute . We can again use SageMath to perform the u-substitution by repeating the steps in Example 1 with a new integrand and new . In order to save time for future examples, we can package all of the steps together into a function which we will call . 2 x ( + 5   dx x 2 ) 4 f ( x ) u u_sub(f, sub) In [13]: Before we use to solve our new problem, let's verify that it works by using it on the integral from Example 1. u_sub In [12]: It works! Now let us try it with the integral . We have that and . We now use to rewrite the integral in terms of . 2 x ( + 5   dx x 2 ) 4 f ( x ) = 2 x ( + 5 x 2 ) 4 u = + 5 x 2 u_sub u du 1 3 e u def u_sub(f, sub): u = var('u') assume(u > 0) du = diff(sub.rhs(),x) g(u) = (f(x) / du).substitute(solve_for_x(sub,x)).expand() return show(integrate(g(u),u,hold = true)) def f(x): return x ^ 2 * e ^ (x ^ 3) u_sub(f, u == x ^ 3)
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 6 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# In [14]: Now, we should be able to integrate the new integral without much trouble and get To get our final answer, we replace with to get We can check our final answer in SageMath by using the normal command. (Don't forget that SageMath does not include the .)   du = + C . 1 u 4 1 3 u 3 u + 5 x 2 2 x ( + 5   dx = + C . x 2 ) 4 1 3( + 5 x 2 ) 3 integrate + C In [15]: Example 3 Now suppose we wish to evaluate the definite integral We now not only need to rewrite the integrand in terms of , we also have to change the bounds to be in terms of . We can use a modified version of the function above to accomplish this. 3   dx . 1 1 x 2 + 1 x 3 ⎯⎯⎯⎯⎯⎯⎯⎯ u u u_sub In [17]: We can now use to perform a u-substitution on the integral above with integrand and and bounds and . u_sub_with_bounds f ( x ) = 3 x 2 + 1 x 3 ⎯⎯⎯⎯⎯⎯⎯⎯ u = + 1 x 3 a = 1 b = 1 du 1 u 4 1 3 ( + 5 ) x 2 3 def f(x): return 2 * x * (x ^ 2 + 5) ^ ( - 4) u_sub(f, u == x ^ 2 + 5) show(integrate(f(x),x)) def u_sub_with_bounds(f, sub, a, b): u = var('u') assume(u > 0) new_a = sub.rhs().substitute(x = a) ## Rewrites a in terms of u new_b = sub.rhs().substitute(x = b) ## Rewrites b in terms of u du = diff(sub.rhs(),x) g(u) = (f(x) / du).substitute(solve_for_x(sub,x)).expand() return show(integrate(g(u),u,new_a, new_b, hold = true))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 7 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# In [18]: We are able to solve this definite integral since we know the antiderivative of . We can use SageMath to verify our answer by using the command with our original integrand and bounds. u ⎯⎯   du = = ( ) = . 2 0 u ⎯⎯ 2 3 u 3/2 | | | | 2 0 2 3 2 3/2 0 3/2 4 2 ⎯⎯ 3 integrate In [19]: Example 4 Use the functions and to simply the following integrals by using u-substitition. Then solve the integrals by hand using their simplified form. Lastly, use SageMath to verify that your answer is correct. 1. 2. 3. 4. 5. 6. u_sub u_sub_with_bounds (3 x + 2)(3 + 4 x   dx x 2 ) 4 sin( 1)   dx x ⎯⎯ x 3/2 3   dx x 5 + 1 x 3 ⎯⎯⎯⎯⎯⎯⎯⎯ x ( + 1   dx 7 0 x 2 ) 1/3 ( 1 + ) ( x )   dx π /4 0 e tan( x ) sec 2   dx e 3 e 1 x (ln( x )) 2 du 2 0 u ⎯⎯ 4 3 2 ⎯⎯ def f(x): return 3 * x ^ 2 * sqrt(x ^ 3 + 1) u_sub_with_bounds(f, u == x ^ 3 + 1, - 1, 1) show(integrate(f(x),x, - 1,1))
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 8 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb# In [25]: In [28]: In [29]: In [32]: In [42]: In [46]: In [ ]: + + u du 1 9 u 6 2 3 u 5 8 9 u 4 16 9 u 3 16 3 u 2 32 9 sin( u ) du 2 3 du u 3 2 u ⎯⎯ du 8.00000000000000 1 1 2 u 1 3 + 1 du 1 0 e u du 3 1 1 u 2 def g(x): return x * (3 * x + 2) * (3 * x + 4) ^ 4 u_sub(g, u == 3 * x + 2) def h(x): return x ^ (1 / 2) * sin(x ^ (3 / 2) - 1) u_sub(h, u == x ^ (3 / 2) - 1) def f(x): return 3 * x ^ 5 * (x ^ 3 + 1) ^ (1 / 2) u_sub(f, u == x ^ 3 + 1) def g(x): return x * (x ^ 2 + 1) ^ (1 / 3) u_sub_with_bounds(g, u == x ^ 2 + 1, 0, (7) ^ .5) def g(x): return (1 + e ^ (tan(x))) * sec(x) ^ 2 u_sub_with_bounds(g, u == tan(x), 0, pi / 4) def g(x): return 1 / (x * (ln(x)) ^ 2) u_sub_with_bounds(g, u == ln(x), e, e ^ 3)
1/29/24, 12 : 17 PM Lab 03 - The u-Substitution Method - Jupyter Notebook Page 9 of 9 https://notebooks.gesis.org/binder/jupyter/user/calculuslab-calcul…ooks/142-Labs/Lab%2003%20-%20The%20u-Substitution%20Method.ipynb#
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help