Giter Club home page Giter Club logo

differint's Introduction

differint

This package is used for numerically calculating fractional derivatives and integrals (differintegrals). Options for varying definitions of the differintegral are available, including the Grunwald-Letnikov (GL), the 'improved' Grunwald-Letnikov (GLI), the Riemann-Liouville (RL), and the Caputo (L1, L2, and L2C). Through the API, you can compute differintegrals at a point or over an array of function values.

See below for an example of how to use this package, or check out the wiki for references, signatures, and examples for each function.

Motivation

There is little in the way of readily available, easy-to-use code for numerical fractional calculus. What is currently available are functions that are generally either smart parts of a much larger package, or only offer one numerical algorithm. The differint package offers a variety of algorithms for computing differintegrals and several auxiliary functions relating to generalized binomial coefficients.

Installation

This project requires Python 3+ and NumPy to run.

Installation from the Python Packaging index (https://pypi.python.org/pypi) is simple using pip.

pip install differint

Included Files

Core File Description
differint/differint.py Contains algorithms for fractional differentiation and integration.
tests/test.py Testing suite containing all unit tests.

Both of the above files have corresponding __init__.py files.

Setup File Description
.gitignore List of files to ignore during git push/pull requests.
CONTRIBUTING.md Instructions for potential contributors to the differint project.
LICENSE MIT license agreement.
MANIFEST.in Selects the README file for uploading to PyPi.
README.md This README file.
README.rst This README file in ReStructuredText format.
init.py __init__ file for overall package.
changelog.txt List of updates to package.
setup.py Script for downloading package from pip.

Example Usage

Taking a fractional derivative is easy with the differint package. Let's take the 1/2 derivative of the square root function on the interval [0,1], using the Riemann-Liouville definition of the fractional derivative.

import numpy as np
import differint.differint as df

def f(x):
   return x**0.5

DF = df.RL(0.5, f)
print(DF)

You can also specify the endpoints of the domain and the number of points used as follows.

DF = df.RL(0.5, f, 0, 1, 128)

For a description of all functions, their signatures, and more usage examples, see the project's wiki.

Tests

All tests can be run with nose from the command line. Setup will automatically install nose if it is not present on your machine.

python setup.py tests

Alternatively, you can run the test script directly.

cd <file_path>/differint/tests/
python test.py

API Reference

In this section we cover the usage of the various functions within the differint package.

Main Function Usage
GLpoint Computes the GL differintegral at a point
GL Computes the GL differintegral over an entire array of function values using the Fast Fourier Transform
GLI Computes the improved GL differintegral over an entire array of function values
CRONE Calculates the GL derivative approximation using the CRONE operator.
RLpoint Computes the RL differintegral at a point
RL Computes the RL differintegral over an entire array of function values using matrix methods
CaputoL1point Computes the Caputo differintegral at a point using the L1 algorithm
CaputoL2point Computes the Caputo differintegral at a point using the L2 algorithm
CaputoL2Cpoint Computes the Caputo differintegral at a point using the L2C algorithm
PCsolver Solves IVPs for fractional ODEs of the form ${}^CD^\alpha[y(x)]=f(x,y(x))$ using the predictor-corrector method
Auxiliary Function Usage
isInteger Determine if a number is an integer
isPositiveInteger Determine if a number is an integer, and if it is greater than 0
checkValues Used to check for valid algorithm input types
GLIinterpolat Define interpolating coefficients for the improved GL algorithm
functionCheck Determines if algorithm function input is callable or an array of numbers
poch Computes the Pochhammer symbol
Gamma Computes the gamma function, an extension of the factorial to complex numbers
Beta Computes the beta function, a function related to the binomial coefficient
MittagLeffler Computes the two parameter Mittag-Leffler function, which is important in the solution of fractional ODEs
GLcoeffs Determines the convolution filter composed of generalized binomial coefficients used in the GL algorithm
RLcoeffs Calculates the coefficients used in the RLpoint and RL algorithms
RLmatrix Determines the matrix used in the RL algorithm
PCcoeffs Determines the coefficients used in the PC algorithm

Contribute

To contribute to this project, see the contributing guidelines.

Credits

Baleanu, D., Diethelm, K., Scalas, E., & Trujillo, J.J. (2012). Fractional Calculus: Models and Numerical Methods. World Scientific.

Oldham, K.B. & Spanier, J. (1974). The Fractional Calculus: Theory and Applications of Differentiation and Integration to Arbitrary Order. Academic Press Inc.

Karniadakis, G.E.. (2019). Handbook of Fractional Calculus with Applications Volume 3: Numerical Methods. De Gruyter.

License

MIT © Matthew Adams

differint's People

Contributors

cooperhatfield avatar uniformlymatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

differint's Issues

L1_poly = CaputoL1point(-0.5, lambda x: x**2 - 1)

Your example here in the website:
L1_poly = CaputoL1point(-0.5, lambda x: x**2 - 1)
Gives an error from your code def CaputoL1point
if alpha <= 0 or alpha >= 1:
raise ValueError('Alpha must be in (0, 1) for this method.')
May I ask what am I missing?

PCsolver module not found error

I'm trying to use the PCsolver but no matter how I import differint or differint.differint, it gives me the same error of module not found.

How to use this for fractional derivatives at a point?

hi, i’d just like an example of how to use this to get fractional derivatives. I want to get fractional derivatives of a Gaussian. Seems like the RL function doesn’t return this (at least the numbers it returns do not seem to be the fractional derivative at a point, maybe they’re the integral of it or something)

So how would I do this?

Show singularities at endpoints

I use this to test:

import numpy as np
import differint.differint as df
import matplotlib.pyplot as plt

def f(t):
    return np.power(t, 3)

alpha = 0.6

t_1 = np.linspace(-1, 1, 100)
t_2 = np.linspace(0, 1, 100)
GL_1 = df.GL(alpha, f, -1, 1, 100)
GL_2 = df.GL(alpha, f, 0, 1, 100)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(t_1, GL_1, marker='o', markevery=5)
ax.plot(t_2, GL_2, marker='x', markevery=5)

plt.show()

And this is result. Obviously, 0.6 derivative of the function y = x^3 shouldn't be so low at endpoint.

In particular, its fractional derivative should be 0 at zero, but if you give differint to sovle [0,1], it would be wrong at x = 0.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.