Code Monkey home page Code Monkey logo

1d-function-integrator's Introduction

1D Function Integrator

This repository contains a simple Python class called Integrator that numerically integrates a given function f(x).

Usage

To use the Integrator class, follow these steps:

  1. Clone the repository:

    git clone https://github.com/your-username/1D-Function-Integrator.git
  2. Import the Integrator class into your Python script:

    from integrator import Integrator
  3. Define your own function to integrate, similar to the f(x) function provided in the example:

    import numpy as np
    
    def f(x):
        return (x**2) * np.exp(-x) * np.sin(x)
  4. Create an instance of the Integrator class, providing the function, minimum and maximum values for integration, and the number of intervals:

    examp = Integrator(f, 1, 3, 200000)
    • f: The function to integrate.
    • xMin: The minimum value for integration.
    • xMax: The maximum value for integration.
    • N: The number of intervals for integration.
  5. Perform the integration by calling the integrate() method:

    examp.integrate()
  6. Display the result by calling the show() method:

    examp.show()

    This will print the rounded result of the integration.

  7. Run your Python script:

    python your_script.py

Example

The provided example demonstrates how to use the Integrator class to integrate the function f(x) = x^2 * exp(-x) * sin(x):

import numpy as np
from integrator import Integrator

def f(x):
    return (x**2) * np.exp(-x) * np.sin(x)

def main():
    examp = Integrator(f, 1, 3, 200000)
    examp.integrate()
    examp.show()

if __name__ == "__main__":
    main()

The integration is performed over the interval [1, 3] using 200,000 intervals (N = 200000). The result is then displayed using the show() method.

Feel free to modify the function and integration parameters to suit your needs.

References

This project is based on an assignment of the Coursera course Simulation and modeling of natural processes (https://www.coursera.org/learn/modeling-simulation-natural-processes).

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.