def graph(func, f_prime, a, b, n):
    """Graphs both a functions vectorized approximation and analytical derrivative."""
    x = np.linspace(a, b, n)
    f_prime = f_prime(x)
    diff_mesh, f_diff = differentiator.diff(func, a, b, 1000)[0], differentiator.diff(func, a, b, 1000)[2]
    mp.plot(x, f_prime, 'ko')
    mp.plot(diff_mesh, f_diff, 'b-')
    mp.xlim([a - 0.01, b + 0.01])
    mp.xlabel('x')
    mp.ylabel('y')
示例#2
0
def arclength(g, a, b, n):
    xlist = np.linspace(a, b, n + 1)
    f = np.vectorize(g)
    ylist = f(xlist)
    difflist = calculus.diff(f, a, b, n)[1]
    s = np.zeros(n + 1)
    #s will hold the incremental values of each indivual arc length at first
    il = np.vectorize(incremental_lengther)
    s[1:] = il(difflist[1:])
    #now traverse backwards to sum individual points
    for i in xrange(n, -1, -1):
        s[i] = np.sum(s[:i + 1])
    return s
def arclength(g, a, b, n):
    xlist = np.linspace(a, b, n+1)
    f = np.vectorize(g)
    ylist = f(xlist)
    difflist = calculus.diff(f, a, b, n)[1]
    s = np.zeros(n+1)
    #s will hold the incremental values of each indivual arc length at first
    il = np.vectorize(incremental_lengther)
    s[1:] = il(difflist[1:])
    #now traverse backwards to sum individual points
    for i in xrange(n, -1, -1):
        s[i] = np.sum(s[:i+1])
    return s
def multiplicity(f, root, tol=eps, maxsteps=10, **kwargs):
    """
    Return the multiplicity of a given root of f.

    Internally, numerical derivatives are used. This might be inefficient for
    higher order derviatives. Due to this, ``multiplicity`` cancels after
    evaluating 10 derivatives by default. You can be specify the n-th derivative
    using the dnf keyword.

    >>> from mpmath import *
    >>> multiplicity(lambda x: sin(x) - 1, pi/2)
    2
    """
    kwargs['d0f'] = f
    for i in xrange(maxsteps):
        dfstr = 'd' + str(i) + 'f'
        if dfstr in kwargs:
            df = kwargs[dfstr]
        else:
            df = lambda x: diff(f, x, i)
        if not abs(df(root)) < tol:
            break
    return i
示例#5
0
def multiplicity(f, root, tol=eps, maxsteps=10, **kwargs):
    """
    Return the multiplicity of a given root of f.

    Internally, numerical derivatives are used. This might be inefficient for
    higher order derviatives. Due to this, ``multiplicity`` cancels after
    evaluating 10 derivatives by default. You can be specify the n-th derivative
    using the dnf keyword.

    >>> from mpmath import *
    >>> multiplicity(lambda x: sin(x) - 1, pi/2)
    2
    """
    kwargs['d0f'] = f
    for i in xrange(maxsteps):
        dfstr = 'd' + str(i) + 'f'
        if dfstr in kwargs:
            df = kwargs[dfstr]
        else:
            df = lambda x: diff(f, x, i)
        if not abs(df(root)) < tol:
            break
    return i
示例#6
0
 def d2f(x):
     return diff(df, x)
示例#7
0
 def df(x):
     return diff(f, x)
def test_derrivatives():
    """Ensures that the value of the derrivative of x^3 is good at x = 3 as per the vectorized derrivative function."""
    apt = np.fabs(differentiator.diff(h, 2, 3.01, 1000)[1][-1] - 56.6625)
    msg = 'Derrivative is imporperly calculated.'
    assert apt, msg