similar to: Do loop

Displaying 20 results from an estimated 10000 matches similar to: "Do loop"

2003 Apr 26
2
Multiple Integration
Dear all, May I do multiple integration using R? I was looking adapt but it is saying it integrates a scalar function over a multidimensional rectangle. I have integrand of several variable and upper, lower limit too variable. I wanted to see the result using adapt (though it is not for this purpose, I suppose) Func<-function(x){(x[1]*x[2])} adapt(2, lo=c(0,1), up=c(1,x[1]), functn=Func) it
2008 Mar 07
3
Numerical Integration in 1D
Dear UseRs, I'm curious about the derivative of n!. We know that Gamma(n+1)=n! So when on takes the derivative of Gamma(n+1) we get Int(ln(x)*exp(-x)*x^n,x=0..Inf). I've tried code like > integrand<-function(x) {log(x)*exp(x)*x^n} > integrate(integrand,lower=0,upper=Inf) It seems that R doesn't like to integrate for any n, and I was wondering if anyone knew a way around
2008 Aug 26
2
Problem with Integrate for NEF-HS distribution
I need to calcuate the cumulative probability for the Natural Exponential Family - Hyperbolic secant distribution with a parameter theta between -pi/2 and pi/2. The integration should be between 0 and 1 as it is a probability. The function "integrate" works fine when the absolute value of theta is not too large. That is, the NEF-HS distribution is not too skewed. However, once the
2011 Nov 10
2
performance of adaptIntegrate vs. integrate
Dear list, [cross-posting from Stack Overflow where this question has remained unanswered for two weeks] I'd like to perform a numerical integration in one dimension, I = int_a^b f(x) dx where the integrand f: x in IR -> f(x) in IR^p is vector-valued. integrate() only allows scalar integrands, thus I would need to call it many (p=200 typically) times, which sounds suboptimal. The
2012 Oct 20
4
Error in integrate(integrand, 0, Inf) : non-finite function value
Dear R users, When I run the code below, I get the error "Error in integrate(integrand, 0, Inf) : non-finite function value". The code works if the function returns only "sum(integ)". However, I want to add "cmh" to it. When I add "cmh" I get that error. I can't figure out why this is happening because my integrate function has nothing to do with
2011 Jun 06
2
Taking Integral and Optimization using Integrate, Optim and maxNR
Dear All, Hello! I have some questoins in R programming as follows: Question 1- How to take the integral of this function with respect to y, such that x would appear in the output after taking integral. f(x,y)=(0.1766*exp(-exp(y+lnx))*-exp(y+lnx))/(1-exp(-exp(y+lnx))) y in (-6.907,-1.246) It is doable in maple but not in R. At least I could not find the way. p.s: result from maple is:
2005 Nov 16
1
Error in integrate
Hi! I am a beginner of R. I am trying to calculate integrate and draw a graph of the output, but just kept on getting error messages. I list my program and error message below. Please help. Many Thanks! ======================= + > a<--11 > b<-0.1 > c<-0.012 > x<-0:110 > t<-0:15 > integrand<-function(x) {exp(-exp(a-c*t)*(exp(b*x)-exp(c*x))/(b-c))} >
2010 Oct 29
2
what´s wrong with this code?
Hello, I want to maximize a likelihood function expressed as an integral that can not be symbolically evaluated. I expose my problem in a reduced form. g<- function(x){ integrand<-function(y) {exp(-x^2)*y} g<-integrate(integrand,0,1) } h<-function(x) log((g(x))) g is an object of the class function, but g(2) is a integrate object, I can print(g(2))
2018 Mar 23
1
Integrate erros on certain functions
In the help for ?integrate: >When integrating over infinite intervals do so explicitly, rather than just using a large number as the endpoint. This increases the chance of a correct answer ? any function whose integral over an infinite interval is finite must be near zero for most of that interval. I understand that and there are examples such as: ## a slowly-convergent integral integrand
2010 Feb 09
1
how to adjust the output
Hi R-users,   I have this code below and I understand the error message but do not know how to correct it.  My question is how do I get rid of “with absolute error < 7.5e-06” attach to value of cdf so that I can carry out the calculation.   integrand <- function(z) { alp  <- 2.0165   rho  <- 0.868   # simplified expressions   a      <- alp-0.5   c1     <-
2012 Oct 17
1
for loop output
Dear R users, In the code below, I am trying to print the result of my loop function. The output first gives me the result for k=1, and then for k=1 and k=2. I only want the last output which is [,1] [,2] [1,] 0.1700065 0.5002659 [2,] 0.3080273 0.4954731 [3,] 0.4844886 0.4544306 [4,] 0.5062987 0.1868154 [5,] 0.5846982 0.4353522 [6,] 0.4332621 0.2202922 [7,] 0.4391985
2010 Jan 02
2
ifelse and piecewise function
I am a novice user of "R" and I'm learning with R version 2.8.1, using WinEdt_1.8.1, under Widows Vista Home Version. ## The test function below, from a vector input, returns vector values: # and it contains an "ifelse"statement TEST<- function(x) { low<- -x^2 up<- x^4 ifelse(x>=0,up,low ) } u<- seq(-1,1,0.5) TEST(u)
2013 Apr 09
1
Solving an integral in R gives the error “The integral is probably divergent”
I am trying to solve an integral in R. However, I am getting an error when I am trying to solve for that integral. The equation that I am trying to solve is as follows: $$ C_m = \frac{{abs{x}}e^{2x}}{\pi^{1/2}}\int_0^t t^{-3/2}e^{-x^2/t-t}dt $$ [image: enter image description here] The code that I am using is as follows: a <- seq(from=-10, by=0.5,length=100) ## Create a function to compute
2012 May 23
1
numerical integration
Greetings, Sorry, the last message was sent by mistake! Here it is again: I encounter a strange problem computing some numerical integrals on [0,oo). Define $$ M_j(x)=exp(-jax) $$ where $a=0.08$. We want to compute the $L^2([0,\infty))$-inner products $$ A_{ij}:=(M_i,M_j)=\int_0^\infty M_i(x)M_j(x)dx $$ Analytically we have $$ A_{ij}=1/(a(i+j)). $$ In the code below we compute the matrix
2008 Aug 27
5
Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Hey fellas: I would like to integrate the following function: integrand <- function (x,t) { exp(-2*t)*(2*t)^x/(10*factorial(x)) } with respect to the t variable, from 0 to 10. The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44. I have tried Vectorize to no avail. Thanks in advance, jose romero
2010 Dec 22
3
How to integrate a function with additional argument being a vector or matrix?
Dear expeRts, I somehow don't see why the following does not work: integrand <- function(x, vec, mat, val) 1 # dummy return value A <- matrix(runif(16), ncol = 4) u <- c(0.4, 0.1, 0.2, 0.3) integrand(0.3, u, A, 4) integrate(integrand, lower = 0, upper = 1, vec = u, mat = A, val = 4) I would like to integrate a function ("integrand") which gets an "x" value (the
2013 Feb 12
2
integrate function
Hi All, Can any one help to explain why min and max function couldn't work in the integrate function directly. For example, if issue following into R: integrand <- function(x) {min(1-x, x^2)} integrate(integrand, lower = 0, upper = 1) it will return this: Error in integrate(integrand, lower = 0, upper = 1) : evaluation of function gave a result of wrong length However, as min(U,V) =
2012 Oct 19
2
likelihood function involving integration, error in nlm
Dear R users, I am trying to find the mle that involves integration. I am using the following code and get an error when I use the nlm function d<-matrix(c(1,1,0,0,0,0,0,0,2,1,0,0,1,1,0,1,2,2,1,0),nrow=10,ncol=2) h<-matrix(runif(20,0,1),10) integ<-matrix(c(0),nrow=10, ncol=2) ll<-function(p){ for (k in 1:2){ for(s in 1:10){ integrand<-function(x)
2010 Sep 21
3
bivariate vector numerical integration with infinite range
Dear list, I'm seeking some advice regarding a particular numerical integration I wish to perform. The integrand f takes two real arguments x and y and returns a vector of constant length N. The range of integration is [0, infty) for x and [a,b] (finite) for y. Since the integrand has values in R^N I did not find a built-in function to perform numerical quadrature, so I wrote my own after
2011 Jun 25
1
integration function
Hi all, Can anyone please take a look at the following two functions. The answer does not seem to be right. Thank you very much! f1 <- function(x) {integrand <- function (x, mu){ dnorm(x, mean=mu, sd=1)*dnorm(mu, mean=2, sd=1) } integrate(integrand, -Inf, Inf,x)$val } f2 <- function(x) {integrand <- function (x, mu){