4
$\begingroup$

I have never solved numerically differential equations, but in an optimal control problem I got this one that I cannot solve:

$$ 1-f’(x)^2+f’(x)(x +1)+f’’(x)-f’’(x)f’(x)-f’’(x)f’(x)^2=f(x) $$

I do not have specific initial conditions, but I guess I have to see which ones work. Do you have any suggestions?

$\endgroup$
3
  • 1
    $\begingroup$ If not addressed by the end of the day i will write an answer detailing the varried boundary condition you describe. Ive asked a variety of questions similar on this topic which you can find in my history in the meantime. $\endgroup$
    – akozi
    Mar 31, 2022 at 15:59
  • $\begingroup$ Thanks! I wrote in the comment below the kind of conditions I have. My main problem is that one boundary condition is evaluated at a point which is determined by the value of a derivative in that point. So, being completely new to numerical ODE I don't know how to write it down in a code. Thanks again for your help! $\endgroup$
    – Giuliosky
    Mar 31, 2022 at 16:03
  • $\begingroup$ Hi! If you are still interested in this question here's the updated version: mathematica.stackexchange.com/questions/266051/… $\endgroup$
    – Giuliosky
    Apr 2, 2022 at 0:54

2 Answers 2

7
$\begingroup$
$Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global`*"]

Manipulate[
 Module[{eqns},
  eqns = {1 - f'[x]^2 + f'[x] (x + 1) + f''[x] - f''[x] f'[x] - 
       f''[x] f'[x]^2 == f[x], f[0] == f0, f'[0] == fp0} // 
    FullSimplify;
  sol = NDSolve[eqns, f, {x, 0, xmax}][[1]];
  Plot[Evaluate[{f[x], f'[x], f''[x]} /. sol],
   {x, 0, xmax},
   Frame -> True,
   FrameLabel -> {Style["x", 14], None},
   PlotLabel -> eqns[[1]],
   PlotLegends -> {"f(x)", "f'(x)", "f''(x)"}]],
 {{f0, 0.75}, -0.99, 0.99, 0.01,
  Appearance -> "Labeled"},
 {{fp0, 0.25}, -0.99, 0.99, 0.01,
  Appearance -> "Labeled"},
 {{xmax, 5}, 1, 10, 1,
  Appearance -> "Labeled"}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you for your answer! The conditions I should use are maybe weird, but here they are: $$f(0)=0,\ f'(z)=-1$$ where $z$ is the first point at which $f''(z)=0$$ I hope what I wrote makes some sense. Thank you again for your precious help!! $\endgroup$
    – Giuliosky
    Mar 31, 2022 at 15:37
  • $\begingroup$ Hi! If you are still interested in this question here's the updated version: mathematica.stackexchange.com/questions/266051/… $\endgroup$
    – Giuliosky
    Apr 2, 2022 at 0:55
6
$\begingroup$

I do not have specific initial conditions, but I guess I have to see which ones work.

The advice in situations like this one is to give some information and description of the background material.

The following is just to get you started


Basic commands to look up in the documentation: NDSolve and ParametricNDSolve.


Testing some basic stuff using physics intuition


We assume that the solution has to be normalizable and finite. In other words, in the beginning it should start at 1 and at the end it should go to 0. I am also assuming that the beginning is 0 and the end is 10.


Set up the differential equation and initial conditions for specific values


eqn = 1 - f'[x]^2 + f'[x] (x + 1) + f''[x] - f''[x] f'[x] - 
    f''[x] f'[x]^2 - f[x] == 0;
intcondtn = {f[0] == 1, f[10] == 0};

Now we solve

sltnde = NDSolveValue[{eqn, intcondtn}, f[x], {x, 0, 10}]

and we plot to have a look

Plot[sltnde, {x, 0, 10}, PlotRange -> All]

plot1


Free parameters and numerical solutions


eqn = 1 - f'[x]^2 + f'[x] (x + 1) + f''[x] - f''[x] f'[x] - 
    f''[x] f'[x]^2 - f[x] == 0;
intcondtn = {f[0] == xx1, f[10] == xx2};

and then in order to solve

paramsltn = 
 ParametricNDSolveValue[{eqn, intcondtn}, 
  f[x], {x, 0, 10}, {xx1, xx2}]

and we can plot one of them to have a look

Plot[paramsltn[1, 1], {x, 0, 10}, PlotRange -> All]

plot2

$\endgroup$
5
  • $\begingroup$ Thank you for your answer! The conditions I should use are maybe weird, but here they are: $$f(0)=0,\ f'(z)=-1$$ where $z$ is the first point at which $f''(z)=0$$ I hope what I wrote makes some sense. Thank you again for your precious help!! $\endgroup$
    – Giuliosky
    Mar 31, 2022 at 15:34
  • 1
    $\begingroup$ @Giuliosky what you say makes sense, but I think that you should post another question, link this one and describe this set of conditions explicitly :-) $\endgroup$
    – bmf
    Mar 31, 2022 at 16:11
  • $\begingroup$ Ok thanks for the advice! I will write a new question then! $\endgroup$
    – Giuliosky
    Mar 31, 2022 at 16:14
  • 1
    $\begingroup$ @Giuliosky just remember to link this one, i.e this question is a follow-up to and include link and be specific about the conditions you want to impose. $\endgroup$
    – bmf
    Mar 31, 2022 at 16:15
  • $\begingroup$ Hi! If you are still interested in this question here's the updated version: mathematica.stackexchange.com/questions/266051/… $\endgroup$
    – Giuliosky
    Apr 2, 2022 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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