Can someone help me understand why function mu
found below does not execute when everything before it seems ok.
Cc = 1
Cw = 1
δ = 1.3
(the following function finds a root of an expression)
MM[μ_, λ1_, T1_, n1_] := FindRoot[2 Sqrt[Cc Cw E^((m1 δ)/n1) n1] +
Cc E^((m1 δ)/n1) n1 T1 λ1 -
m1 ((Cc Cw E^((m1 δ)/n1) δ)/Sqrt[Cc Cw E^((m1 δ)/n1) n1] +
Cc E^((m1 δ)/n1) T1 δ λ1) + μ == 0, {m1, 10}][[1, 2]]
MM[6, 2, 3, 100]
77.9641628564483
(MM seems to work)
(*The following function solves differential equation using NDSolve. It seems to work ok.)
w[μ_?NumericQ, λT_?NumericQ, T_?NumericQ, n_?NumericQ] :=
{cc = μ T λT;
λ = λT/T; M = MM[μ, λ, T, n];
{x[0], x} /.NDSolve[{ 1/(2 Cw λT x[t]^3)
Sqrt[Cc Cw E^((δ Derivative[1][x][t])/x[t])
λT x[t]] (2 x[t]^2 (Cw λT +
T λSqrt[Cc Cw E^((δ Derivative[1][x][t])/x[t]) λT x[t]])
+ δ^2 (Cw λT +
2 T λ Sqrt[Cc Cw E^((δ Derivative[1][x][t])/x[t]) λT x[t]])
Derivative[1][x][t]^2 - δ x[t] (Cw λT +
2 T λSqrt[Cc Cw E^((δ Derivative[1][x][t])/x[t]) λT x[t]])
(Derivative[1][x][t] + δ (x^′′)[t])) == 0,
x[T] == n, x'[T] == M}, x, {t, 0, T}]}[[1, 1]];
w[100, 2, 3, 100]
(* {2.404002904182026, InterpolatingFunction[{{0., 3.}}, <>]}*)
w
seems to work: Observation: w[mv, 2, 3, 100][[1]] - 1
has a zero at about mv=181.4
.
Next, function mu tries to find the above root for w-1==0
using FindRoot
mu[λT2_?NumericQ, T2_?NumericQ, n2_?NumericQ] :=
FindRoot[w[mv, λT2, T2, n2][[1]] - 1 == 0, {mv, 180}]
mu[2, 3, 100]
{mv -> 1.}
BUT mu does not evaluate w
and [[1]]
just takes the first domain variable and uses it in the equation mv-1==0
.
Thanks in advance.
PS: I have spent (wasted) a huge number of days trying to figure this out. FullForm
is uninformative to me at least. The expression for mu
is very simple as I have decomposed the problem into parts. The w
function works. If I just cut and paste it out of the expression for mu, it executes and gives me the correct answer: w[mv, λT2, T2, n2][[1]]=.944.....
I can plot w
as well with no problems. Why does w
not evaluate when put in FindRoot
?
FullForm
or something. $\endgroup$