Questions tagged [uniroot]

33 questions
3
votes
2 answers

Find the x that gives a specific value of a function

I have this function: a <- 1 b <- 2 get_y <- function (x,a,b) { a * b * x } And I want to create a function that takes in get_y and returns the x that makes y = 4 for example. How would I do that?
Victor Nielsen
  • 443
  • 2
  • 14
2
votes
2 answers

Error in uniroot while calculating XIRR in R

Reproducible example: v <- c(-400000.0,-200000.0, 660636.7) d <- c("2021-10-27","2022-12-23","2023-01-04") d1 <- as.Date(d, format="%Y-%m-%d") tvm::xirr(v, d1) # gives the error below Error in uniroot(xnpv, interval = interval, cf = cf, d = d, tau…
ottodidakt
  • 3,631
  • 4
  • 28
  • 34
2
votes
2 answers

Solve for X row by row

I'll start with what I've done already. I'm looking for a way to solve equation f by changing the b and s parameters for each row, Q and n are constants. I know that apply() works for this type of problem, but that doesn't seem to work for me. The…
2
votes
0 answers

nsga2 Constraints - mco package in R

My objective function considers ellipse arc lengths. Within the objective function, I use uniroot to find the semi-minor axis b for the semi-major a and arc angle provided by nsga. I've written a constraint function to ensure that the limits…
user1375871
  • 1,199
  • 1
  • 12
  • 23
1
vote
1 answer

How to optimize an equation in R

Suppose f(u,v)=v(1+theta(1-v)(1-2u))=t, where u and t are uniform(0,1) random samples and theta=0.5. How can I optimize the value of v in R? I tried to make a code using uniroot in r, but it gave me an error. How can I optimize the value of v? Here…
Anakha K K
  • 11
  • 2
1
vote
1 answer

Solve improper double integral using integrate and uniroot functions

We have a function. t ~ Weibull(alpha, lambda) and c ~ Exponential(beta): Given p = 0.10, alpha = 1, lambda = 4. Find the value of beta. We want to integrate this function for t then to c. Then find the value of beta where integral equals to p…
1
vote
1 answer

Identifying uniroot for multiple independent variables in R

I am trying to calculate the value of x where y = 0. I could able to do it for single x using the following code lm.model <- lm(y ~ x) cc <- coef(lm.model) f <- function(x) cc[2]*x + cc[1] plot(x, y) abline(coef(lm.model)) abline(h=0,…
UseR10085
  • 7,120
  • 3
  • 24
  • 54
1
vote
0 answers

Dplyr calculation gives an error and stops running the calculations

I'm trying to calculate IRRs with cashflow datas that I have for my data's funds. I try this with following code: install.packages("tvm") library(dplyr) library(tvm) var1 <- my_data %>% group_by(Fund_name) %>% mutate(DATE = as.Date(DATE)) %>% …
Jaakko
  • 11
  • 1
1
vote
1 answer

uniroot gives multiple answers to equation with 1 unknown

I want to create a column in a data frame in which each row is the solution to an equation with 1 unknown (x). The other variables in the equation are provided in the other columns. In another Stack Overflow question, @flodel provided a solution,…
1
vote
1 answer

Find root using uniroot

I'm trying to find a root of the following function (based on the Gamma (gamma()) function) using the uniroot() function: cv = 0.056924/1.024987^2 fx2 = function(theta, eta){ p1 = 1 - 2/(theta*(1-eta)) p2 = 1 - 1/(theta*(1-eta)) return((…
Alien
  • 116
  • 8
1
vote
0 answers

R uniroot: Solving an unknown variable in uniroot from a function with multiple arguments

I am trying to obtain the value of a variable that is inside a log by using the uniroot function. In the function with the equation I want to solve, I intend on having a vector argument so that I can multiply values from that vector to each log. I…
Alex
  • 11
  • 1
1
vote
1 answer

uniroot() function in source code does not work with modification; Could not figure out the error

I was trying to find out coordinates of the intersection of two curves in R. The input data are coordinates of empirical points from the two curves. My solution is to use the function curve_intersect(). I need to do this for 2000 replications (i.e.,…
Athena
  • 27
  • 5
1
vote
1 answer

solving equations with variables on both sides with r

0.5Q+30 = −0.2Q+100 0.5q+0.2q=100-30 70=0.7q q=70/0.7 q=100 0.5*100+30 =80 Is there a package that solves equations with variables on both sides?
KmnsE2
  • 424
  • 2
  • 9
0
votes
0 answers

R: bug in pwr.t.test or why is it not counting?

I faced the problem with the library(pwr) and its function pwr.t.test. An example from statistical textbook: library(pwr) pwr::pwr.t.test(-0.228, sig.level =0.05, power=0.80, type = "one.sample", alternative="less") # Error in uniroot(function(d)…
0
votes
0 answers

Solve a dynamic system of equations by optimizing a function

I want to solve a dynamic set of equations that from a algebraic perspective a = bX, where a is a vector of 1's, b is a vector of discount factors and X is a lower triangular matrix of cash flows. I want to solve for X; however, as far as my…
1
2 3