Problem to solve an integral equation
On Dec 17, 2013, at 8:53 AM, Aur?lien Philippot wrote:
Dear R experts,
I am trying to find numerical solutions for an integral equation.
Here is an example:
I started by defining the integrand, as a function of x and C, where x is
the variable of integration and C is the parameter I am interested in:
integrand<- function(C,x){-((100000*x)^(-1)-(1000*x+C)^(-1))*
1/(0.20*sqrt(2*pi))*exp(-0.5*(x-0.10)/(0.20))^2)}
Error: unexpected ')' in:
"integrand<- function(C,x){-((100000*x)^(-1)-(1000*x+C)^(-1))*
1/(0.20*sqrt(2*pi))*exp(-0.5*(x-0.10)/(0.20))^2)"
Taking out the last parenthesis resulted in a variety of error messages including:
output(0)
Error in integrate(integrand, C = C, lower = 0, upper = Inf) : extremely bad integrand behaviour
output(-10)
Error in integrate(integrand, C = C, lower = 0, upper = Inf) : the integral is probably divergent
Then, I integrate with respect to x, and define an objective function (output) with respect to C: output<- function(C) integrate(integrand, C=C, lower=0, upper=Inf)$value
Generally these problems are solved with the use of something along the lines of
sapply( seq(...), output) # across an appropriate domain
Or using the `Vectorize` function.
But since you did not supply tested code for the integrand, I am not proceeding further.
--
david.
I would like all the values of C (if any) for which the integral is equal
to 0.
I did the following:
library(rootSolve)
uniroot.all(output, c(0,1000000))
but that does not work ("evaluation of function gave a result of wrong
length"). I cannot either plot the function using plot or curve. I don't
understand what is going on?
Thanks in advance for any advice!
Aurelien
David Winsemius Alameda, CA, USA