# Solving and plotting derivative included function

Please suggest a method that I can use to solve (for y(x) and y'(x)) and plot the derivative related given function.

Note: L may be vary):

a = 2.7*10^-3; θ = Pi/6; g = 9.8; ρ = 1000; σ = 70*10^-3;
L = 4*10^-3;
δp = 2*σ/L - g*(ρ*L)/2;
y' = D[y, x];
1 + y'/Sqrt[(1 + y'^2)] ==  x^2/(2*a^2) + (δp*x)/σ + (1 - Cos[θ]


• Please clarify what the function is, and what variable the derivative is taken with respect to. Dec 10, 2019 at 4:38
• I suppose OP needs to solve differential equation on y[x] with parameter L and some initial condition, this can be done like: δp[L_]:=2*σ/L - g*(ρ*L)/2; sol = ParametricNDSolve[{1 + y'[x]/Sqrt[(1 + y'[x]^2)] == x^2/(2*a^2) + (δp[L]*x)/σ + (1 + Cos[θ]), y[0] == 0}, y, {x, 0, 1}, {L}]. Then he can plot y': Plot[y'[0.004][x] /. sol, {x, Sequence @@ First[(y[0.004] /. sol)["Domain"]]}], I substituted in here value of L given in question.
– Alx
Dec 10, 2019 at 4:42
• Please clarify your question. Do you want to solve for and plot the derivative y'[x], or do you want to solve for and plot the function y[x]? Dec 10, 2019 at 4:46
• Also note that equations are expressed with ==, not = which is an assignment. So you likely want 1 + y'[x]/Sqrt[(1 + y'[x]^2)] == x^2/(2*a^2) + (δp*x)/σ + (1 + Cos[θ]) Dec 10, 2019 at 4:50
• @Alx. That looks more like an answer than a comment. I suggest you write it up as answer. Dec 10, 2019 at 4:51

OK, write my comment as answer. If I understood OP's intention correctly, he wants to solve for y[x] and plot y'[x]. The equation contains a parameter L, so we need to use ParametricNDSolve:

a = 2.7*10^-3; θ = Pi/6; g = 9.8; ρ = 1000; σ = 70*10^-3;
δp[L_] := 2*σ/L - g*(ρ*L)/2;

sol = ParametricNDSolve[{1 + y'[x]/Sqrt[(1 + y'[x]^2)] ==
x^2/(2*a^2) + (δp[L]*x)/σ + (1 + Cos[θ]),
y[0] == 0}, y, {x, 0, 1}, {L}]


Now the solution can be plotted for some value of L (I used here initial value from the question):

Plot[y'[0.004][x] /. sol, {x, Sequence @@ First[(y[0.004] /. sol)["Domain"]]},
AxesLabel -> {x, y'[x]}]


To vary L one can use Manipulate:

Manipulate[
Plot[y'[L][x] /. sol, {x,
Sequence @@ First[(y[L] /. sol)["Domain"]]},
AxesLabel -> {x, y'[x]},
PlotLabel -> Row[{Style["L", Italic], "\[ThinSpace]=\[ThinSpace]", L}]],
{{L, 0.004}, 0.002, 0.02, 0.002}]


Another possibility is using table-like representation:

Grid@Partition[
Plot[y'[#][x] /. sol, {x,
Sequence @@ First[(y[#] /. sol)["Domain"]]},
AxesLabel -> {x, y'[x]},
PlotLabel -> Row[{L, "\[ThinSpace]=\[ThinSpace]", #}]] & /@
Range[0.002, 0.02, 0.002], 2]


EDIT

To answer edited question. First we can plot y[L][x] as function of x, then one approach is to take points from this plot and interchange coordinates, as a result we can plot x as a function of y[L][x]. This can be done in the following way:

With[{L = 0.004}, With[{plot = Plot[Evaluate[y[L][x] /. sol],
{x, Sequence @@ First[(y[L] /. sol)["Domain"]]}, PlotRange -> All]},
ListLinePlot[First[Cases[plot, Line[x_] :> x, Infinity]] /. {x_, y_} :> {y, x},
PlotRange -> All, Frame -> True, FrameLabel -> {HoldForm[y[x]], HoldForm[x]},
GridLines -> {None, {L}}, GridLinesStyle -> Directive[Thick, Gray],
Epilog -> Text["L level", {y[L][L/10] /. sol, L}, {0, 1.1}]]]]


One can also use Manipulate:

Manipulate[With[{plot = Plot[Evaluate[y[L][x] /. sol],
{x, Sequence @@ First[(y[L] /. sol)["Domain"]]}, PlotRange -> All]},
ListLinePlot[First[Cases[plot, Line[x_] :> x, Infinity]] /. {x_, y_} :> {y, x},
PlotRange -> All, Frame -> True, FrameLabel -> {HoldForm[y[x]], HoldForm[x]},
GridLines -> {None, {L}}, GridLinesStyle -> Directive[Thick, Gray],

With parameters given this (both Manipulate and ListLinePlot) only works up to L = 0.006, then the shape of the plot is changed, and one has to comment out Epilog part to plot for greater values of L.
• See my edit about how to vary L`.