# How to manipulate a plot with intermediate parameters

optV[r_, λ_, μ_, η_, σ_] :=
V /. FindRoot[{A V^θ h[V, c,
r, λ, μ, η, σ] == V - c,
D[A V^θ h[V, c, r, λ, μ, η, σ], V] == 1}, {A, 0}, {V, 1}];
a[r_, λ_, μ_, η_, σ_] :=
A /. FindRoot[{A V^θ h[V, c, r, λ, μ, η, σ] == V - c,
D[A V^θ h[V, c, r, λ, μ, η, σ], V] == 1}, {A, 0}, {V, 1}];
Manipulate[Plot[Evaluate[{F[V, c, r, λ, μ, η, σ],
nv[V, c],
F [V, c, r, λ, μ, η, σ] /.
V -> optV[c, r, λ, μ, η, σ]}, {V, 0, 3},
PlotRange -> All], Frame -> {True, True, False, False},
FrameLabel -> {"Construction Cost", "Land Value"},
ImageSize -> {500, 350}],
{{r, 0.04, "risk‐free rate"}, .01, .2, Appearance -> "Labeled"},
{{μ, .08, "risk-adjusted discount rate"}, .01, .2, Appearance -> "Labeled"},
{{σ, 0.2,"standard deviation"}, .01, 0.5, Appearance -> "Labeled"},
{{c, 1, "construction cost"}, 0, 3, Appearance -> "Labeled"},
{{λ, 1, "long-term average price"}, 0, 2, Appearance -> "Labeled"},
{{η, .05, "speed of reversion"}, .01, .2, Appearance -> "Labeled"},
Initialization :> (
θ[r_, λ_, μ_, η_, σ_] :=
1/2 + (μ - r - η λ)/σ^2 + Sqrt[((r - μ + η λ)/σ^2 - 1/2)^2 + 2 r/σ^2];
b[r_, λ_, μ_, η_, σ_] :=
2 θ[r, λ, μ, η, σ] + 2 (r - μ + η λ)/σ^2;
h[V_, r_, λ_, μ_, η_, σ_] :=
Hypergeometric1F1[θ[r, λ, μ, η, σ],
b[r, λ, μ, η, σ], 2 η V/σ^2];
F[V_, c_, r_, λ_, μ_, η_, σ_] :=
a[c, r, λ, μ, η, σ]*V^θ [r, λ, μ, η, σ]*h[V, r, λ, μ, η, σ];
nv[V_, c_] := Max[0, (V - c)];
)]


How could I manipulate a plot in such situation: two of the parameters, a and optV, are numerical solutions of equation set. The parameters of the equation set are not constant but variables c, r, λ, μ, η, σ. They are also parameters of the expression I would like to manipulate, namely F [V, c, r, λ, μ, η, σ].

-
Dear lcet, this is your fourth question posted on the site. People are generally finding them hard to follow. It is often not clear what you are wanting. That is one reason you are getting downvotes. The other is that you are dumping large amounts of hard-to-read code in your questions. Please simplify your code to a minimum working example, and use normal letters instead of greek letters for parameters. –  Verbeia Jun 18 '13 at 22:35
lcet, good job for deciding how to handle the functions with replacements in their body. I appreciate this updated code. We might have resolved issues in the chat, but lcet has not enough reputation. I do not see how he could have communicated the new code, as his previous question was closed. Formatting code with special characters like [Lambda] in them is hard but not impossible, so I don't blame lcet for displaying the code in this form. Anyway, lcet you should have provided links to your other questions and you should have at least mentioned that you were (cont...) –  Jacob Akkerboom Jun 19 '13 at 12:27
passing the wrong number of arguments, this has been pointed out to you before. Conclusion: let's not let the questions score get below -3 :P. –  Jacob Akkerboom Jun 19 '13 at 12:28
Lcet, please let me know if my answer is what you want.. –  Jacob Akkerboom Jun 25 '13 at 10:57
@JacobAkkerboom Thank you very much for your patience and kind help and sorry for not coming here for long time. I accept the all the blame for my number of arguments but actually I am newbie of Mathmatica and I am not sure how many arguments I should use in each function. But it seems that the answer is still not what I want. The reason I dumped codes was that I thought the logic is quite simple and professinals can handle it: there is an equation set required to be soloved in Initialization. In order to plot, the equation set should be solved but its coefficients are input variables. –  lcet Jul 4 '13 at 12:07

Let me dump some working code here. Sorry for the poor formatting.

θ[r_, λ_, μ_, η_, σ_] := 1/2 + (μ - r - η λ)/σ^2 +
Sqrt[((r - μ + η λ)/σ^2 - 1/2)^2 + 2 r/σ^2];
b[r_, λ_, μ_, η_, σ_] := 2 θ[r, λ, μ, η, σ] + 2 (r - μ + η λ)/σ^2;
h[V_, r_, λ_, μ_, η_, σ_] := Hypergeometric1F1[θ[r, λ, μ, η, σ],
b[r, λ, μ, η, σ],
2 η V/σ^2];
F[V_, c_, r_, λ_, μ_, η_, σ_] := a[r, λ, μ, η, σ]*V^θ[r, λ, μ, η, σ]*h[V, r, λ, μ, η, σ];
nv[V_, c_] := Max[0, (V - c)];

a[r_, λ_, μ_, η_, σ_] := A/.FindRoot[{
A V^θ[r, λ, μ, η, σ] h[V, r, λ, μ, η, σ] == V-c,
D[A V^θ[r, λ, μ, η, σ] h[V, r, λ, μ, η, σ], V] == 1
}, {A, 0}, {V, 1}];

optV[r_, λ_, μ_, η_, σ_] := V /. FindRoot[{
A V^θ[r, λ, μ, η, σ] h[V, r, λ, μ, η, σ] == V - c,
D[A V^θ[r, λ, μ, η, σ] h[V, r, λ, μ, η, σ], V] == 1
}, {A, 0}, {V, 1}];


Where I have just corrected the number of arguments supplied to each function. We can then do

Manipulate[
Block[
{c = cRep},
Plot[Evaluate[{F[V, c, r, λ, μ, η, σ],
nv[V, c],
F[V, c, r, λ, μ, η, σ] /. V -> optV[r, λ, μ, η, σ]
}],
{V, 0, 3}, PlotRange -> All, Frame -> {True, True, False, False},
FrameLabel -> {"Construction Cost", "Land Value"}, ImageSize -> {500, 350}]
]
, {{r, 0.04, "risk\[Hyphen]free rate"}, .01, .2, Appearance -> "Labeled"},
{{μ, .08, "risk-adjusted discount rate"}, .01, .2, Appearance -> "Labeled"},
{{σ, 0.2, "standard deviation"}, .01, 0.5, Appearance -> "Labeled"},
{{cRep, 1, "construction cost"}, 0, 3, Appearance -> "Labeled"},
{{λ, 1, "long-term average price"}, 0, 2, Appearance -> "Labeled"},
{{η, .05, "speed of reversion"}, .01, .2, Appearance -> "Labeled"}]


Where I have corrected the arguments that Evaluate "surrounds". In your code there was some doubt wether or not to pass c as an argument. I have solved the issue by removing the passing of c everywhere and using Block to make c known to all the functions.

-
@Kuba thanks for editing :). –  Jacob Akkerboom Jul 16 '13 at 8:49
You're welcome. :) –  Kuba Jul 16 '13 at 8:53