2
$\begingroup$

I am trying to solve the following problem: given the differential equation $$\frac{d^2y}{dx^2}+\bigg(a+b\frac{2}{\pi}\tan^{-1}x\bigg)y=0$$ subjected to two different initial condition we get two different solution lets call them $y_1(x)$ and $y_2(x)$. Now I have to plot the following expression $$z(a,b)=|y_1\partial_xy_2-y_2\partial_xy_1|\bigg|_{x=0}$$ To implement it I have written following code

s = ParametricNDSolve[{y''[x] + (a + b (2 + 2/Pi ArcTan[x])) y[x] == 
0, y[-10] == Exp[I 10 Sqrt[a + b]], 
y'[-10] == -I Sqrt[a + b]*Exp[I 10 Sqrt[a + b]]}, 
y, {x, -10, 10}, {a, b}]

u = ParametricNDSolve[{z''[x] + (a + b (2 + 2/Pi ArcTan[x])) z[x] == 
0, z[10] == Exp[-I 10 Sqrt[a + 3 b]], z'[10] == -I Sqrt[a + 3 b]*Exp[I 10 Sqrt[a + 3 b]] },z, {x, -10, 10}, {a, b}]

Plot3D[Evaluate[Abs[s[a, b][x] D[u[a, b][x], x] /. 
 x -> 0 - D[s[a, b][x], x] u[a, b][x] /. x -> 0]], {a, 0, 5} {b, 0, 5}]

The first two lines of the code(solving the equation) are correct. I have checked them. Its the third line where the code seems to not work. It gives me the error

$a\{0,5\}$ is not of the form $\{x,xmin,xmax\}$.

Can someone help me figure out where I am making the mistake?

$\endgroup$
4
$\begingroup$

With little modifications it seems to wotk:

s = ParametricNDSolveValue[{Derivative[2][y][x] + (a + b*(2 + (2/Pi)*ArcTan[x]))*y[x] == 0, y[-10] == Exp[I*10*Sqrt[a + b]], 
    Derivative[1][y][-10] == (-I)*Sqrt[a + b]*Exp[I*10*Sqrt[a + b]]}, y, {x, -10, 10}, {a, b}]

u = ParametricNDSolveValue[{Derivative[2][z][x] + (a + b*(2 + (2/Pi)*ArcTan[x]))*z[x] == 0, z[10] == Exp[(-I)*10*Sqrt[a + 3*b]], 
    Derivative[1][z][10] == (-I)*Sqrt[a + 3*b]*Exp[I*10*Sqrt[a + 3*b]]}, z, {x, -10, 10}, {a, b}]

Plot3D[Evaluate[Abs[(s[a, b][0] Derivative[1][u[a, b]][0]) -
      (Derivative[1][s[a, b]][0] u[a, b][0])]], {a, 0, 5}, {b, 0, 5}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks but can you tell specifically what mistake am I making. Also when you wrote Derivative[1]u[a,b][0] which derivative will it be i.e. with respect to which variable a,b,x? $\endgroup$ – aitfel Jan 17 at 4:58
  • $\begingroup$ With your approach you have to make additional substitutioin: y/.s etc., using ParametricNDSolveValue returns just IinterpolationFunction (not your y->InterpolationFunction[...]). Derivative is with respect to argument of function, i.e. x: function is u[a,b] anf it's argument is x, and derivative is taken at value of argument is equal to 0, you may find this in help on Derivative. $\endgroup$ – Alx Jan 17 at 5:38

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.