I do not have enough reputation to comment on other questions, hence I have to ask my own one
I want to solve the following nonlinear first order ODE,
$$(1 + x) (0.5 y[x]^{-0.5} (x - y[x])^{0.5} -
0.5 y[x]^{0.5} (x - y[x])^{-0.5}) == -y[x] (x - y[x])/y'[x]$$
As it does not have a closed form solution, I want to plot the directional field and pick a particular line corresponding to an initial value.
Here is my code,
f[x_] = {
{NDSolveValue[{(1 + x) (0.5 y[x]^-0.5 (x - y[x])^0.5 -
0.5 y[x]^0.5 (x - y[x])^-0.5) == -y[x] (x - y[x])/y'[x],
y[1] == 0.5}, y[x], {x, 0, 2}]},
{\[Placeholder]}
}
But I get errors:
Power::infy: Infinite expression 1/0. encountered. >>
NDSolveValue::ndnum: Encountered non-numerical value for a derivative at x == 1.`. >>
I think I have seen others with similar functional form (potentially 1/0) plot their directional fields, is there anyway to get around here?
If I can do this first step(solving the ODE numerically), then I can plot it,
g1=Plot[f[x], {x, 0, 2},
PlotStyle -> Directive[Thick, Red],
PlotRange -> {{-0.999, 2}, Automatic},
PlotPoints -> 100
]
then do the streamplot as it is called,
g2=StreamPlot[{1, (-y[x] (x - y[x]))/((1 + x)[
0.5 y[x]^-0.5 (x - y[x])^0.5 - 0.5 y[x]^0.5 (x - y[x])^-0.5])}, {x, 0, 2}, {y, 0, 1}]
and then finally showing them both
Show[g1,g2]
The code above is what I modified from other's, his code does works. I changed the function into mine, and changed the range of x, that is all. Can someone help me figure it out?
The directional field should looks like this, but I want to highlight a red curve corresponding to a initial condition.
Also, can I add lines like y=x and y=x/2 on this plot?
Thanks in advance!