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 8417373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:01:30+00:00 2026-06-10T02:01:30+00:00

I want to integrate a function fun_integrate that has a vector vec as an

  • 0

I want to integrate a function fun_integrate that has a vector vec as an input parameter:

fun_integrate <- function(x, vec) { 
  y <- sum(x > vec)
  dnorm(x) + y
}

#Works like a charm
fun_integrate(0, rnorm(100))

integrate(fun_integrate, upper = 3, lower = -3, vec = rnorm(100))
300.9973 with absolute error < 9.3e-07
Warning message:
  In x > vec :
  longer object length is not a multiple of shorter object length

As far as I can see, the problem is the following: integrate calls fun_integrate for a vector of x that it computes based on upper and lower. This vectorized call seems not to work with another vector being passed as an additional argument. What I want is that integrate calls fun_integrate for each x that it computes internally and compares that single x to the vector vec and I’m pretty sure my above code doesn’t do that.

I know that I could implement an integration routine myself, i.e. compute nodes between lower and upper and evaluate the function on each node separately. But that wouldn’t be my preferred solution.

Also note that I checked Vectorize, but this seems to apply to a different problem, namely that the function doesn’t accept a vector for x. My problem is that I want an additional vector as an argument.

  • 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-10T02:01:31+00:00Added an answer on June 10, 2026 at 2:01 am
    integrate(Vectorize(fun_integrate,vectorize.args='x'), upper = 3, lower = -3, vec = rnorm(100),subdivisions=10000)
    
    304.2768 with absolute error < 0.013
    
    
    #testing with an easier function
    test<-function(x,y) {
      sum(x-y)
    }
    
    test(1,c(0,0))
    [1] 2
    
    test(1:5,c(0,0))
    [1] 15
    Warning message:
    In x - y : 
    longer object length is not a multiple of shorter object length
    
    Vectorize(test,vectorize.args='x')(1:5,c(0,0))
    [1]  2  4  6  8 10
    
    #with y=c(0,0) this is f(x)=2x and the integral easy to solve
    integrate(Vectorize(test,vectorize.args='x'),1,2,y=c(0,0))
    3 with absolute error < 3.3e-14 #which is correct
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to integrate facebook like button into my website . My website has
I want to integrate the MySQL fulltext search function in my PHP site. I
jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
I have an anonymous function in matlab: f=@(x) x/(1+x^4) . I want to integrate
I want to integrate .live() into this function: $('a.oembed').each(function(){ $(this).embedly({maxWidth:400,'method':'replace'}).bind('embedly-oembed', function(e, oembed){ $(this).parent().append($(<img>, {
I am making a C function to integrate into Python that basically creates a
i want to integrate an affiliate script with a shopping cart, for that i
I want to integrate a probability density function from (-\infty, a] because the cdf
I want integrate CPD (Copy-Paste-Detection) to my iOS project. I read about it here
i want to integrate Struts with Hibernate. I am new to these technologies. Infortunately

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.