Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I make Newton's Method return the zeros of sin?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-2,2,20)
y = np.linspace(-2,2,20)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
newton(xx+yy*1j,f,fp,100)

Output:

array[[3.14159265+0.00000000j, -3.14159265+0.00000000j, ...,
       3.14159265+0.00000000j, -3.14159265+0.00000000j]]

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

How do I make Newton's Method return the zeros of sin?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-2,2,20)
np.linspace(-7,7,100)
y = np.linspace(-2,2,20)
np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
newton(xx+yy*1j,f,fp,100)
newton(xx+yy*1j,f,fp,150)

Output:

array[[3.14159265+0.00000000j, -3.14159265+0.00000000j, array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
       3.14159265+0.00000000j, -3.14159265+0.00000000j]]
 6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

How do I make Newton's Method return the zeros of sin?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

How do I make Newton's Method return the zeros of sin?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

How do I make Newton's Method return the zeros of sin?Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

var('a')
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
g(x) = sin(x)
g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?

Is fast_callable breaking my code?

I'm currently trying to make an interact for newton fractals that accepts most functions. This is my code for newton's method:

import numpy as np

def newton(z0,f,fp,MAX_IT):
      cnt = 0
      TOL = 1e-10
      z = z0
      condition = fp(z) != 0
      a = z[condition]
      for i in range(MAX_IT):
           dz = f(a)/fp(a)
           adz = np.absolute(dz)
           if np.all(adz < TOL) :
              return a
           cnt += 1
           a -= dz
      return False

Input:

g(a) = sin(a)
f = fast_callable(g, vars=(a))
fp = fast_callable(diff(g), vars(a))
x = np.linspace(-7,7,100)
y = np.linspace(-7,7,100)
xx,yy = np.meshgrid(x,y)
newton(xx+yy*1j,f,fp,150)

Output:

array([-6.28318531+0.j, -6.28318531+0.j, -6.28318531+0.j, ...,
        6.28318531+0.j,  6.28318531+0.j,  6.28318531+0.j])

I'm supposed to get 0 or 2*pi in addition to the above. When I use numpy functions I don't have this issue. Is fast_callable breaking something?