CoCalc Public FilesThiel Workspace.ipynbOpen with one click!
Authors: Karim Ahmed, Julia Burnside, Randy Cazales, Dylan Cortes, Starling Hidalgo, Sharalee Jones , Anika Khan, MIRALIA MOREAU, Tunazzina Mahdin, Mekeisha Naughton, and 11 more authors...
Views : 109
Compute Environment: Ubuntu 20.04 (Default)

Approximating 2\sqrt{2}

In [1]:
def sqrt2approx(n): if n == 0: return 1 else: return sqrt2approx(n-1)-(sqrt2approx(n-1)**2-2)/(2*sqrt2approx(n-1))
In [2]:
sqrt2approx(0)
1
In [3]:
sqrt2approx(1)
1.5
In [4]:
sqrt2approx(2)
1.4166666666666667
In [5]:
sqrt2approx(3)
1.4142156862745099
In [6]:
2**0.5
1.4142135623730951

Newton's Method (general version)

In [7]:
def newton(f,df,x,n,err): i = 0 while abs(f(x)) > err and i <= n: x = x - f(x)/df(x) i += 1 if i > n: return False else: return x

Approximating 43\sqrt[3]{4}

In [10]:
def myfun(x): return x**3-4 def myfunDeriv(x): return 3*x**2
In [11]:
newton(myfun,myfunDeriv,1.5,5,0.0001)
1.587401052148227
In [12]:
1.587401052148227**3
4.000000001360922

Line tangent to exe^x and lnx\ln{x}

In [ ]:
import math def f(x): return
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: