0

I am looking for a fixed point x when f(x)=x of a function, ofcourse numerically, but I have no idea how to solve it with R, I am trying with fsolve with following code, but possibly its not the right way to write this...I am not getting anything...Many thanks in advance

library(pracma)  
p<- c(x=0.1, y=0.1)
f1 <- function(p) {
                expPfLeft<- (160*p[1]) + ((1-p[1])*200)
                expPfRight<- (10*p[1])+ ((1-p[1])*370)
                expPfTop <- (200*p[2]) + ((1-p[2])*160)
                expPfBottom <- (370*p[2]) + ((1-p[2])*10) 

                return(c (exp(2*expPfLeft)/((exp(2*expPfLeft)+exp(2*expPfRight))) , 
                          exp(2*expPfTop)/((exp(2*expPfTop))+(exp(2*expPfBottom))) ) )


        }


fsolve(f1,p)

1 Answer 1

1

Assuming your function is defined correctly. You are looking for f(p[1], p[2]) = c(p[1], p[2])

You can create fix your answer by changing the return statement to:

return(c(exp(2*expPfLeft)/((exp(2*expPfLeft)+exp(2*expPfRight))), exp(2*expPfTop)/((exp(2*expPfTop))+(exp(2*expPfBottom)))) - p)

We can observe that your optimization function are actually two independent functions. p[1] is used in Left and Right. p[2] is used in Top and Bottom.

We can separate your functions.

f.x <- function(p) {
  expPfLeft<- (160*p) + ((1-p)*200)
  expPfRight<- (10*p)+ ((1-p)*370)
  return(exp(2*expPfLeft)/((exp(2*expPfLeft)+exp(2*expPfRight))) - p)
}

f.y <- function(p) {
  expPfTop <- (200*p) + ((1-p)*160)
  expPfBottom <- (370*p) + ((1-p)*10) 
  return(exp(2*expPfTop)/((exp(2*expPfTop))+(exp(2*expPfBottom))) - p)
}

Simplifying your expression so we can cheat a little for the starting value

enter image description here

We can see that there is only one approximate approximate solution at x = 1.

fsolve(f.x, 1)

$x
[1] 1

$fval
[1] 0

And similarly for the second function, there is a solution at 0.4689.

fsolve(f.y, 0.1)

$x
[1] 0.4689443

$fval
[1] 4.266803e-09

Doing all this defeats the purpose of optimization, and leads me to believe that your optimization function is mis-defined.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot mate, yes it should be -p, ofcourse. I am stupid!!! but I guess I did some other mistake in defining the function, the problem is there is some recursive structure in the modelling, which I am not fully getting how to write, but as soon as I get that I will try to make it more clear.....Thank you so much.It is actually a matching pennies game and I am looking for a Quantal Response Equilibria

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.