Skip to main content
Fixed code
Source Link
Michael E2
  • 238.9k
  • 17
  • 339
  • 758
(*"
 * Solves y''[x] == F[y[x], y'[x]] if LHS is integrable w.r.t x
"*)
DownValues@mySpecialOrder2BVP = {
   HoldPattern[
     mySpecialOrder2BVP[eqn_, ycond_, yprimecond_, a_, y_, x_]] :> 
    Block[{rhs, w, res1, c, res},
     rhs = eqn[[2]] /.  (**) {y[x] | y'[x] -> w}(**);
     (res1 = 
        Quiet[Solve[ (**)
          Derivative[1][y][x] == Integrate[eqn[[2]], x](**)  + c /. 
            x -> a /. {ycond, yprimecond}, c]];
       (res1 = (**)
          Derivative[1][y][x] == 
           Integrate[eqn[[2]], x](**)  + (c /. res1[[1]]);
         res = (**)
          DSolve[res1 && ycond[[1]] == ycond[[2]], {y}, {x}]; (**)
         res /; FreeQ[res, $Failed](**)DSolve(**)]) /;
        MatchQ[res1, {{c -> m_}}] && FreeQ[res1, Integrate]) /;
      FreeQ[rhs, y | x]]
   };


mySpecialOrder2BVP[ode, Sequence @@ First@Solve[ic], 3, y, x]

(*  {{y -> Function[{x}, -Log[4 - x]]}}  *)

I don't have a way to hook this into DSolve automatically.

Edit notice: I neglected to mark the change from the internal DSolve`DSolveParser to DSolve. DSolveParser[] threw a couple of Part::partw errors that could be ignored. Calling the top-level DSolve seemed the best fix for this answer. The Condition should therefore be FreeQ[res, DSolve]. It seems to me that the errors are but that arise because the internal SpecialOrder2BVP[] hasn't been updated to pass DSolveParser[] complete option value data (with the new options like IncludeSingularSolutions). I haven't noticed anyone reporting such a bug yet, though. (Also, I don't know why Integrate is called twice. It seems wasteful.)

(*"
 * Solves y''[x] == F[y[x], y'[x]] if LHS is integrable w.r.t x
"*)
DownValues@mySpecialOrder2BVP = {
   HoldPattern[
     mySpecialOrder2BVP[eqn_, ycond_, yprimecond_, a_, y_, x_]] :> 
    Block[{rhs, w, res1, c, res},
     rhs = eqn[[2]] /.  (**) {y[x] | y'[x] -> w}(**);
     (res1 = 
        Quiet[Solve[ (**)
          Derivative[1][y][x] == Integrate[eqn[[2]], x](**)  + c /. 
            x -> a /. {ycond, yprimecond}, c]];
       (res1 = (**)
          Derivative[1][y][x] == 
           Integrate[eqn[[2]], x](**)  + (c /. res1[[1]]);
         res = DSolve[res1 && ycond[[1]] == ycond[[2]], {y}, {x}];
         res /; FreeQ[res, $Failed]) /;
        MatchQ[res1, {{c -> m_}}] && FreeQ[res1, Integrate]) /;
      FreeQ[rhs, y | x]]
   };


mySpecialOrder2BVP[ode, Sequence @@ First@Solve[ic], 3, y, x]

(*  {{y -> Function[{x}, -Log[4 - x]]}}  *)

I don't have a way to hook this into DSolve automatically.

(*"
 * Solves y''[x] == F[y[x], y'[x]] if LHS is integrable w.r.t x
"*)
DownValues@mySpecialOrder2BVP = {
   HoldPattern[
     mySpecialOrder2BVP[eqn_, ycond_, yprimecond_, a_, y_, x_]] :> 
    Block[{rhs, w, res1, c, res},
     rhs = eqn[[2]] /.  (**) {y[x] | y'[x] -> w}(**);
     (res1 = 
        Quiet[Solve[ (**)
          Derivative[1][y][x] == Integrate[eqn[[2]], x](**)  + c /. 
            x -> a /. {ycond, yprimecond}, c]];
       (res1 = (**)
          Derivative[1][y][x] == 
           Integrate[eqn[[2]], x](**)  + (c /. res1[[1]]);
         res = (**)
          DSolve[res1 && ycond[[1]] == ycond[[2]], {y}, {x}]; (**)
         res /; FreeQ[res, (**)DSolve(**)]) /;
        MatchQ[res1, {{c -> m_}}] && FreeQ[res1, Integrate]) /;
      FreeQ[rhs, y | x]]
   };


mySpecialOrder2BVP[ode, Sequence @@ First@Solve[ic], 3, y, x]

(*  {{y -> Function[{x}, -Log[4 - x]]}}  *)

I don't have a way to hook this into DSolve automatically.

Edit notice: I neglected to mark the change from the internal DSolve`DSolveParser to DSolve. DSolveParser[] threw a couple of Part::partw errors that could be ignored. Calling the top-level DSolve seemed the best fix for this answer. The Condition should therefore be FreeQ[res, DSolve]. It seems to me that the errors are but that arise because the internal SpecialOrder2BVP[] hasn't been updated to pass DSolveParser[] complete option value data (with the new options like IncludeSingularSolutions). I haven't noticed anyone reporting such a bug yet, though. (Also, I don't know why Integrate is called twice. It seems wasteful.)

Source Link
Michael E2
  • 238.9k
  • 17
  • 339
  • 758

I'd report this to WRI. If buried in the DSolve code base is a way to solve this, then the decision tree misses it. Otherwise, they should implement a way. DSolve has a method to solve y''[x] == F[y[x]]. Here's is a modification of it to solve y''[x] == F[y[x], y'[x]] (tested only on this problem!).

I snatched the code for y''[x] == F[y[x]] and modified by hand. The modifications are surround by (**) on either side.

mySpecialOrder2BVP // ClearAll;
First@DownValues@DSolve`DSolveExtendedLibraryDump`SpecialOrder2BVP /. 
  s_Symbol :> 
   With[{v = Symbol@SymbolName[s]}, 
    RuleCondition[v, ! MemberQ[Context[s], $ContextPath]]] /. 
 SpecialOrder2BVP -> mySpecialOrder2BVP

Edit the output above to be the following:

(*"
 * Solves y''[x] == F[y[x], y'[x]] if LHS is integrable w.r.t x
"*)
DownValues@mySpecialOrder2BVP = {
   HoldPattern[
     mySpecialOrder2BVP[eqn_, ycond_, yprimecond_, a_, y_, x_]] :> 
    Block[{rhs, w, res1, c, res},
     rhs = eqn[[2]] /.  (**) {y[x] | y'[x] -> w}(**);
     (res1 = 
        Quiet[Solve[ (**)
          Derivative[1][y][x] == Integrate[eqn[[2]], x](**)  + c /. 
            x -> a /. {ycond, yprimecond}, c]];
       (res1 = (**)
          Derivative[1][y][x] == 
           Integrate[eqn[[2]], x](**)  + (c /. res1[[1]]);
         res = DSolve[res1 && ycond[[1]] == ycond[[2]], {y}, {x}];
         res /; FreeQ[res, $Failed]) /;
        MatchQ[res1, {{c -> m_}}] && FreeQ[res1, Integrate]) /;
      FreeQ[rhs, y | x]]
   };


mySpecialOrder2BVP[ode, Sequence @@ First@Solve[ic], 3, y, x]

(*  {{y -> Function[{x}, -Log[4 - x]]}}  *)

I don't have a way to hook this into DSolve automatically.