# Numerical solution of ODE

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.

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

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

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

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

• still I am not able to get the value of y1 and y2 Commented Sep 13, 2018 at 9:30