# Solving a nonlinear equation with random variable

I would like to solve an equation that looks like this

UPDATE

$E[(R^{1-\gamma})(r_k+\theta-r_z)]=0$ , where $R=\phi r_z+(1-\phi)(r_k+\theta)$ and $\phi\in[0,1]$,

$\theta$, is a random variable normaly distributed with zero mean, and some variance $\sigma^2$. Thus, the $E[.]$ stands for the expectation operator over this random variable.

An alternative version of the problem, solves a similar equation, but now $\theta$ is lognormally distributed.

The computational task, is to find $\phi$, such as the condition/equation above holds, for some given numbers/values for $r_z,r_k$ and $\gamma$ all of which are positive real numbers.

Can someone help on how I can calculate this, ideally in MATLAB ?

• Welcome to SciComp.SE! What do you mean by "optimizing an equation"? How do you know such a $\phi$ even exists? – Christian Clason Oct 18 '14 at 11:53
• This particular equation, comes from a first order condition of a maximization problem from a particular economic model. The nature of the problem and the theoretical foundations of the model, assure that a solution exist. I am interested on the computational task on how to solve this equation with respect to $\phi$, that's my main scope. I used the "optimize" in the sense that the $\phi$ has to satisfy this equation. – user17880 Oct 18 '14 at 12:09
• I see; that usage is slightly misleading so I took the liberty of editing your question accordingly. If you don't agree, feel free to revert the edit. – Christian Clason Oct 18 '14 at 14:01
• Not a problem at all. Thx for the effort anyway. – user17880 Oct 18 '14 at 14:18

Since $\phi$ is a scalar between $0$ and $1$, the easiest method for finding a root is bisection. If you cannot calculate the expectation of the nonlinear function $$f_\phi(\theta) = \left(\phi r_z +(1-\phi)(r_k+\theta)\right)^{1-\gamma}(r_k+\theta-r_z)$$ in terms of $\phi$ analytically, you can use quadrature to approximate. For the first variant, this amounts to $$E[f_\phi(\theta)] = \frac{1}{\sigma\sqrt{2\pi}}\int_{-\infty}^{\infty} e^{-\frac{t^2}{2\sigma^2}} f_\phi(t)\,dt \approx \sum_{i=1}^N \frac{w_i}{\sqrt{\pi}} f_\phi(\sqrt2 \sigma t_i),$$ where $t_i$ and $w_i$ are the Gauss-Hermite quadrature nodes and weights of order $N$. If $\theta$ is log-normally distributed, then $\theta=e^\beta$, where $\beta$ is normally distributed, so you can just replace $t_i$ by $s_i:=e^{t_i}$ in the above to get a quadrature rule (with the same weights) for the log-normal variant.
• One clarifications, by $R_{\phi}(\sqrt(2)\sigma t_i)$ you mean that $R_{\phi}$ is a function of the term or it multiplies the term ? I understood the second. Second, why we do not also multiply with the $\sqrt(2)\sigma t_{i}$ since the expection that i want to estimate it multiplies the nonlinear function with the random variable. – user17880 Oct 18 '14 at 18:26
• Thanks for the clarification. But something that cannot understand then, since I have to approximate $E[R^{1-\gamma}\theta]$. Using your notation, this shouldn't be $$E[R_\phi(\theta)*\theta] = \frac{1}{\sigma\sqrt{2\pi}}\int_{-\infty}^{\infty} e^{-\frac{t^2}{2\sigma^2}} R_\phi(t)\,dt \approx \sum_{i=1}^N \frac{w_i}{\sqrt{\pi}} R_\phi(\sqrt2 \sigma t_i)*\sqrt2 \sigma t_i,$$ ? since theta also multiplies the $R^{1-\gamma}$. Is something that I am missing? – user17880 Oct 19 '14 at 12:17
• Maybe you wish to ignore my last, I thought you defined $R_{\phi}$ in the way I defined $R$ – user17880 Oct 19 '14 at 12:22