Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Integration Calculator #1994

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sakshamjain98
Copy link
Contributor

@Sakshamjain98 Sakshamjain98 commented Feb 6, 2025

Fixes Issue🛠️

Closes #1974

Integration Calculator

An advanced web-based calculator for computing single, double, and triple integrals with an intuitive user interface.

##Screenshot
image

Features

  • Multiple Integration Types

    • Single Integration (1D)
    • Double Integration (2D)
    • Triple Integration (3D)
  • Modern User Interface

    • Clean, responsive design
    • Dynamic input fields
    • Real-time error feedback
    • Helper text for function syntax
  • Advanced Calculation Features

    • Support for complex mathematical functions
    • Midpoint method for improved accuracy
    • Optimized performance for multi-dimensional integration
    • Comprehensive error handling

Usage

Basic Operation

  1. Select the integration type (single, double, or triple)
  2. Enter your mathematical function using JavaScript syntax
  3. Input the integration limits for each variable
  4. Click "Calculate" to see the result

Function Syntax

  • Use standard JavaScript mathematical operators: +, -, *, /, **
  • Available mathematical functions:
    • Math.sin(x), Math.cos(x), Math.tan(x)
    • Math.exp(x), Math.log(x)
    • Math.sqrt(x), Math.pow(x, n)

Example Inputs

// Single Integration
x * x                  // Integrate x² from a to b
Math.sin(x)           // Integrate sin(x) from a to b

// Double Integration
x * y                 // Integrate xy over a region
Math.exp(x + y)       // Integrate e^(x+y) over a region

// Triple Integration
x * y * z             // Integrate xyz over a volume
Math.sin(x) * y * z   // Integrate sin(x)yz over a volume

Technical Details

Integration Methods

  • Single Integration: Trapezoidal Rule with n=1000 points
  • Double Integration: Midpoint Method with n=50 points per dimension
  • Triple Integration: Midpoint Method with n=20 points per dimension

Error Handling

The calculator includes comprehensive error checking for:

  • Invalid function syntax
  • Missing or invalid limits
  • Non-numeric inputs
  • Potential security issues in function evaluation

Performance Considerations

  • Optimized point counts for multi-dimensional integration
  • Efficient function evaluation
  • Dynamic UI updates without page reload

Implementation Details

Core Functions

// Single Integration (Trapezoidal Rule)
function trapezoidalRule(func, a, b, n = 1000) {
    const h = (b - a) / n;
    let sum = (evaluateFunction(func, {x: a}) + evaluateFunction(func, {x: b})) / 2;
    
    for (let i = 1; i < n; i++) {
        const x = a + i * h;
        sum += evaluateFunction(func, {x});
    }
    return sum * h;
}

// Double Integration (Midpoint Method)
function doubleIntegral(func, ax, bx, ay, by, n = 50) {
    const hx = (bx - ax) / n;
    const hy = (by - ay) / n;
    let sum = 0;

    for (let i = 0; i < n; i++) {
        for (let j = 0; j < n; j++) {
            const x = ax + (i + 0.5) * hx;
            const y = ay + (j + 0.5) * hy;
            sum += evaluateFunction(func, {x, y});
        }
    }
    return sum * hx * hy;
}

// Triple Integration (Midpoint Method)
function tripleIntegral(func, ax, bx, ay, by, az, bz, n = 20) {
    const hx = (bx - ax) / n;
    const hy = (by - ay) / n;
    const hz = (bz - az) / n;
    let sum = 0;

    for (let i = 0; i < n; i++) {
        for (let j = 0; j < n; j++) {
            for (let k = 0; k < n; k++) {
                const x = ax + (i + 0.5) * hx;
                const y = ay + (j + 0.5) * hy;
                const z = az + (k + 0.5) * hz;
                sum += evaluateFunction(func, {x, y, z});
            }
        }
    }
    return sum * hx * hy * hz;
}

Security Considerations

  • Function evaluation is done using a safe subset of JavaScript
  • Input validation prevents injection attacks
  • No external dependencies or eval() usage

Future Improvements

  • Add support for parametric integration
  • Implement adaptive integration methods
  • Add visualization of integration regions
  • Include common integration formulas library
  • Add step-by-step solution display
  • Support for symbolic integration

Copy link

netlify bot commented Feb 6, 2025

👷 Deploy request for calcdiverse pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3dd9bac

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Sakshamjain98, Welcome to the project CalcDiverse! 🎊
Thanks for your contribution! Your effort makes this project better. Keep it up! 🙌
Please wait for the PR to be reviewed. Happy Coding!! ✨

@Sakshamjain98
Copy link
Contributor Author

Merge it please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add Integration Calculator
1 participant