CoCalc Public FilesNewton's method to approximate cube root of 4.ipynbOpen with one click!
Authors: Karim Ahmed, Randy Cazales, Sharalee Jones , MIRALIA MOREAU, Tunazzina Mahdin, Mekeisha Naughton, David Ramirez, Jose Armando Sanchez Diaz, Tetiana Soloviova
Views : 35
Compute Environment: Ubuntu 20.04 (Default)

This activity asks to use three iterations of Newton's method to approximate the cube root of 4.First I define a function calls newton and that function I have "f" which is the original function, "df" as the derivation of the original function, x represents the initial value, n stands for the number of iterations,and err is the error which I use the value of 0.0001.So since the function is given and I have the error value, I will need to find the x value in order to find the approximate value for the cube root of 4.So I graph my original function in Desmos and I find that the root is actually between 1 and 2 then I pick 1 as for my x value. After plotting everything I found out with three iteration of Newton's method to approximate the cube root of 4 with an error of 0.0001 is 2.

In [ ]:
In [1]:
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 n>n: return false else: return x
In [2]:
def myf(x): return x**3-4 def myfderiv(x): return 3*x**2
In [1]:
newton(myf,myfderiv,1.5,3,0.0001)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-1-933d163d298d> in <module> ----> 1 newton(myf,myfderiv,1.5,3,0.0001) NameError: name 'newton' is not defined