Lorenays25
Lorenays25

Reputation: 11

Is it possible to apply the sympy function to a cumulative distribution function of a normal distribution? (Newton Raphson Method)

I want to find the solution of a equation that contains a cumulative distribution function of a normal distribution using Sympy library in order to apply the Newton Raphson Method. However, it returns the following error: 'Symbol' object has no attribute 'cdf' when sp.Derivative() is executed. My equation is nonlinear and I would like to know how to solve this exercise. More details below.

I have an error AttributeError: 'Symbol' object has no attribute 'cdf' when I'm trying to calculate for Newton Raphson the solution of an equation that contains a cumulative distribution function of a normal distribution norm.cdf the example equation is :

funcion2='x*(stats.norm.cdf(1/x))'

where

for k in range(1, T):     # las iteraciones
    xold = x0
    # created function
    fx = funcion(expr, x0)
    df_dx = derivada(expr, x0)   # This is the error
    x0 = x0-fx/df_dx  # Newton Raphson

where

def funcion(expr, val):
    x = val
    y = eval(expr)
    return y

def derivada(expr, x0):  # in order to calculate the derivative function
    x = sp.Symbol('x')
    f_prime = sp.Derivative(expr, x)
    derivative_function = f_prime.doit().subs(x, x0)
    return derivative_function

I don't know how to obtain the derivate from the example equation. Could someone please help? Thank you very much in advance!

Upvotes: 0

Views: 39

Answers (0)

Related Questions