Lab9temp_152_23C

pdf

School

Texas A&M University *

*We aren’t endorsed by this school

Course

152

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

6

Uploaded by MasterFireHeron35

Report
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 1/6 Limit is : 5/9 The series converges. In [1]: import sympy as sp from sympy.plotting import ( plot , plot_parametric ) import matplotlib.pyplot as plt import numpy as np In [2]: x , n = sp . symbols ( 'x , n' , real = True , positive = True ) eq = (( - 1 ) ** n * ( n + 1 ) * 9 ** ( n + 1 ) * ( x + 3 ) ** ( n + 2 )) / ( 5 ** ( n + 3 )) #display(eq) def ratio_test ( series ): an_1 = series . subs ( n , n + 1 ) an = series ratio = abs ( an_1 / an ) result = sp . limit ( ratio . subs ( x + 3 , 1 ), n , sp . oo ) # result is 9/5 * (x+3) final = sp . solve ( result * x - 1 , x ) # solve 9/5 * (x+3) < 1 print ( 'Limit is :' , * final ) if final [ 0 ] < 1 : print ( "The series converges." ) elif final [ 0 ] > 1 : print ( "The series diverges." ) else : print ( "The test is inconclusive." ) ratio_test ( eq ) In [3]: def ratio_test ( series ): an_1 = series . subs ( n , n + 1 ) an = series ratio = abs ( an_1 / an ) result = sp . limit ( ratio . subs ( x + 3 , 1 ), n , sp . oo ) # result is 9/5 * (x+3) final = sp . solve ( result * x - 1 , x ) # solve 9/5 * (x+3) < 1 return final def interval ( series ): interval = [] radius = ratio_test ( series )[ 0 ] interval1 = radius - 3
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 2/6 Interval of convergence: [-22/9, -32/9] Radius of convergence : interval2 = - radius - 3 interval . append ( interval1 ) interval . append ( interval2 ) return interval print ( 'Interval of convergence:' ) print ( interval ( eq )) print ( 'Radius of convergence : ' ) display ( * ratio_test ( eq )) In [171… matplotlib inline In [4]: f = 9 * ( x + 3 ) ** 2 / ( 9 * x + 32 ) ** 2 series = (( - 1 ) ** n * ( n + 1 ) * 9 ** ( n + 1 ) * ( x + 3 ) ** ( n + 2 )) / ( 5 ** ( n + 3 )) s5 = sp . summation ( series ,[ n , 0 , 5 ]) s10 = sp . summation ( series ,[ n , 0 , 10 ]) s15 = sp . summation ( series ,[ n , 0 , 15 ]) p1 = plot ( s5 ,( x , - 4 , - 2 ), ylim = [ - 4 , 4 ], show = False ) p2 = plot ( s10 ,( x , - 4 , - 2 ), ylim = [ - 4 , 4 ], show = False ) p3 = plot ( s15 ,( x , - 4 , - 2 ), ylim = [ - 4 , 4 ], show = False ) p4 = plot ( f ,( x , - 4 , - 2 ), ylim = [ - 4 , 4 ], show = False ) p1 . extend ( p2 ) p1 . extend ( p3 ) p1 . extend ( p4 ) p1 . show ()
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 3/6 The radius of convergence is: In [5]: J = (( - 1 ) ** n * ( x ** ( 2 * n + 1 ))) / ( sp . factorial ( n ) * sp . factorial ( n + 1 ) * 2 ** ( 2 * n + 1 )) display ( J ) def radius ( series ): an_1 = series . subs ( n , n + 1 ) an = series ratio = abs ( an_1 / an ) result = sp . limit ( ratio , n , sp . oo ) return result if radius ( J ) == 0 : print ( 'The radius of convergence is: ' ) display ( sp . oo )
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
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 4/6 In [6]: bessel_function = sp . besselj ( 1 , x ) series = (( - 1 ) ** n * ( x ** ( 2 * n + 1 ))) / ( sp . factorial ( n ) * sp . factorial ( n + 1 ) * 2 ** ( 2 * i = sp . symbols ( 'i' ) s0 = sp . Sum ( series . subs ( n , i ), ( i , 1 , 1 )) . doit () s1 = sp . Sum ( series . subs ( n , i ), ( i , 1 , 2 )) . doit () s2 = sp . Sum ( series . subs ( n , i ), ( i , 1 , 3 )) . doit () s3 = sp . Sum ( series . subs ( n , i ), ( i , 1 , 4 )) . doit () s4 = sp . Sum ( series . subs ( n , i ), ( i , 1 , 5 )) . doit () p1 = sp . plot ( s0 , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p2 = sp . plot ( s1 , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p3 = sp . plot ( s2 , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p4 = sp . plot ( s3 , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p5 = sp . plot ( s4 , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p6 = sp . plot ( bessel_function , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) p1 . extend ( p2 ) p1 . extend ( p3 ) p1 . extend ( p4 ) p1 . extend ( p5 ) p1 . extend ( p6 ) p1 . show () In [7]: bessel_functions = [ sp . besselj ( n , x ) for n in range ( 5 )]
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 5/6 plots = [ sp . plot ( bessel_function , ( x , 0 , 5 ), ylim = [ - 0.6 , 0.6 ], show = False ) for for i in range ( 1 , 5 ): plots [ 0 ] . extend ( plots [ i ]) plots [ 0 ] . show () In [8]: x , n , a = sp . symbols ( 'x n a' ) def nth_derivative_and_eval ( f , n , a ): nth_derivative = sp . diff ( f , x , n ) nth_derivative_at_a = nth_derivative . subs ( x , a ) return nth_derivative_at_a f_a = sp . sin ( x ) a_value = 0 taylor_polynomial_a = sum ( nth_derivative_and_eval ( f_a , i , a_value ) / sp . factori display ( taylor_polynomial_a )
11/19/23, 5:44 PM Lab9temp_152_23C localhost:8888/nbconvert/html/Lab9temp_152_23C.ipynb?download=false 6/6 In [9]: f_b = sp . tan ( x ) taylor_polynomial_b = sum ( nth_derivative_and_eval ( f_b , i , a_value ) / sp . factori display ( taylor_polynomial_b ) In [10]: f_c = sp . exp ( x ) taylor_polynomial_c = sum ( nth_derivative_and_eval ( f_c , i , a_value ) / sp . factori display ( taylor_polynomial_c ) In [11]: f_d = sp . sin ( x ) a_value_d = sp . pi / 2 taylor_polynomial_d = sum ( nth_derivative_and_eval ( f_d , i , a_value_d ) / sp . facto display ( taylor_polynomial_d ) In [ ]:
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