≡ Menu

Punto fisso

Un punto fisso per una funzione definita da un insieme in sé è un elemento coincidente con la sua immagine. Siano \(f:A \to A\) e \(x \in A\). \(x\) è un punto fisso per \(f\) se $$x=f(x)$$ Si tratta di un punto che la funzione mappa in sé stesso.

Con l’ausilio di Python, valutiamo il punto fisso della funzione \(y=\sqrt{x}\).

import matplotlib.pyplot as plt
from numpy import array,linspace,sqrt,sin
from numpy.linalg import norm

def fixedp(f,x0,tol=10e-5,maxiter=100):
 """ Fixed point algorithm """
 e = 1
 itr = 0
 xp = []
 while(e > tol and itr < maxiter):
    x = f(x0)      # fixed point equation
    e = norm(x0-x) # error at the current step
    x0 = x
    xp.append(x0)  # save the solution of the current step
    itr = itr + 1
 return x,xp

f = lambda x : sqrt(x)
x_start = .5
xf,xp = fixedp(f,x_start)
x = linspace(0,2,1000)
y = f(x)
plt.plot(x,y,xp,f(xp),'bo',
     x_start,f(x_start),'ro',xf,f(xf),'go',x,x,'k')
stringa = "Fixed Point: " + str(round(xf, 4))

Figure 1
{ 0 comments… add one }

Rispondi

Next post:

Previous post: