0
$\begingroup$

I try to solve a complicated equation. To do that, I write (excuse me, I could not copy paste in an appropriate way from the notebook) ;

m[n_,θ_]:=-(((θ+ρ)+h z-(θ (1-n) (1-ω))/((1-α) λ)+λ n)^((α/(1-α)))/((λ^2 n ((h z)/Exp[β λ n]+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n)^(α/(1-α)) ((((θ+ρ)+h z-(θ (1-n) (1-ω))/((1-α) λ)+λ n)/((h z)/Exp[β λ n]+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n))^(α/(1-α))/Exp^[λ n (β/(1-α)+γ)+λ n]+1))/(1-n)^α))+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n

I try to solve this equation for variable "n" and I give values for $\theta$ between $0$ and $1$.

I use the calibration in the following way ;

paramFinal = {ρ -> 0.01, γ -> 0.5, ω -> 0.05, ψ -> 15.55, α -> 0.4, β -> 0.3, λ -> 0.5, h -> 0.05, z -> 0.08};

Firstly, I proceed in a following way ;

sol[i_] := NSolve[m[n, i] == 0 /. paramFinal, n];
Table[sol[i], {i, 0.5, 1}];
solution = sol[i];

This one did not work. I also try ?NumericQ way to solve it.

sol3[i_?NumericQ] := {n, i} /. 
NSolve[m[n, i] == 0 /. paramFinal, n, Reals]
tab = Table[sol3[i], {i, 0, 1}]

It did not work neither, it remains always in "Running..." mode. Unfortunately, I can not simplify the expression mathematically.

How can I proceed to solve this equation ? Thanks in advance for all suggestions.

$\endgroup$
6
  • 1
    $\begingroup$ Do you mean E or e? $\endgroup$
    – Michael E2
    Commented Nov 1, 2016 at 18:05
  • 1
    $\begingroup$ Your syntax defining m is incorrect. $\endgroup$
    – Michael E2
    Commented Nov 1, 2016 at 18:05
  • 1
    $\begingroup$ Something like this?: FindRoot[m[n, 0.5] == 0 /. paramFinal, {n, 0.9}], FindRoot[m[n, 0.5] == 0 /. paramFinal, {n, -0.9}] $\endgroup$
    – Michael E2
    Commented Nov 1, 2016 at 18:10
  • $\begingroup$ @MichaelE2 I edited the syntax concerning exponential and brackets for "m". Sorry for that. Yes, I try to find values for "n" for different $\theta$ values. $\endgroup$ Commented Nov 1, 2016 at 18:12
  • $\begingroup$ Now you have another syntax error: Syntax::sntxf: "Exp^" cannot be followed by "[λ n(β/(1-α)+γ)+λ n]" -- Drop the ^. There are other instances of e^(...), too. $\endgroup$
    – Michael E2
    Commented Nov 1, 2016 at 18:15

1 Answer 1

2
$\begingroup$

Update

In your equation is still a syntax error Exp^. I have corrected this error. The solutions I've found are correct.

paramFinal = {ρ -> 0.01, γ -> 0.5, ω -> 0.05, ψ -> 15.55, α -> 0.4, β -> 
    0.3, λ -> 0.5, h -> 0.05, z -> 0.08};

m[θ_]=-(((θ+ρ)+h z-(θ (1-n) (1-ω))/((1-α) λ)+λ n)^((α/(1-α)))/((λ^2 n ((h z)/Exp[β λ n]+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n)^(α/(1-α)) ((((θ+ρ)+h z-(θ (1-n) (1-ω))/((1-α) λ)+λ n)/((h z)/Exp[β λ n]+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n))^(α/(1-α))/Exp[λ n (β/(1-α)+γ)+λ n]+1))/(1-n)^α))+(θ+ρ)-(θ (1-n) (1-ω))/((1-α) λ)+λ n/.paramFinal

  sol=Table[First@FindInstance[m[i] == 0, n], {i, 0, 5}] // Chop
    {{n -> 0.987955}, {n -> 0.911649}, {n -> 0.854773}, 
    {n -> 0.819723}, {n -> 0.796528}, {n -> 0.780113}}

Table[m[i] /. sol[[i + 1]], {i, 0, 5}] // Chop
{0, 0, 0, 0, 0, 0}

An addition

With θ between 0 and 1, the roots are in the range [-2, 1], as shown by the plots. Now we have "seeds" to feed FindRoot (start point).

Multicolumn[Plot[m[#], {n, -5, 2}] & /@ Range[0, 1, 0.1] // Quiet, 3]

enter image description here

FindRoot[m[#] == 0, {n, 1}] & /@ Range[0, 1, 0.1] // Chop

enter image description here

FindRoot[m[#] == 0, {n, -1}] & /@ Range[0, 1, 0.1] // Chop

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks a lot ! There is a point that I did not understand on the code. How you give the value for $\theta$ ? because as you define the function m, just in terms of "n", I don't see how $\theta$ plays a role. $\endgroup$ Commented Nov 1, 2016 at 19:27
  • $\begingroup$ Also, when I run exact the same code, I get error messages. $\endgroup$ Commented Nov 1, 2016 at 19:35
  • 1
    $\begingroup$ @ optimal control I have made an update. m[n_] is a copy and paste error, sorry. $\endgroup$
    – user36273
    Commented Nov 1, 2016 at 23:00
  • $\begingroup$ Thanks a lot ! This helped really a lot ! $\endgroup$ Commented Nov 2, 2016 at 11:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.