Addendum (orginial question below). Thank you for the responses! After thinking some more about this problem, and thanks to @bbgodfreys helpful comment, I realised that the problem as posted below is incomplete. What I need instead is to find $R$ and $f$ such that
- $f(R) = g(\lambda R)$,
- $f'(R) = g'(\lambda R)$,
- $\lim_{r \to 0} \frac{r f'(r)}{f(r)} = -\gamma$, and
$f$ also satisfies the ODE below. This leads to two questions.
Q1. Which two conditions I should pass to NDSolve
, and which one should be the focus of the FindRoot
operation? Further, what is the correct way to pass condition 3 to NDSolve
?
Q2. In either case, the small-$r$ limit and corresponding singularity of $f$ in condition 3 makes life difficult - what is the best way to deal with this?
Perhaps Q1 is not so critical - Q2 seems to me to be the bottleneck. My current attempt, using the methods in the answers below, is to pass conditions 1 and 2 to NDSolve
, and use FindRoot
for condition 3. I have however been unsuccessul thus far. To wit, if I set $r = 0$ as the left boundary of NDSolve
, I first of all get the expected warning
NDSolveValue::ndsz: At r == 1.2839295947759316`*^-19, step size is effectively zero; singularity or stiff system suspected.
This sets a lower bound on $r$ for FindRoot
, since I assume from the warning above that I am not to trust the solution for $r < 10^{-19}$. I hence have to make an ad hoc choice for FindRoot
for condition 3, for example,
trig = R/.FindRoot[
-\[Gamma] - (r Derivative[1][solver[R]][r])/solver[R][r] /. CONS /.
r -> 10^-15,
{R, (1/100/1000)/5}
][[1]]
(* 4.28145*10^-15 *)
I am unconvinced by FindRoot
's solution, since (i) it seems to depend on my ad hoc choice for "$r \to 0$", and (ii) doesn't seem to perform well anyway:
sol = solver[trig]
-\[Gamma] - (r Derivative[1][sol][r])/sol[r] /. CONS /. r -> 10^-15
(* 0.0230768 *)
I'm aware that this addendum significantly alters the question - my apologies! Would be grateful for any suggestions on how to proceed from here. Thanks again for your help thus far.
Original question. I have the following ODE for $f(r)$:
pdef = 2 (\[Beta] f[r] +
r (-\[Mu] + \[Rho]) Derivative[1][f][
r] + ((-1)^(\[Gamma]/(-1 + \[Gamma])) r^((
2 \[Gamma])/(-1 + \[Gamma])) (-1 + \[Gamma]) \
\[Zeta]^(-(\[Gamma]/(-1 + \[Gamma]))) \[Rho]^(\[Gamma]/(-1 + \
\[Gamma]))
Derivative[1][f][r]^(\[Gamma]/(-1 + \[Gamma])))/\[Gamma]) ==
r^2 \[Sigma]^2 (f^\[Prime]\[Prime])[r]
I am looking for an $R > 0$ such that for the following known function $g$,
g[r_] := (2^(1 - \[Gamma]) (1/
r)^\[Gamma] \[Eta]^\[Gamma] \[Rho]^-\[Gamma] ((-2 \[Beta] + \
\[Gamma] (-2 \[Mu] +
2 \[Rho] + (1 + \[Gamma]) \[Sigma]^2))/(-1 + \[Gamma]))^(-1 + \
\[Gamma]))/\[Gamma]
we have $f(R) = g(\lambda R)$, and $f'(R) = g'(\lambda R)$ for $\lambda$ a constant. Further, for $r < R$, we must have $f(r) > g(r)$, as well as $\lim_{r \to\ 0} f(r) = \infty$
Since I do not know $R$, my idea is to wrap NDSolve
in FindRoot
as follows. First, for some guess $R$, define
solver[R_?NumericQ] := NDSolveValue[{
pdef /. CONS,
DirichletCondition[f[r] == g[\[Lambda] r] /. CONS, r == R]
},
f,
{r, R/10, R}
]
where
CONS = {\[Rho] -> 0.02,
J -> 5, \[Gamma] -> 0.5, \[Mu] -> 0.03, \[Sigma] -> 0.2, \[Zeta] ->
0.5, \[Beta] -> 0.012, k -> 10, \[Eta] -> 0.8, \[Lambda] -> 1.03}
is a set of constants. Then use FindRoot
to ensure that the condition on the derivative is specified:
FindRoot[
Derivative[1][solver[R]][R] - D[g[\[Lambda] R], R] /. CONS,
{R, 1/100000}
]
However, I run into trouble with my function solver
, which gives me the error message
DiscretizePDE::femdpop: The FEMLoadElements operator failed.
A plot shows that the solution, instead of "shooting" up and above the orange curve, collapses to the $r$-axis.
What is wrong with my NDSolve
setup? I would be grateful for any suggestions on how to improve my approach or attack the problem with an alternative method.
PS. I have resorted to the above since I simply could not understand how to implement NeumannValue
for this problem. I was also unsuccessful in implementing Method -> "Shooting"
with the smooth fit conditions: the solution "collapsed" just as above, leading me to believe that the derivative condition was simply being ignored when shooting.
pdef
is a second order ODE, NDSolve requires that two boundary conditions be specified. One of them clearly isf[R]
. Sincef'[R]
is to be used to determineR
. it cannot be used forNDSolve
. This suggests that a boundary condition very nearr = 0
be specified. This, in turn, requires that an asymptotic solution be determined there, perhaps i the form of a power series. $\endgroup$r*f'[r]/f[r] == -1/2
for very smallr
could be the inner boundary condition. $\endgroup$1/Sqrt[r]
/ In p rinciple, you can simply insert the equation in my last comment intoNDSolve
. However, I encountered overflow errors after doing so, which I need to investigate. $\endgroup$