Skip to main content

This Python package containts functions that do numeric differentiation.

Project description

FirstSecondNumericDiff

A Python class for computing first and second-order numerical derivatives using finite difference methods.

Features

  • Computes first and second derivatives using:
    • Forward Difference
    • Backward Difference
    • Central Difference
  • Handles uniformly spaced data.
  • Provides warning when handling non-uniformly spaced data.
  • Provides error handling for invalid data formats.

Installation

This class requires Python.

Usage

To use this module, import it from the numeric_diff package like this:

from numeric_diff import first_second_numeric_diff

And use it like this:

x_data = [1, 2, 3, 4, 5] y_data = [7.5, 8.3, 9.1, 10.8, 12] order = 'First' method = 'Forward'

x_output, y_output = first_second_numeric_diff(x_data, y_data, order, method)

Methods

init(x_data, y_data, order, method)

Initializes the numerical differentiation class

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
    • order (str): Numerical differentiation order.
    • method (str): Numerical differentiation method.

__first_second_numeric_differentiation(x_data, y_data, order, method)

Computes the specified derivative.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
    • order (str): Numerical differentiation order. Options:
      • 'first': Calculates first-order derivative.
      • 'second': Calculates second-order derivative.
    • method (str): Numerical differentiation method. Options:
      • 'forward': Uses forward difference.
      • 'backward': Uses backward difference.
      • 'central': Uses central difference.

__first_order_differentiation(x_data, y_data, method)

Computes the first derivative.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
    • method (str): Numerical differentiation method. Options:
      • 'forward': Uses forward difference.
      • 'backward': Uses backward difference.
      • 'central': Uses central difference.
    • Returns: list of independent variable values and list of first derivative values.

__second_order_differentiation(x_data, y_data, method)

Computes the second derivative.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
    • method (str): Numerical differentiation method. Options:
      • 'forward': Uses forward difference.
      • 'backward': Uses backward difference.
      • 'central': Uses central difference.
    • Returns: list of independent variable values and list of second derivative values.

__forward_diff_first_order(x_data, y_data)

Computes the first derivative with forward difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

__backward_diff_first_order(x_data, y_data)

Computes the first derivative with backward difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

__central_diff_first_order(x_data, y_data)

Computes the first derivative with central difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

__forward_diff_second_order(x_data, y_data)

Computes the second derivative with forward difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

__backward_diff_second_order(x_data, y_data)

Computes the second derivative with backward difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

__central_diff_second_order(x_data, y_data)

Computes the second derivative with central difference.

  • Parameters:
    • x_data (list, tuple, set, or NumPy array): Independent variable values.
    • y_data (list, tuple, set, or NumPy array): Dependent variable values.
  • Returns: list of independent variable values and list of first derivative values.

Notes

  • If x_data type is not valid, an Exception will rise.
  • If y_data type is not valid, an Exception will rise.
  • If x_data and y_data do not have the same length, an Exception will rise.
  • If length of x_data and y_data is less than 2, an Exception will rise.
  • If the elements of x_data and y_data are not valid float values, an Exception will rise.
  • If order type is not valid, an Exception will rise.
  • If method type is not valid, an Exception will rise.
  • If length of x_data and y_data is less than 3 for second-order derivative, an Exception will rise.
  • If length of x_data and y_data is less than 3 for first-order derivative with central difference, an Exception will rise.

Authors

Juan David Amaya Carreño - jd.amaya20@uniandes.edu.co

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numeric_diff-1.0.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numeric_diff-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file numeric_diff-1.0.0.tar.gz.

File metadata

  • Download URL: numeric_diff-1.0.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for numeric_diff-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b4002c9145c99b7502aaf067859c1bc865a07f2befb84e223320f2b436ce99b1
MD5 e566c9e241e4a3c3011aae1f0490d3b7
BLAKE2b-256 1dc2ed77cad6bd736f0b2cdc594321ca2e9abb8e3bd26430ecd94ff4a21712e5

See more details on using hashes here.

File details

Details for the file numeric_diff-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: numeric_diff-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for numeric_diff-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bc55808786cfa52ba62d51f27d4ad967987ca3b7e80b34c0154bd3d6f99b919
MD5 016cdcc060081ecc08d54a098ee35c5d
BLAKE2b-256 cfe04ca24ff82922d7e7b08c926ec63b05fd614861f7982229c33b4b271f6b4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page