Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to solve the following differential equation: -u''(x) + ((x-k)^2 -en)u(x)=0 with boundary conditions u(0)=0 and u(infinity)=0. Implementing this is Mathematica has led me to very cumbersome code. I have used the following approach: Use NDSolve to solve for general u(x) (which is also a function of k and en) with boundary conditions u(0)=0, u'(0)=1.

    solution1 = 
NDSolve[{-D[uall[x, en, k], x, x] + ((x - k)^2 - en) uall[x,
    en, k] == 0., uall[0, en, k] == 0, 
Derivative[1, 0, 0][uall][0, en, k] == 1}, 
uall, {x, -8, 8}, {en, 1.8, 3.6}, {k, -.1, 0.6}];

Go on to solve for the eigenvalues en by imposing u(8)=0 (this acts to approximate the condition u(infinity)=0

Eofk1[k_] := 
 en /. FindRoot[(uall[8, en, k] /. solution1) == 0, {en, 2.4}];

Whilst this approach does technically work, it is required that I specify a different range of the parameter k and en for NDSolve to work within for each solution. This means that I have to manually write out very similar lines of code again and again... I need help to make the code more efficient. Thanks!!!!

UPDATE: I tried modifying the example on "StartingInitialConditions" on this page http://reference.wolfram.com/mathematica/tutorial/NDSolveBVP.html

sols = Map[
First[Block[{en = 1, k = 1}, 
NDSolve[{-u''[x] + ((x - k)^2 - en) u[x] == 0., 
u[0.] == u[8.] == 0.}, u, x, 
Method -> {"Shooting", 
"StartingInitialConditions" -> {u[0] == 0, 
u'[0] == #}}]]] &, {1.5, 1.75, 2}];
Plot[Evaluate[u[x] /. sols], {x, 0, 10}, 
PlotStyle -> {Black, Blue, Green}]

The problem is that I want to be able to find the values of en as a function of k that satisfy the boundary conditions properly.

share|improve this question
    
You can use Manipulate –  Sektor Jan 11 at 11:09
    
Where's your L? Are you sure your equation is correct? In fact it can be solved by DSolve, and according to the result, the only solution fitted your BC seems to be $u(x)=0$. –  xzczd Jan 11 at 11:40
    
You ODE syntax is not really right. You write D[uall[x, en, k], x, x], but $u$ is not a function of en and k. These are paramters, not independent variables. Otherwise, you'd be talking about a partial differential equation. You should just write u''[x] and that is it. As for the NDSolve itself, look at Method shooting and startingInitialConditions. See the NDSolve advanced documentations for examples of boundary values for second order ODEs using the shooting method. –  Nasser Jan 11 at 12:04
    
Sorry, L was meant to be 8. Thanks for the comments, will looks into that and see how it goes. –  Kris Jan 11 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.