1
$\begingroup$

I have two coupled non linear second order differential equation.

{
 -y1''[x] == -Exp[k1 (y1[x] - y2[x])] + Exp[-k2 (y1[x] - y2[x])],
 -y2''[x] == Exp[k1 (y1[x] - y2[x])] - Exp[-k2 (y1[x] - y2[x])]
}

How can I solve this numerically to get the values of y1 and y2 at different points using NDSolve.

$\endgroup$
2
  • 1
    $\begingroup$ Please give proper e.g. initial conditions, what are the values for k1, k2? How about y1[0], y1'[0], y2[0], y2'[0]? $\endgroup$ Commented Sep 13, 2018 at 8:34
  • 1
    $\begingroup$ What are your boundary conditions? Without those, you can't solve numerically. $\endgroup$ Commented Sep 13, 2018 at 8:35

2 Answers 2

1
$\begingroup$

Initial/boundary conditions are missing along with the values for k1 and k2. Therefore, I choose random ones.

Eq1 = -y1''[x] == -Exp[k1 (y1[x] - y2[x])] + Exp[-k2 (y1[x] - y2[x])]

Eq2 = -y2''[x] == Exp[k1 (y1[x] - y2[x])] - Exp[-k2 (y1[x] - y2[x])]

k1 = 1; k2 = 1;

sol = NDSolve[{Eq1, Eq2, y1[0] == 1, y1'[0] == 0, y2[0] == 1, y2'[0] == 0}, {y1, y2}, {x, 0, 10}]

xy = Table[{x, y1[x], y2[x]} /. First@sol, {x, 0, 10, 2}];

% // TableForm
$\endgroup$
2
  • $\begingroup$ @MATHS Your conditions doesn't make any sense. $\endgroup$
    – zhk
    Commented Sep 13, 2018 at 8:46
  • $\begingroup$ k1=10, k2=10, y2[0]=0, y1'[0]=0,y2'[0.001]=0,y1'[0.001]=4 These are my conditions $\endgroup$
    – MATHS
    Commented Sep 13, 2018 at 8:52
1
$\begingroup$

I recommend you take a look at ParametricNDSolveValue:

{xmin, xmax} = {0, 1};
sol = ParametricNDSolveValue[
  {
   -y1''[x] == -Exp[kk1 (y1[x] - y2[x])] + 
     Exp[-kk2 (y1[x] - y2[x])], -y2''[x] == 
    Exp[kk1 (y1[x] - y2[x])] - Exp[-kk2 (y1[x] - y2[x])],
   y1[xmin] == yy10,
   y1[xmax] == yy11,
   y2[xmin] == yy20,
   y2[xmax] == yy21
  },
  {y1, y2},
  {x, xmin, xmax},
  {kk1, kk2, yy10, yy11, yy20, yy21}
]


Manipulate[
  Plot[
    Evaluate[Through[sol[k1, k2, y10, y11, y20, y21][x]]],
    {x, xmin, xmax}, AxesOrigin -> {0, 0}, PlotRange -> All
  ],
  {{k1, 1}, -1, 1},
  {k2, -1, 1},
  {{y10, 0}, -1, 1},
  {y11, -1, 1},
  {{y20, 0}, -1, 1},
  {y21, -1, 1}
]

If you need numeric values for a particular set of x-values, you can get them like this:

xValues = Range[0, 1, 0.1]
yValues = Through[sol[1, 1, 0, 1, 1, 0][xValues]]
$\endgroup$
1
  • $\begingroup$ still I am not able to get the value of y1 and y2 $\endgroup$
    – MATHS
    Commented Sep 13, 2018 at 9:30

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.