Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:33+00:00 2026-06-03T07:23:33+00:00

I came across an interesting but rather annoying problem. I am trying to integrate

  • 0

I came across an interesting but rather annoying problem.

I am trying to integrate a function which has been calculated from a dataset.
The data can be found here: Link to sample.txt.

I start by fitting a line to my data. this can be done linear with approxfun or non-linear with splinefun. In my example below I use the latter.
Now, when I try to integrate the fitted function I run into the error

  • maximum number of subdivisions reached

but when I increase the subdivision I get

  • roundoff error

From the values in my sample code, you can see that for this specific dataset the threshold is 754->755.

My colleague has no problem to integrate this dataset in Matlab. Is there a way to manipulate my data to integrate? Is there another method for numerical integration in R?

enter image description here

data<-read.table('sample.txt',sep=',')
colnames(data)<-c('wave','trans')
plot(data$wave,data$trans,type='l')

trans<- -1 * log(data$trans)
plot(data$wave,trans,type='l')

fx.spline<-splinefun(data$wave,trans)

#Try either
Fx.spline<-integrate(fx.spline,min(data$wave),max(data$wave))
#Above: Number of subdivision reached
Fx.spline<-integrate(fx.spline,min(data$wave),max(data$wave),subdivisions=754)
#Above: Number of subdivision reached
Fx.spline<-integrate(fx.spline,min(data$wave),max(data$wave),subdivisions=755)
#Above: Roundoff error
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:23:35+00:00Added an answer on June 3, 2026 at 7:23 am

    There are many integration routines in R, and you can find some of them by ‘RSiteSearch’ing or by using the ‘sos’ package.

    For example, package pracma has several implementations, for instance

    quad(fx.spline,min(data$wave),max(data$wave))   # adaptive Simpson
    # [1] 2.170449                                  # 2.5 sec
    quadgk(fx.spline,min(data$wave),max(data$wave)) # adaptive Gauss-Kronrod
    # [1] 2.170449                                  # 0.9 sec
    quadl(fx.spline,min(data$wave),max(data$wave))  # adaptive Lobatto
    # [1] 2.170449                                  # 0.8 sec
    

    Please not that these are pure R scripts and therefore slower than, e.g., the compiled integrate routine with such an oscillating function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just came across the interesting problem of trying to trim the leading zeroes
I have came across very interesting problem which I think it's on Salesforce's end
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
While searching I came across this . It looks interesting but I have absolutely
I just came across an interesting problem with a procedure I am writing in
I came across a very interesting book. I have done some 2d games but
I came across an interesting problem today whilst implementing a feature into a dynamic
Today while helping someone I came across an interesting issue which I couldn't understand
I'm using CodeIgniter and I came across an interesting problem. I need to use
We just came across an interesting issue which we face during unit testing of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.