3
$\begingroup$

I have a system of two ODE's, each of order 2 with three initial conditions. One of the condition is of the form f(0)+g(0)=1, which is the main reason that NDSolve is unable to find the solution.

Here the system with the initial conditions,

ode1 = f''[x] + (f[x] + g[x])*f'[x] == 0
ode2 = g''[x] + (f[x] + g[x])*g'[x] == 0
ics = {f[0] + g[0] == 1, f'[0] == 0, g'[0] == 1};
system = {ode1, ode2}
NDSolve[Join[system, ics], {f[x], g[x]}, {x, 0, 5}]

NDSolve::ndnco: The number of constraints (3) (initial conditions) is not equal to the total differential order of the system plus the number of discrete variables (4)

How we can handle such situation?

$\endgroup$

2 Answers 2

6
$\begingroup$

Then there should be infinite solutions. Let's introduce a parameter:

ode1 = f''[x] + (f[x] + g[x])*f'[x] == 0;
ode2 = g''[x] + (f[x] + g[x])*g'[x] == 0;
ics = {f[0] + g[0] == 1, f'[0] == 0, g'[0] == 1};
system = {ode1, ode2};
{solf, solg} = 
  ParametricNDSolve[{system, ics, f[0] == a}, {f, g}, {x, 0, 5}, a][[All, -1]];

Manipulate[Plot[{solf[a][x], solg[a][x]}, {x, 0, 5}, PlotRange -> 7], {a, -5, 5}]

enter image description here

$\endgroup$
4
  • $\begingroup$ How I will know that what value of a is the correct one? $\endgroup$
    – zhk
    Commented Oct 27, 2016 at 14:06
  • $\begingroup$ @mmm Well, as said above, with only 3 boundary conditions, this equation set owns infinite possible solutions, so every value of a points to a valid solution, there's no incorrect a. $\endgroup$
    – xzczd
    Commented Oct 27, 2016 at 14:16
  • $\begingroup$ If I understood you correctly, then we can take f(0)=a and g(0)=1-a where $a\in R$? $\endgroup$
    – zhk
    Commented Oct 27, 2016 at 14:21
  • 1
    $\begingroup$ @mmm Actually a can even be a complex number. $\endgroup$
    – xzczd
    Commented Oct 27, 2016 at 14:25
4
$\begingroup$

Perhaps define an interim function h[x]?

ode1 = f''[x] + h[x]*f'[x] == 0
ode2 = g''[x] + h[x]*g'[x] == 0
ode3 = h[x] == f[x] + g[x]
ics = {h[0] == 1, f'[0] == 0, g'[0] == 1};
system = {ode1, ode2, ode3}
soln = NDSolve[Join[system, ics], {f[x], g[x]}, {x, 0, 5}]

{ {f[x] -> InterpolatingFunction[{{0., 5.}}, <>][x], g[x] -> InterpolatingFunction[{{0., 5.}}, <>][x]} }

Plot[{f[x], g[x]} /. soln, {x, 0, 5}]

Plot of f[x] and g[x]

$\endgroup$
1
  • $\begingroup$ Interesting, seems that NDSolve has introduced an artificial boundary f[0] == 0.5 silently in this case, but there should be infinite solutions actually, see my answer. $\endgroup$
    – xzczd
    Commented Oct 27, 2016 at 14:02

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.