0
$\begingroup$

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[θ]

$\endgroup$
9
  • $\begingroup$ Please clarify what the function is, and what variable the derivative is taken with respect to. $\endgroup$
    – bill s
    Dec 10, 2019 at 4:38
  • 1
    $\begingroup$ 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. $\endgroup$
    – Alx
    Dec 10, 2019 at 4:42
  • 1
    $\begingroup$ 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]`? $\endgroup$
    – m_goldberg
    Dec 10, 2019 at 4:46
  • $\begingroup$ 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[θ]) $\endgroup$
    – m_goldberg
    Dec 10, 2019 at 4:50
  • 1
    $\begingroup$ @Alx. That looks more like an answer than a comment. I suggest you write it up as answer. $\endgroup$
    – m_goldberg
    Dec 10, 2019 at 4:51

1 Answer 1

8
$\begingroup$

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]}]

enter image description here

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], 
PlotRangePadding -> {Automatic, {Automatic, Scaled[0.1]}}, 
    Epilog -> Text["L level", {y[L][L/10] /. sol, L}, {0, 1.1}]]]]

enter image description here

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], 
PlotRangePadding -> {Automatic, {Automatic, Scaled[0.1]}}, 
Epilog -> Text["L level", {y[L][L/10] /. sol, L}, {0, 1.1}]]], 
{{L, 0.004}, 0.002, 0.02, 0.002, Appearance -> "Labeled"}]

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.

$\endgroup$
5
  • $\begingroup$ Thanks, It is working. $\endgroup$ Dec 10, 2019 at 6:13
  • $\begingroup$ Please also suggest how to vary L (e.g. {L,.001,0.02,.0002(step)}) $\endgroup$ Dec 10, 2019 at 6:28
  • $\begingroup$ See my edit about how to vary L. $\endgroup$
    – Alx
    Dec 10, 2019 at 7:51
  • $\begingroup$ Please look at the update, I added the expected plot. Please suggest how to get it. ( you can put (1-cos(\theta)) instead of (1+cos(\theta)) $\endgroup$ Jan 28, 2020 at 11:07
  • $\begingroup$ Thanks for your update, but the shape of a graph not matching, especially the upper half part. $\endgroup$ Jan 29, 2020 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.