Re: [R] uniroot

2006-07-30 Thread Uwe Ligges
nurza m wrote:
 Hello,
 
 I am struggling to find the root of a exponent 
 function.
 uniroot is complaining about a values at end points
 not of opposite sign?

And you think it is not the case? Why?
We cannot help because you have not given a reproducible example (What 
is w and gp?), which the posting guide asks you to do.

Please also format your code in a way that is easy for others to read, 
including some blanks and without all those  and +:


saeqn - function(s, l)
{
 p - exp(-l$gp$lambda + s) * l$gp$c
 k11 - (l$gp$mu * (l$gp$lambda^2) * l$gp$c -
 s * l$gp$lambda * l$gp$c * l$gp$mu +
 l$gp$mu * l$gp$lambda) * p
 k12 - -l$gp$mu * l$gp$lambda -
s^2 + 2 * s * l$gp$lambda - (l$gp$lambda^2)
 k13 - k11 + k12
 k14 - (l$gp$lambda - s) *
(-l$gp$mu * s - s * l$gp$lambda + s^2 +
 l$gp$mu * l$gp$lambda * p)
 k1 - -k13 / k14
 k1 - l$t
}


s - sapply(seq(along = w), function(i) {
 uniroot(saeqn, lower = -5000, upper = 0.01036597923,
 l = list(t = w[i], gp = gp))$root
 }
)



  
 s- sapply(1:length(w),function(i)
 +  {
 +  
 + + 
 + 
 +
 uniroot(saeqn,lower=-5000,upper=0.01036597923,l=list(t=w[i],gp=gp))$root
 +  })
 Error in uniroot(saeqn, lower = -5000, upper =
 0.01036597923, l = list(t = w[i],  : 
 f() values at end points not of opposite sign
 
 
 
  
 and here is my fonction saeqn.
 
 
 
saeqn-function(s,l)
 
 +  {
 + 
 + 
 + p- exp(-l$gp$lambda+s)*l$gp$c
 + 
 + 
 +
 k11-(l$gp$mu*(l$gp$lambda^2)*l$gp$c-s*l$gp$lambda*l$gp$c*l$gp$mu+l$gp$mu*l$gp$lambda)*p
 + 
 + k12 -
 -l$gp$mu*l$gp$lambda-s^2+2*s*l$gp$lambda-(l$gp$lambda^2)
 + 
 + k13 -k11+k12
 + 
 +
 k14-(l$gp$lambda-s)*(-l$gp$mu*s-s*l$gp$lambda+s^2+l$gp$mu*l$gp$lambda*p)
 + 
 + k1- -k13/k14
 + 
 +  k1-l$t
 +  }
 
  
 
 . There is something I must be missing since I never
 had 
 luck with uniroot!
 
 Thanks,
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] uniroot

2006-07-29 Thread nurza m
Hello,

I am struggling to find the root of a exponent 
function.
uniroot is complaining about a values at end points
not of opposite sign?

 
s- sapply(1:length(w),function(i)
+  {
+  
+ + 
+ 
+
uniroot(saeqn,lower=-5000,upper=0.01036597923,l=list(t=w[i],gp=gp))$root
+  })
Error in uniroot(saeqn, lower = -5000, upper =
0.01036597923, l = list(t = w[i],  : 
f() values at end points not of opposite sign
 


 
and here is my fonction saeqn.


 saeqn-function(s,l)
+  {
+ 
+ 
+ p- exp(-l$gp$lambda+s)*l$gp$c
+ 
+ 
+
k11-(l$gp$mu*(l$gp$lambda^2)*l$gp$c-s*l$gp$lambda*l$gp$c*l$gp$mu+l$gp$mu*l$gp$lambda)*p
+ 
+ k12 -
-l$gp$mu*l$gp$lambda-s^2+2*s*l$gp$lambda-(l$gp$lambda^2)
+ 
+ k13 -k11+k12
+ 
+
k14-(l$gp$lambda-s)*(-l$gp$mu*s-s*l$gp$lambda+s^2+l$gp$mu*l$gp$lambda*p)
+ 
+ k1- -k13/k14
+ 
+  k1-l$t
+  }

 

. There is something I must be missing since I never
had 
luck with uniroot!

Thanks,

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] UNIROOT

2005-01-14 Thread aar paar
f(x) = .01*(1.2^y) integrated from 0 to x
Find x such that
f(x) = some number, say 4
How do we do it in R?
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] UNIROOT

2005-01-14 Thread Gabor Grothendieck
aar paar aar420 at hotmail.com writes:

: 
: f(x) = .01*(1.2^y) integrated from 0 to x
: 
: Find x such that
: 
: f(x) = some number, say 4
: 
: How do we do it in R?

You don't need R for this.

Your integral can be solved analytically, check any 
table of integrals, and the rest can be solved using
elementary algebra so R is not needed here.  If you 
really do want to use R anyways:

g - function(y) .01 * 1.2^y
f - function(x) integrate(g, 0, x)$value - 4
uniroot(f, low = -100, up = 100)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html