0

I have an implicit function, and I'm trying to plot the derivative of the solution of this function.

The function is:


p = \[Phi]/(1/\[Beta]) + ((1 - \[Phi]) \[Phi] (1 - \[Lambda]) \
\[Beta])/(((W - A) 1/\[Beta] + \[Phi] A/
      p) 1/\[Beta] + \[Phi]*(1 - \[Phi]) A/p)/(
 1/\[Beta] (\[Lambda]/((W - A) 1/\[Beta] + \[Phi] (A/
      p)  ) + (1 - \[Lambda])/(((W - A) 1/\[Beta] + \[Phi] A/
         p) 1/\[Beta] + \[Phi] (1 - \[Phi]) A/p)))

And I would like to plot the derivative of the following expression w.r.t \[Phi]

\[Phi]/p ((1-\[Phi]) A + 1/\[Beta] A )

I've been trying to first solve for p explicitly, and plug the solution into the expression above and plot the derivative of the expression, but kept getting an error. My code is :

Manipulate[
 ans = p /. 
   Solve[p - \[Phi]/(
      1/\[Beta]) - ((1 - \[Phi]) \[Phi] (1 - \[Lambda]) \[Beta])/(((W \
- A) 1/\[Beta] + \[Phi] A/p) 1/\[Beta] + \[Phi]*(1 - \[Phi]) A/p)/(
      1/\[Beta] (\[Lambda]/((W - A) 1/\[Beta] + \[Phi] (A/
           p)  ) + (1 - \[Lambda])/(((W - A) 1/\[Beta] + \[Phi] A/
              p) 1/\[Beta] + \[Phi] (1 - \[Phi]) A/p))) == 0, p],
 Plot[Evaluate[
   D[f[\[Phi]] == \[Phi]/
      ans[[2]] ((1 - \[Phi]) A + 1/\[Beta] A), \[Phi]]], {\[Phi], 
   0.01, 1}], {A, 10, 500}, {\[Beta], 0.001, 1}, {W, 100, 
  10^9}, {\[Lambda], 0.01, 1}]

The error I'm getting is:

"Manipulate:Manipulate argument \
Plot[Evaluate[\!\(\*SubscriptBox[\(\[PartialD]\), \(\[Phi]\)]\((f[\
\[Phi]] == \((\[Phi]\\\ Power[<<2>>])\)\\\ \((Times[<<2>>] + 
     Times[<<2>>])\))\)\)],{\[Phi],0.01,1}] does not have the correct \
form for a variable specification"

What am I doing wrong?

Thank you!

  • 1
    First change the comma between your `Solve` and `Plot` into a semicolon. See if that is enough to fix your problem. Second we do not know what your function f is so we cannot try our changes to your code to see if our fixes work. Third you are trying to plot D[f[φ] == φ/ans[[2]]... and that is going to be the derivative of True or False. It is not clear to me what the derivative of True or False is going to be or what a plot of that would look like. – Bill Aug 02 '21 at 17:14
  • Thank you, @Bill ! A few follow-up questions: 1. Replacing comma with semicolon got rid of the error. I thought semicolon just hides the output, why would it make a difference? 2. The function f[φ] is supposed to be φ/ans[[2]]*((1-φ)A+1/\[Beta]A). I'm defining f[φ] inside D[], is that wrong? 3. There are 2 equations here. The first is inside `Solve`. `p` is an implicit equation, and I use `Solve` to solve for it explicitly. The second equation is `φ/p*((1-φ)A + 1/beta A)`, where I replace p with the second solution from `Solve`. I might be doing it wrong. – fatpandabot Aug 02 '21 at 17:45
  • With semicolon instead of comma, the code runs, but the plot is empty. Would anyone know what's going on? – fatpandabot Aug 02 '21 at 18:51
  • 1
    First the help page shows `Manipulate[expr,{u,min,max}]` and not `Manipulate[expr1,expr2,{u,min,max}]` and Mathematica sees `expr1;expr2` as one expression. Next when any plot doesn't work I always try replacing `Plot` with `Table` so `Table[Evaluate[D[f[φ]==φ/ans[[2]]((1-φ)A+1/β A),φ]],{φ,0.01,1,0.1}]` or even `Table[f[φ]==φ/ans[[2]]((1-φ)A+1/β A),{φ,0.01,1,0.1}]` to see what it is that you are trying to differentiate. I do not see you defining `f` anywhere in that. Maybe try `ans=...;f[φ_]:=...;Table[f[φ],{φ,0.01,1,0.1}]` and see what you get. When you get a `Table` that works then try Plot – Bill Aug 02 '21 at 19:40

0 Answers0