0
$\begingroup$

Trying to solve a demand-supply equilibrium here and them find a partial derivative of the equilibrium with respect to the parameters.

S[q_] := -Log[q]
d[Il_, beta_] := phi*v*zeta/(1 - beta - delta)*(A/(v*zeta*(1 + phi*Il)))^(v/(v - 1))
S1[Il_, beta_, ig_] := S[(delta + beta)*i  - beta*ig - (1 - beta - delta)*Il]

d is the demand and S1 is the supply. The equilibrium price is expressed in terms of the parameters beta and ig.

f[beta_, ig_] := x /. Solve[d[x, beta] == S1[x, beta, ig], x, Reals][[1]]

Now I want to look at the partial derivative of the equilibrium wrt ig as a function of beta.

Eff[beta_] := D[f[beta, ig], ig] /. ig -> 0.03

But Eff() at any value is taking forever to compute. The function f() is well-defined and is giving me quick output when I plug in some arguments.

Is there anything wrong in the code or is it just computationally time-consuming?

Values of the symbols are as follows.

phi = 0.2
v = 1.5
zeta = 1
delta = 0.04
A = 1
i = 0.05
$\endgroup$
4
  • $\begingroup$ The problem is not Eff[], but The Solve n the definition of f`` . With all the undefined symbols like: phi, v, zeta, delta, ig` it is hard, to solve. Try giving numerical values to these symbols $\endgroup$ Apr 21 at 20:33
  • $\begingroup$ Yes. I had assigned values to them, which i missed out on mentioning. Edited now $\endgroup$
    – McLovin
    Apr 21 at 20:38
  • $\begingroup$ If I evaluate your code I get the error: Solve::nsmet: This system cannot be solved with the methods available to Solve. If you give the extra variables numeric values you might want to try NSolve instead of solve: the form of your equation is not one that can be inverted symbolically I think so you would have to resolve to numerical methods anyway $\endgroup$
    – Gert
    Apr 21 at 20:48
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Apr 22 at 0:53
0
$\begingroup$

If you replace Solve with NSolve and calculate your derivative the old fashioned way you can quickly evaluate it for enough values to make a proper plot.

phi=0.2; v=1.5; zeta=1; delta=0.04; A=1; i=0.05;

d[Il_,beta_]:=1. (phi v zeta)/(1-beta-delta) ( A/(v zeta(1+phi Il)))^(v/(v-1));

S1[Il_,beta_,ig_]:=-1. Log[(delta+beta)*i-beta*ig-(1-beta-delta)*Il]

f[beta_,ig_] := Module[{x},
    x/. NSolve[d[x,beta]==S1[x,beta,ig],x,Reals][[1]]
];
Eff[beta_, dx_] := (f[beta,0.03+dx]-f[beta,0.03])/dx;

By setting dx to 0.0001 you can calculate the derivative for any beta pretty quickly. (Note that I also put factors 1. in front of your functions to let Mathematica evaluate them numerically from the beginning.)

$\endgroup$
1
  • $\begingroup$ Thanks! That is indeed a quick fix to the problem $\endgroup$
    – McLovin
    Apr 22 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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