Lab3temp_151_24A

pdf

School

Texas A&M University *

*We aren’t endorsed by this school

Course

151

Subject

Mathematics

Date

Apr 3, 2024

Type

pdf

Pages

14

Uploaded by SargentSeahorsePerson1986

Report
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 1/14 MATH 151 Lab 3 Put team members' names and section number here. Question 1 1a In [128… import sympy as sp from sympy.plotting import ( plot , plot_parametric ) In [ ]: Section 404 - Group 3 Lisa Pham , Coby Holley , Bradley White , Owen Koss , Redlin Krueger , Garret Worden In [2]: matplotlib notebook
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 2/14 In [11]: # Start your code here #x = symbols('x') import numpy as np import matplotlib.pyplot as plt from sympy import limit , Symbol , sqrt , sin , pi # function definition def f ( x ): return np . sqrt ( x ** 3 + x ** 2 ) * np . sin ( np . pi / x ) + 2 def g ( x ): return np . full_like ( x , - 2 ) def h ( x ): return np . full_like ( x , 2 ) # domain x = np . linspace ( - 0.8 , 0.8 , 100 ) # x values f_values = f ( x ) g_values = g ( x ) h_values = h ( x ) # plot plt . plot ( x , f_values , label = 'f(x)' ) plt . plot ( x , g_values , label = 'g(x)' ) plt . plot ( x , h_values , label = 'h(x)' )
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 3/14 # plot defintion plt . xlabel ( 'x' ) plt . ylabel ( 'y' ) plt . title ( 'Graph of f(x), g(x), and h(x)' ) plt . legend () plt . show () #plot(x**2,(x,0,1))
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
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 4/14 1b
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 5/14 lim_{x->0} g(x) = -2 lim_{x->0} h(x) = 2 lim_{x->0} f(x) = -2 1c In [15]: # limits lim_g = g ( 0 ) lim_h = h ( 0 ) lim_f = lim_g print ( "lim_{x->0} g(x) =" , lim_g ) print ( "lim_{x->0} h(x) =" , lim_h ) print ( "lim_{x->0} f(x) =" , lim_f ) x_sym = Symbol ( 'x' ) f_expr = sqrt ( x_sym ** 3 + x_sym ** 2 ) * sin ( pi / x_sym ) + 2 In [16]: # limits lim_g = g ( 0 ) lim_h = h ( 0 ) lim_f = lim_g print ( "lim_{x->0} g(x) =" , lim_g ) print ( "lim_{x->0} h(x) =" , lim_h ) print ( "lim_{x->0} f(x) =" , lim_f ) x_sym = Symbol ( 'x' ) f_expr = sqrt ( x_sym ** 3 + x_sym ** 2 ) * sin ( pi / x_sym ) + 2
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 6/14 lim_{x->0} g(x) = -2 lim_{x->0} h(x) = 2 lim_{x->0} f(x) = -2 lim_{x->0} f(x) (direct calculation) = 2 Question 2 2a through 2c # limit of f(x) lim_f_direct = limit ( f_expr , x_sym , 0 ) print ( "lim_{x->0} f(x) (direct calculation) =" , lim_f_direct ) In [66]: import numpy as np import matplotlib.pyplot as plt import sympy as sp def f ( x ): if x <= 1 : return - 2 elif 1 < x <= 3 : return 2 * x - 5 elif 3 < x <= 5 : return ( x ** 2 - 2 * x - 8 ) / ( x - 4 ) #Limit of 1 left_limit_of_1 = sp . limit ( f ( 1 ), x , 1 , '-' )
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
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 7/14 print ( "The left sided limit when x is approaching 1 is: " , left_limit_of right_limit_of_1 = sp . limit ( f ( 1 + 0.0001 ), x , 1 , '+' ) print ( "The right sided limit when x is approaching 1 is: " , right_limit_ print ( "As the limit approaches 1 for f(x) from the right and the left doe print () #Limit of 3 left_limit_of_3 = sp . limit ( f ( 3 ), x , 3 , '-' ) print ( "The left sided limit when x is approaching 3 is: " , left_limit_of_ right_limit_of_3 = sp . limit ( f ( 3 ), x , 3 , '+' ) print ( "The right sided limit when x is approaching 3 is: " , right_limit_o print ( "As the limit approaches 3 for f(x) from the right and the left doe print () #Limit of 5 left_limit_of_5 = sp . limit ( f ( 5 ), x , 5 , '-' ) print ( "The left sided limit when x is approaching 5 is: " , left_limit_of_ right_limit_of_5 = sp . limit ( f ( 5 ), x , 5 , '+' ) print ( "The right sided limit when x is approaching 5 is: " , right_limit_o print ( "As the limit approaches 5 for f(x) from the right and the left doe
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 8/14 The left sided limit when x is approaching 1 is: -2 The right sided limit when x is approaching 1 is: -2.99980000000000 As the limit approaches 1 for f(x) from the right and the left does not e qual each other f(x) is not continous. The left sided limit when x is approaching 3 is: 1 The right sided limit when x is approaching 3 is: 1 As the limit approaches 3 for f(x) from the right and the left does equal each other f(x) is continous. The left sided limit when x is approaching 5 is: 7.00000000000000 The right sided limit when x is approaching 5 is: 7.00000000000000 As the limit approaches 5 for f(x) from the right and the left does equal each other f(x) is continous. 2d In [4]: matplotlib notebook In [127… import numpy as np import matplotlib.pyplot as plt import sympy as sp def f ( x ): if x <= 1 : return - 2 elif 1 < x <= 3 : return 2 * x - 5
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 9/14 There is a hole at x=4 therefore there is the error message. C:\Users\27pha\AppData\Local\Temp\ipykernel_18748\3659915970.py:11: Runti meWarning: invalid value encountered in scalar divide return (x**2 - 2*x -8) / (x-4) elif 3 < x <= 5 : return ( x ** 2 - 2 * x - 8 ) / ( x - 4 ) x_values = np . linspace ( 0 , 7 ) y_values = [ f ( x ) for x in x_values ] plt . plot ( x_values , y_values ) print ( 'There is a hole at x=4 therefore there is the error message.' )
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
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 10/14 Question 3 3a
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 11/14 1.0000063497741163 3b In [8]: import math n = 99999 sum ([ math . log ( i + 1 ) for i in range ( n )]) / ( n * math . log ( n ) - n ) #proves that any (non integer) number with stirling's formula will approxi Out[8]: In [126… import numpy as np import matplotlib.pyplot as plt from sympy import factorial , sqrt , pi # Define the factorial function f(x) def f ( x ): return factorial ( x ) # Define Stirling's approximation function g(x) def g ( x ): return sqrt ( 2 * pi * x ) * ( x / np . e ) ** x # Generate x values x_values = np . linspace ( 0.1 , 5 , 100 ) # Compute y values for both functions f_values = [ f ( xi ) for xi in x_values ] g_values = [ g ( xi ) for xi in x_values ]
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 12/14 # Plot the functions plt . plot ( x_values , f_values , label = 'f(x)' , linewidth = 4 ) plt . plot ( x_values , g_values , label = 'g(x)' ) # Add labels and legend plt . xlabel ( 'x' ) plt . ylabel ( 'f(x), g(x)' ) plt . legend () # Show plot plt . grid ( True ) plt . show ()
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
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 13/14 In [ ]:
2/21/24, 3:18 PM Lab3temp_151_24A localhost:8888/nbconvert/html/Lab3temp_151_24A.ipynb?download=false 14/14 In [ ]: