解决一个只有一个未知数的非线性方程系统

huangapple go评论66阅读模式
英文:

Solving a system of non-linear equations with only one unknown

问题

I is equal to P1 - P2 = 0
P1 <- (mu_L[i]^(-1)(w_L/delta)^delta)
P2 <- (mu_H[i]^(-1)
(w_H/alpha)^alpha)

task <- seq(0.01,1, by = 0.01)
alpha <- 0.55
delta <- 0.83
mu_H <- task
mu_L <- 1-task
L_L <- 0.8
L_H <- 0.2
Y <- 40000
I_start <- 0.5
I <- I_start

w_H <- alpha * I * (Y / L_H)
w_L <- delta*(1-I)*(Y / L_L)

In the definition of I, it is the task (i) in which the price of low-skill production minus the price of high-skill production is zero. the value of mu is dependent on the industry and by finding for which value of mu, the equation equals zero, one can find which industry I is. mu high is equal to i, while mu low is (1-i). i indicating the task from a uniform distribution between 0 and 1.

I have written a for loop to account for the dynamic modeling but cannot figure out how to pin down I in this, all non-linear system solvers require two unknowns for two equations and I cannot figure out how to code it in such a way that it is equal to zero as a condition.

I have tried the following approaches:

using range:
range2 <- seq(0.01,1, by = 0.001)
range <- (1 - range2)
range[which(range^(-1)(w_L/delta)^delta == range2^(-1)(w_H/alpha)^alpha)]

The issue is that the answer lies between step 14 and 15, and as the steps are too large there is no exact match found. Also not when I increase the steps to 1e-8, at some point I get an error that there are too many steps. If I could add a tolerance level here that might be the solution, however, I don't know how I can do that. I tried it like this:

r <- range^(-1)(w_L/delta)^delta - range2^(-1)(w_H/alpha)^alpha
rr <- ifelse(r<0.01, print(TRUE), print(FALSE))
data.r <- data.frame(r, rr)
length(unique(data.r$rr))

but the tolerance might be too small, at the same time, the difference must be between 0 and 1, as the mu is limited between 0 and 1. So I feel that a tolerance of 0.01 is not asking too much. In theory, that should work.

I tried the nleqslv package, but it gives me answers outside of the range [0,1].

dslnex <- function(x) {
y <- numeric(2)
y1 <- (x1^(-1)(w_L/delta)^delta)
y[2] <- (x[2]^(-1)
(w_H/alpha)^alpha)
y
}
xstart=c(0.5, 0.5)
nleqslv(xstart, dslnex, control = list())

I am hoping to find for which value of mu such that the two equations for price are equal to each other so I can pin down the task (i) in which this is.

英文:

I am trying to pin down the barrier between high-skill technology and low-skill technology industries in the Task-Based model of the labor market. This takes place in the task in which the price of production is equal to each other.

解决一个只有一个未知数的非线性方程系统

    I is equal to P1 - P2 = 0    
    P1 &lt;- (mu_L[i]^(-1)*(w_L/delta)^delta)
    P2 &lt;- (mu_H[i]^(-1)*(w_H/alpha)^alpha)

It is part of a dynamic problem in which wage is dependent on I and I on wage. The relevant further equations are wage high and low: wage high and wage low. L_L, the labour supply linked to low and high-skill is based on data and around 0.8 for L_L and 0.2 for L_H. Y is for now set on 40,000 also based on data.

task &lt;- seq(0.01,1, by = 0.01)
alpha &lt;-  0.55 
delta &lt;- 0.83
mu_H &lt;- task
mu_L &lt;- 1-task
L_L &lt;- 0.8
L_H &lt;- 0.2
Y &lt;- 40000
I_start &lt;- 0.5
I &lt;- I_start
   
w_H &lt;- alpha * I * (Y / L_H) 
w_L &lt;- delta*(1-I)*(Y / L_L)

In the definition of I, it is the task (i) in which the price of low-skill production minus the price of high-skill production is zero. the value of mu is dependent on the industry and by finding for which value of mu, the equation equals zero, one can find which industry I is. mu high is equal to i, while mu low is (1-i). i indicating the task from a uniform distribution between 0 and 1.

I have written a for loop to account for the dynamic modelling but cannot figure out how to pin down I in this, all non-linear system solvers require two unknown for two equations and I cannot figure out how to code it in such a way that it is equal to zero as a condition.

I have tried the following approaches:

using range:

range2 &lt;- seq(0.01,1, by = 0.001)
range &lt;- (1 - range2)
range[which(range^(-1)*(w_L/delta)^delta == range2^(-1)*(w_H/alpha)^alpha)]

The issue is that the answer lies between step 14 and 15, and as the steps are too large there is no exact match found. Also not when I increase the steps to 1e-8, at some point I get an error that there are too many steps. If I could at a tolerance level here that might be the solution, however, I dont know how I can do that. I tried it like this:

r &lt;- range^(-1)*(w_L/delta)^delta - range2^(-1)*(w_H/alpha)^alpha
rr &lt;- ifelse(r&lt;0.01, print(TRUE), print(FALSE))
data.r &lt;- data.frame(r, rr)
length(unique(data.r$rr))

but the tolerance might be too small, at the same time, the difference must be between 0 and 1, as the mu is limited between 0 and 1. So I feel that a tolerance of 0.01 is not asking too much. In the theory that should work.

I tried the nleqslv package but it gives me answers outside of the range [0,1].

dslnex &lt;- function(x) {
  y &lt;- numeric(2)
  y[1] &lt;- (x[1]^(-1)*(w_L/delta)^delta)
  y[2] &lt;- (x[2]^(-1)*(w_H/alpha)^alpha)
  y 
}
xstart=c(0.5, 0.5)
nleqslv(xstart, dslnex, control = list())

I am hoping to find for which value of mu such that the two equations for price are equal to each other so I can pin down the task (i) in which this is.

答案1

得分: 1

以下是翻译好的部分:

你可以使用 uniroot() 来实现这个功能:

f <- function(x) {
   (1/x)*(w_L/delta)^delta - (1/(1-x))*(w_H/alpha)^alpha
}
uniroot(f, c(1e-2, 1))

解决方案:

$root
[1] 0.888271

$f.root
[1] -1.03622

$iter
[1] 9

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

如果需要更高精度,可以减小容差:uniroot(f, c(1e-2, 1), tol = 1e-8) 可以得到一个根为 0.8882506。

英文:

You can use uniroot() for this:

f &lt;- function(x) {
   (1/x)*(w_L/delta)^delta - (1/(1-x))*(w_H/alpha)^alpha
}
uniroot(f, c(1e-2, 1))

Solution:

$root
[1] 0.888271

$f.root
[1] -1.03622

$iter
[1] 9

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

For more precision (if you need it) you can reduce the tolerance: uniroot(f, c(1e-2, 1), tol = 1e-8) gives a root at 0.8882506

huangapple
  • 本文由 发表于 2023年2月19日 00:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定