3
$\begingroup$

While trying to solve

With[{h = h[x]},
{eq, bc} = {D[h, x, x] == Sin[Pi x], {h == 0 /. x -> 0, 
 D[h, x, x] == -D[h, x] + h /. x -> 1}}];
g = NDSolveValue[{eq, bc}, h, {x, 0, 1}]

I got the error

NDSolve::nlnum1: The function value {0.,0.31831 +(NDSolve`h$9$1^[Prime])1} is not a list of numbers with dimensions {2} when the arguments are {0.,0.,0.31831,0.63662}.

Then I found this trick so I tried

With[{h = h[x]},
{eq, bc} = {D[h, x, x, x] == 
 Pi Cos[Pi x], {D[h, x, x] == Sin[Pi x] /. x -> 0, 
 h == 0 /. x -> 0, D[h, x, x] == -D[h, x] + h /. x -> 1}}];
 g = NDSolveValue[{eq, bc}, h, {x, 0, 1}]
 Plot[g[x], {x, 0, 1}]

I obtained enter image description here

I guess this solution is not correct due to high values (maybe instability).

Is there a better way to solve such an equation?

$\endgroup$
2
  • 1
    $\begingroup$ for second order ode, IC/BC should not really have derivative terms in it of equal of higher than the 2. And why do you write things this strange way? why not write ode = h''[x] == Sin[Pi x] and bc = {h[0] == 0, h''[1] == -h'[1] + h[1]} which is much more readable and clear. $\endgroup$
    – Nasser
    Commented Mar 18 at 17:51
  • $\begingroup$ @Nasser yes I realized that, but still looking for good solutions.For the form I wrote, it's because I simplified complicated eqs. $\endgroup$
    – S. Euler
    Commented Mar 18 at 17:58

1 Answer 1

5
$\begingroup$

Your ode-system has no solution!

general solution depends on two parameters

H = DSolveValue[h''[x] == Sin[Pi x], h, x]
(*Function[{x}, C[1] + x C[2] - Sin[\[Pi] x]/\[Pi]^2]*)

Solve[{H[0] == 0, (H^\[Prime]\[Prime])[1] ==H[1] - Derivative[1][H][1] }, {C[1], C[2]}]
(* {} *)

Only bc h[0]==1/Pi gives a solution

Solve[{H[0] == 1/Pi, (H^\[Prime]\[Prime])[1] ==H[1] - Derivative[1][H][1] }, {C[1], C[2]}][[1]]
(* {C[1] -> 1/\[Pi]} *)
$\endgroup$
4
  • $\begingroup$ thanks for pointing this out. This is because I simplified the eq. I can take h[0]==1/Pi to focus on bc issue. $\endgroup$
    – S. Euler
    Commented Mar 18 at 18:04
  • $\begingroup$ @S.Euler As Nasser mentioned in hist comment NDSolve doesn't allow boundary conditions with order of ode! $\endgroup$ Commented Mar 18 at 18:09
  • $\begingroup$ what about approximating h'' by first oder derivative? $\endgroup$
    – S. Euler
    Commented Mar 19 at 1:49
  • $\begingroup$ @S.Euler Try DSolveValue[{h''[x] == Sin[Pi x], h[0] == 1/Pi, Sin[Pi] == h[1] - h'[1]}, h, x] , but Mathematica gives an error message. $\endgroup$ Commented Mar 19 at 9:15

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.