1
$\begingroup$

I am trying to solve the differential equation enter image description here with boundary conditions enter image description here using the shooting method. Also assuming y(0) and y(1) are nonzero and equal. I am having trouble setting this up, and here is a first try.

system[\[CapitalOmega]_] := {y1'[x] == y2[x], y2'[x] == y1[x]^2 + 2*Pi^2*Cos[2*Pi*x] - Sin[Pi*x]^4, y1[0] == \[CapitalOmega], y2[0] == \[CapitalOmega]}
myODEsoln[\[CapitalOmega]_] := NDSolve[system[\[CapitalOmega]], {y1[x], y2[x]}, {x, 0, 1}]
yend[\[CapitalOmega]_?NumericQ] := First[y1[x] /. myODEsoln[\[CapitalOmega]] /. x -> 1]
bc = FindRoot[yend[\[CapitalOmega]] == 0, {\[CapitalOmega], -5, 5}]
Plot[Evaluate[y1[x] /. myODEsoln[\[CapitalOmega] /. bc]], {x, -1, 1}, PlotStyle -> Thick, Frame -> True, FrameLabel -> {Style["x", 12], Style["y1(x)", 12]}]
$\endgroup$
3
  • $\begingroup$ If you use myODEsoln[Ω_] := NDSolve[system[Ω], {y1[x], y2[x]}, {x, -1, 1}] instead of what you have the code runs without any errors. Right? $\endgroup$
    – user49048
    Commented Feb 9, 2022 at 6:22
  • $\begingroup$ Or, since $0 \leq x \leq 1$ perhaps you should use the following instead of what you have: Plot[Evaluate[y1[x] /. myODEsoln[Ω /. bc]], {x, 0, 1}, PlotStyle -> Thick, Frame -> True, FrameLabel -> {Style["x", 12], Style["y1(x)", 12]}] Again no errors $\endgroup$
    – user49048
    Commented Feb 9, 2022 at 6:27
  • 1
    $\begingroup$ But you are aware, that you can solve it directly? ysol = y /. First[NDSolve[{Derivative[2][y][x] == 2*Pi^2*Cos[2*Pi*x] - Sin[Pi*x]^4 + y[x]^2, Derivative[1][y][0] == 0, Derivative[1][y][1] == 0}, y, {x, 0, 1}]]; Plot[ysol[x], {x, 0, 1}] $\endgroup$
    – Akku14
    Commented Feb 9, 2022 at 7:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.