Skip to content

Conversation

@Erennn7
Copy link
Contributor

@Erennn7 Erennn7 commented Oct 18, 2025

PR: Simpson’s Rule for Numerical Integration in R

This PR introduces a fully documented implementation of Simpson’s Rule in R, a numerical integration technique that approximates the definite integral of a function using quadratic polynomials.
Simpson’s Rule provides higher accuracy than the Trapezoidal Rule by approximating the area under the curve with parabolic arcs rather than straight line segments.

Overview

The simpson_rule function divides the integration interval ([a, b]) into an even number of subintervals and applies quadratic interpolation to estimate the integral.
Key features include:

  • Handles arbitrary continuous functions and numeric intervals
  • Provides both standard and vectorized implementations for improved performance
  • Computes approximate integrals and can compare against exact values if known
  • Supports convergence studies by varying the number of subintervals
  • Demonstrates accuracy and applicability for common functions, including sin(x), , e^x, and probability density functions

Simpson’s Rule is widely used in applications such as:

  • Scientific computing and physics simulations
  • Signal processing and data analysis
  • Probability, statistics, and areas under curves
  • Computer graphics and visualization

Complexity

  • Time Complexity: O(n), where n = number of subintervals
  • Space Complexity: O(n) for storing x-values

@Erennn7 Erennn7 requested a review from siriak as a code owner October 18, 2025 09:58
Copilot AI review requested due to automatic review settings October 18, 2025 09:58
@Erennn7 Erennn7 requested a review from acylam as a code owner October 18, 2025 09:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an implementation of Simpson's Rule for numerical integration in R, providing both a standard and vectorized approach to approximate definite integrals using quadratic polynomial interpolation.

Key Changes:

  • Implements simpson_rule() function with input validation and error handling
  • Adds a vectorized version simpson_rule_vectorized() for improved performance
  • Provides comprehensive examples demonstrating convergence, accuracy, and various use cases

Copilot AI review requested due to automatic review settings October 19, 2025 06:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings October 19, 2025 06:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@Erennn7
Copy link
Contributor Author

Erennn7 commented Oct 20, 2025

@siriak please have a look

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit f697081 into TheAlgorithms:master Oct 24, 2025
2 checks passed
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.

2 participants