Questions tagged [uniroot]

33 questions
0
votes
0 answers

How to find the input of a function given we have the output

I have a function that is calcualting a profitmargin (PM) given a principal(P). PMfunction<- function(P,InterestRate,Expenses){ ... There are quite a lot of calcualtions in the middle that come off a table and it's irrelevant ... return(PM) } I now…
Fizboy
  • 1
  • 2
0
votes
0 answers

Error in integrate : evaluation of function gave a result of wrong length after Vectorize

I am trying to simulate survival data from a Weibull PH model with a time varying covariate. I wrote a function invS that integrates the hazard function containing the time-varying component. Then I used the uniroot function with invS as a function…
Faithhhhhh
  • 131
  • 5
0
votes
2 answers

Update value in function using uniroot

Just some smaller changes which do not need to be considered.
0
votes
1 answer

how to predict x given y for nls model?

I am using the nls SSlogis function in R to make a model expressing water absorption in a plant, where y=water absorption (g per m^2), and x=minutes in water. For a given y value (in this case max water absorption), I would like to solve for x (the…
treee
  • 13
  • 3
0
votes
1 answer

How can I combine uniroot and lapp/overlay function from terra package to perform raster calculation?

I am trying to lapp from terra package to solve an equation with raster cells and uniroot function. I am stuck on how to get the final raster output from combining lapp and uniroot functions. I would be thankful for any kind of…
0
votes
1 answer

Solving a single variable equation in R using unitroot

I have a complicated equation for which I have written the code as follows: sigma = 1.336449027; f_t = 0.500185113; alpha = 0.364; #elasticity of capital beta = 0.115; #elasticity of labor R = 3.131696599; chi = 0.5; M = log(1056); sigma =…
riskiem
  • 187
  • 2
  • 7
0
votes
1 answer

Why can't I use uniroot with plot?

I am working on code that uses the uniroot function to approximate the root of an equation. I am trying to plot the behaviour of the function being passed through uniroot as the value of a free variable changes: library(Deriv) f1 <- function(s) { …
Tim C
  • 3
  • 2
0
votes
1 answer

Uniroot solution two equatations

I posted similar question a few days later, but now I have more complex problem. I have this dataset product = data.frame(length = c(100, 200, 300, 400), qty = c(1, 2, 1, 3)) And price is defined by this equation (product[["length"]] * old_const *…
onhalu
  • 735
  • 1
  • 5
  • 17
0
votes
0 answers

RuntimeWarning: invalid value encountered in power scipy.optimize root

basically I am trying to reproduce an example from a website because I want to find the equivalent to the R uniroot for python. I found a blog entry (https://waterprogramming.wordpress.com/2016/08/18/root-finding-in-matlab-r-python-and-c/) where the…
scriptgirl_3000
  • 161
  • 3
  • 16
0
votes
1 answer

Why is uniroot.all throwing unused variable error when root function has multiple arguments?

Once in a blue moon I need to use the lovely uniroot.all function from the rootSolve package to find the root(s) of a function with multiple arguments. Every time I do this I run into a bunch of snags which I eventually resolve, but then forget how…
ben
  • 787
  • 3
  • 16
  • 32
0
votes
1 answer

How to avoid uniroot error that stops the loop

I am running uniroot function in the loop, but hit an error and the code stopped. The code is as below; func <-function(f) -a*b/c*0.5*d*e^2 + (d/f-1)*g*sin(h*(pi/180))-i dat <- data.frame(a = c(0.99,0.99,0.99), b =…
imtaiky
  • 191
  • 1
  • 12
0
votes
1 answer

How can I avoid uniroot error that stops the loop?

I am running uniroot function in the loop, but hit an error and the code stopped. The code is as below; func <-function(f) -a*b/c*0.5*d*e^2 + (d/f-1)*g*sin(h*(pi/180))-i dat <- data.frame(a = c(0.99,0.99,0.99), b =…
imtaiky
  • 191
  • 1
  • 12
0
votes
1 answer

R function "uniroot": get some mistake

FX <- function(x)(3/4)*(1-x^2) M <- 5000 X2 <- rep(NA,M) for (i in 1:M) { U2 <- runif(1) fct <- function(x)FX(x)-U2 X2[i] <- uniroot(fct,c(-1,1))$root } I have tried to do this R-code but I every time I get a mistake saying: Error in…
Lifeni
  • 159
  • 5
0
votes
1 answer

Uniroot Upper and Lower values in R

I trying to find the solution of the following using uniroot() in R. library(rootSolve) set.seed(2) y=rgamma(10,5,2) myfun=function(y,t)as.numeric(integrate(function(x){ ((x^4) * exp(-x/2))/768 },0,upper=2)[1])-t myfun(y,…
score324
  • 687
  • 10
  • 18
0
votes
0 answers

error in uniroot() in R, f.lower = f(lower) is NA + actual example

here is my code, a3<- c(-1141591.0, -1192686.3, -402424.1, -418201.6, -439137.0, -654150.5, -670148.4 , -696922.9, -719566.3, -766338.7, -794186.4 ,-812940.5, -835722.0, -856374.3) a2<- c(271925.56, 284085.61, 95976.92, …
Mathica
  • 1,241
  • 1
  • 5
  • 17