# Question) How should I solve this equation from a finite-state Markov chain?

**URL:** <https://discourse.julialang.org/t/question-how-should-i-solve-this-equation-from-a-finite-state-markov-chain/55947>\
**Category:** General Usage\
**Created:** [February 24, 2021, 6:04pm UTC](https://discourse.julialang.org/t/question-how-should-i-solve-this-equation-from-a-finite-state-markov-chain/55947 "2021-02-24T18:04:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)\
**Post date:** [February 24, 2021, 6:04pm UTC](https://discourse.julialang.org/t/question-how-should-i-solve-this-equation-from-a-finite-state-markov-chain/55947/1 "2021-02-24T18:04:13Z")

</div>

I have 2,001 states, and say the transition matrix of Markov chain is given. Then there is a variable x(s) attached to each state s \in \{1,...,2001\}, and I have to solve the following equation for any x(s):

\frac{a}{f(x(s))}+x(s)=b+\mathbb{E}\_{s}[\frac{1}{f(x(s'))}] .

where the function f is non-linear.

I understood this problem as solving a system of non-linear equations, so I used nlsolver package.  
I could solve for 50 states, but for 2,001 states, I think I will never get my result as I have to simulate this problem 10,000 times.

This is a replication exercise, and the author mentions that this is a fairly simple numerical exercise. Would there be another approach to solve this problem more time efficiently?

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [February 24, 2021, 7:06pm UTC](https://discourse.julialang.org/t/question-how-should-i-solve-this-equation-from-a-finite-state-markov-chain/55947/2 "2021-02-24T19:06:08Z")

</div>

So you are looking for a fixed point of `x=T(x')`.  
If `T` is a contraction mapping, iteration over `x=T(x')` will converge to the fixed point.  
But this approach requires that you can efficiently compute `x(s)` from the LHS of your equation. That depends on what `f` looks like.

Do you have any additional information about `x` (e.g. monotonicity)?

---

<div class="post-metadata">

**Author:** ![Zerosum](https://avatars.discourse-cdn.com/v4/letter/z/b2d939/32.png) [@Zerosum](https://discourse.julialang.org/u/Zerosum)\
**Post date:** [February 25, 2021, 11:25am UTC](https://discourse.julialang.org/t/question-how-should-i-solve-this-equation-from-a-finite-state-markov-chain/55947/3 "2021-02-25T11:25:37Z")

</div>

Thank you very much!

I could solve with NLsolver package fixedpoint function.  
It takes only like 1/10 of time now!
