2
$\begingroup$

Currently I have an equation with boundary conditions as such, $A \frac{d^2\psi}{dx^2}= C_{F}F, \psi(\frac{1}{2})=0,\psi\:'(0)=0$ and I have to use a "shooting method" to find the Dirichlet boundary condition at $x=0$, shown below:

F = 96485.3321;
A = 5.312*10^-24;
CF = 1000;
fun[y_?NumericQ] := Module[{eqns, sol, ics, x, psi},
  eqns = {A*D[psi[x], x, x] == CF*F};
  ics = {psi[0] == y, psi'[x] == 0 /. x -> 0};
  sol = NDSolve[{eqns, ics}, {psi[x]}, {x, 0, 1/2}][[1]];
  psi[x] /. sol /. x -> 1/2]
ic = FindRoot[fun[x], {x, 0}]

but the FindRoot function gives an error:

FindRoot:Encountered a singular Jacobian at the point {x} = {0.}. Try perturbing the initial point(s).

Can anyone suggest a way to get around this? Thanks a lot.

$\endgroup$

1 Answer 1

3
$\begingroup$
  • At first we directly solve the equation by DSolve and Solve.
F = 96485.3321;
A = 5.312*10^-24;
CF = 1000;
eqns = {A*psi''[x] == CF*F};
ics = {psi[0] == y, psi'[0] == 0};
sol1 = DSolve[{eqns, ics}, psi, x][[1]];
sol2 = Solve[psi[1/2] == 0 /. sol1[[1]], y][[1]]
sol = sol1 /. sol2

enter image description here

{eqns, psi[1/2] == 0, psi'[0] == 0} /. sol

{{True}, True, True}.

  • Then we using shooting method to solve it again.
Clear["Global`*"];
F = 96485.3321;
A = 5.312*10^-24;
CF = 1000;
fun[y_?NumericQ] := 
 Module[{eqns, sol, ics, x, psi}, eqns = {A*psi''[x] == CF*F};
  ics = {psi[0] == y, psi'[0] == 0};
  sol = NDSolve[{eqns, ics}, {psi}, {x, 0, 1/2}][[1]];
  psi /. sol]
Plot[fun[y][1/2], {y, -10*10^30, 0}]
FindRoot[fun[y][1/2], {y, -2*10^30}]

enter image description here

enter image description here

  • The same as ParametricNDSolve.
Clear["Global`*"];
F = 96485.3321;
A = 5.312*10^-24;
CF = 1000;
eqns = {A*psi''[x] == CF*F};
ics = {psi[0] == y, psi'[0] == 0};
sol = ParametricNDSolve[{eqns, ics}, {psi}, {x, 0, 1/2}, {y}]
Plot[psi[y][1/2] /. sol, {y, -10*10^30, 0}]
FindRoot[psi[y][1/2] /. sol, {y, -2*10^30}]
$\endgroup$
3
  • $\begingroup$ Thank you for your response! Would you mind explaining why in Plot[fun[y][1/2], {y, -10*10^30, 0}] and the subsequent FindRoot function, [1/2] is needed after fun[y]? @cvgmt $\endgroup$
    – Jack L
    Commented Feb 18, 2023 at 5:53
  • $\begingroup$ In my code, the fun[y] is a pure function` with parametric y. We need to find the parametric y when it satisfies the equation psi[1/2]==0, that is fun[y][1/2]==0, here psi is fun[y]. $\endgroup$
    – cvgmt
    Commented Feb 18, 2023 at 6:05
  • $\begingroup$ Alright, I got it. Thanks a lot! $\endgroup$
    – Jack L
    Commented Feb 18, 2023 at 6:28

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.