solve_ivp from -x to +x





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







4















I've been trying to use either solve_ivp or solve_bvp to solve a problem I've been having but I'm not making any progress. I think the code I have here will work but I cannot get the range to be correct. for some reason I cannot understand the range is always going from 0 to x and not from -x to x can someone help me fix this part for solve_ivp?



here is the code reduced to a min



from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1
B=4
L= B+a
Vmax= 50
Vpot = False

N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = array([0,1]) # Wave function initial states
Vo = 50
E = 0.0 # global variable Energy needed for Sch.Eq, changed in function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = linspace(-B-a, L, N) # x-axis
def V(x):
'''
#Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<=-a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
# odeint(func, y0, t)
# solve_ivp(fun, t_span, y0)
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
f2 = figure(2)
plot(x, Wave_function(9.8)[0][:1000])
grid()
f2.show()

if __name__ == "__main__":
main()


this is what the code gives me in the end. the right side is okay but the left side is wrong. I depend on both sides working, not for visuals.
enter image description here



edit:
for charity this is what the potential function should look like:
enter image description here



the final graph should look similar to this:
enter image description here










share|improve this question

























  • Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

    – user8408080
    Nov 24 '18 at 22:02











  • sure, I'll start writing it on LaTeX

    – user169808
    Nov 26 '18 at 12:44











  • We need to know the equation, otherwise is difficult to see the problem.

    – b-fg
    Nov 27 '18 at 4:39











  • I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

    – user169808
    Nov 28 '18 at 14:30











  • How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

    – Thomas Kühn
    Nov 29 '18 at 10:16


















4















I've been trying to use either solve_ivp or solve_bvp to solve a problem I've been having but I'm not making any progress. I think the code I have here will work but I cannot get the range to be correct. for some reason I cannot understand the range is always going from 0 to x and not from -x to x can someone help me fix this part for solve_ivp?



here is the code reduced to a min



from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1
B=4
L= B+a
Vmax= 50
Vpot = False

N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = array([0,1]) # Wave function initial states
Vo = 50
E = 0.0 # global variable Energy needed for Sch.Eq, changed in function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = linspace(-B-a, L, N) # x-axis
def V(x):
'''
#Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<=-a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
# odeint(func, y0, t)
# solve_ivp(fun, t_span, y0)
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
f2 = figure(2)
plot(x, Wave_function(9.8)[0][:1000])
grid()
f2.show()

if __name__ == "__main__":
main()


this is what the code gives me in the end. the right side is okay but the left side is wrong. I depend on both sides working, not for visuals.
enter image description here



edit:
for charity this is what the potential function should look like:
enter image description here



the final graph should look similar to this:
enter image description here










share|improve this question

























  • Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

    – user8408080
    Nov 24 '18 at 22:02











  • sure, I'll start writing it on LaTeX

    – user169808
    Nov 26 '18 at 12:44











  • We need to know the equation, otherwise is difficult to see the problem.

    – b-fg
    Nov 27 '18 at 4:39











  • I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

    – user169808
    Nov 28 '18 at 14:30











  • How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

    – Thomas Kühn
    Nov 29 '18 at 10:16














4












4








4








I've been trying to use either solve_ivp or solve_bvp to solve a problem I've been having but I'm not making any progress. I think the code I have here will work but I cannot get the range to be correct. for some reason I cannot understand the range is always going from 0 to x and not from -x to x can someone help me fix this part for solve_ivp?



here is the code reduced to a min



from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1
B=4
L= B+a
Vmax= 50
Vpot = False

N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = array([0,1]) # Wave function initial states
Vo = 50
E = 0.0 # global variable Energy needed for Sch.Eq, changed in function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = linspace(-B-a, L, N) # x-axis
def V(x):
'''
#Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<=-a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
# odeint(func, y0, t)
# solve_ivp(fun, t_span, y0)
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
f2 = figure(2)
plot(x, Wave_function(9.8)[0][:1000])
grid()
f2.show()

if __name__ == "__main__":
main()


this is what the code gives me in the end. the right side is okay but the left side is wrong. I depend on both sides working, not for visuals.
enter image description here



edit:
for charity this is what the potential function should look like:
enter image description here



the final graph should look similar to this:
enter image description here










share|improve this question
















I've been trying to use either solve_ivp or solve_bvp to solve a problem I've been having but I'm not making any progress. I think the code I have here will work but I cannot get the range to be correct. for some reason I cannot understand the range is always going from 0 to x and not from -x to x can someone help me fix this part for solve_ivp?



here is the code reduced to a min



from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1
B=4
L= B+a
Vmax= 50
Vpot = False

N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = array([0,1]) # Wave function initial states
Vo = 50
E = 0.0 # global variable Energy needed for Sch.Eq, changed in function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = linspace(-B-a, L, N) # x-axis
def V(x):
'''
#Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<=-a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
# odeint(func, y0, t)
# solve_ivp(fun, t_span, y0)
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
f2 = figure(2)
plot(x, Wave_function(9.8)[0][:1000])
grid()
f2.show()

if __name__ == "__main__":
main()


this is what the code gives me in the end. the right side is okay but the left side is wrong. I depend on both sides working, not for visuals.
enter image description here



edit:
for charity this is what the potential function should look like:
enter image description here



the final graph should look similar to this:
enter image description here







python scipy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 20:17









Mr. T

4,22391636




4,22391636










asked Nov 22 '18 at 12:41









user169808user169808

8112




8112













  • Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

    – user8408080
    Nov 24 '18 at 22:02











  • sure, I'll start writing it on LaTeX

    – user169808
    Nov 26 '18 at 12:44











  • We need to know the equation, otherwise is difficult to see the problem.

    – b-fg
    Nov 27 '18 at 4:39











  • I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

    – user169808
    Nov 28 '18 at 14:30











  • How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

    – Thomas Kühn
    Nov 29 '18 at 10:16



















  • Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

    – user8408080
    Nov 24 '18 at 22:02











  • sure, I'll start writing it on LaTeX

    – user169808
    Nov 26 '18 at 12:44











  • We need to know the equation, otherwise is difficult to see the problem.

    – b-fg
    Nov 27 '18 at 4:39











  • I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

    – user169808
    Nov 28 '18 at 14:30











  • How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

    – Thomas Kühn
    Nov 29 '18 at 10:16

















Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

– user8408080
Nov 24 '18 at 22:02





Can you post the original equation to solve? (Maybe as a picture of some TeX pdf?)

– user8408080
Nov 24 '18 at 22:02













sure, I'll start writing it on LaTeX

– user169808
Nov 26 '18 at 12:44





sure, I'll start writing it on LaTeX

– user169808
Nov 26 '18 at 12:44













We need to know the equation, otherwise is difficult to see the problem.

– b-fg
Nov 27 '18 at 4:39





We need to know the equation, otherwise is difficult to see the problem.

– b-fg
Nov 27 '18 at 4:39













I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

– user169808
Nov 28 '18 at 14:30





I found a page on the internet that has the original equation, its just the time independent Schrodinger equation. here vergil.chemistry.gatech.edu/notes/quantrev/node8.html

– user169808
Nov 28 '18 at 14:30













How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

– Thomas Kühn
Nov 29 '18 at 10:16





How do you determine that psi0 = array([0,1])? Vmax is not infinite, so the wave function should be finite at the well boundary, or did I understand something wrong?

– Thomas Kühn
Nov 29 '18 at 10:16












2 Answers
2






active

oldest

votes


















0














Not sure if it helps but it may gives you a hint.
It is not that solve_ivp doesn't work for -x to 0, but your function V may be wrong. I noticed that the wave begins to appear after that V decreases from Vmax to 0.



This code :



%matplotlib inline
from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1.
B=4.
L= B+a
Vmax= 50.

N = 10000
E = 9.8

def V(x):
if -L <= x <= -B:
return Vmax
else:
return 0

def SE(z, p):
state0 = p[1]
state1 = (V(z) - E)*p[0]
return array([state0, state1])

def Wave_function():
return solve_ivp(SE, [-L, L], [0., 1.], max_step=2*L/N)

result = Wave_function()
plot(result.t, result.y[0], color='tab:blue')


gives you the "expected" output :



enter image description here






share|improve this answer


























  • "I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

    – user169808
    Nov 28 '18 at 19:56











  • @user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

    – Corentin Limier
    Nov 28 '18 at 20:01











  • I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

    – user169808
    Nov 28 '18 at 20:09



















0














Your code seems Okay in general. However, given your figure for the potential energy, the value for Vo should be *Vo = 10. In addition, in your main function your are only plotting the wave function as the solution of the Schrodinger Equation. Bellow, is what I am proposing you as a possible solution to your problem assuming that I properly understood your concern:



import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import numpy as np

a=1
B=4
L= B+a
Vmax= 50


N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = np.array([0,1]) # Wave function initial states
Vo = 10 # Not 50, in order to conform your figure of the potential energy
E = 0.0 # global variable Energy needed for Sch.Eq, changed in
# function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = np.linspace(-L, L, N) # linspace(-B-a, L, N) # x-axis


def V(x):
'''
Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<= -L: # -a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
plt.figure()
plt.subplot(121)
plt.plot(x, Wave_function(9.8)[0][:1000])
plt.grid()
plt.title("Wave function")
plt.xlabel(r"$ x $")
plt.ylabel(r"$psi(x)$")
plt.subplot(122)

potential = np.vectorize(V) # Make the function 'V(x)' to also work on array

pot = potential(x) # Potential ernergy in the defined domain of 'x'
t = [-L, -a, a, L] # the singular value of x
y = potential(t) # the potential energy at thos singular value of 'x'
# But to conform your figure I'll just do y = 0 * y
plt.plot(x, pot, t, 0*y, 'ko')
plt.title("Potential Energy")
plt.xlabel(r"$ x $")
plt.ylabel(r"$V(x)$")
plt.show()

if __name__ == "__main__":
main()


The output figure is the following:



enter image description here






share|improve this answer
























  • my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

    – user169808
    Nov 29 '18 at 14:16












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431271%2fsolve-ivp-from-x-to-x%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Not sure if it helps but it may gives you a hint.
It is not that solve_ivp doesn't work for -x to 0, but your function V may be wrong. I noticed that the wave begins to appear after that V decreases from Vmax to 0.



This code :



%matplotlib inline
from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1.
B=4.
L= B+a
Vmax= 50.

N = 10000
E = 9.8

def V(x):
if -L <= x <= -B:
return Vmax
else:
return 0

def SE(z, p):
state0 = p[1]
state1 = (V(z) - E)*p[0]
return array([state0, state1])

def Wave_function():
return solve_ivp(SE, [-L, L], [0., 1.], max_step=2*L/N)

result = Wave_function()
plot(result.t, result.y[0], color='tab:blue')


gives you the "expected" output :



enter image description here






share|improve this answer


























  • "I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

    – user169808
    Nov 28 '18 at 19:56











  • @user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

    – Corentin Limier
    Nov 28 '18 at 20:01











  • I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

    – user169808
    Nov 28 '18 at 20:09
















0














Not sure if it helps but it may gives you a hint.
It is not that solve_ivp doesn't work for -x to 0, but your function V may be wrong. I noticed that the wave begins to appear after that V decreases from Vmax to 0.



This code :



%matplotlib inline
from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1.
B=4.
L= B+a
Vmax= 50.

N = 10000
E = 9.8

def V(x):
if -L <= x <= -B:
return Vmax
else:
return 0

def SE(z, p):
state0 = p[1]
state1 = (V(z) - E)*p[0]
return array([state0, state1])

def Wave_function():
return solve_ivp(SE, [-L, L], [0., 1.], max_step=2*L/N)

result = Wave_function()
plot(result.t, result.y[0], color='tab:blue')


gives you the "expected" output :



enter image description here






share|improve this answer


























  • "I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

    – user169808
    Nov 28 '18 at 19:56











  • @user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

    – Corentin Limier
    Nov 28 '18 at 20:01











  • I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

    – user169808
    Nov 28 '18 at 20:09














0












0








0







Not sure if it helps but it may gives you a hint.
It is not that solve_ivp doesn't work for -x to 0, but your function V may be wrong. I noticed that the wave begins to appear after that V decreases from Vmax to 0.



This code :



%matplotlib inline
from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1.
B=4.
L= B+a
Vmax= 50.

N = 10000
E = 9.8

def V(x):
if -L <= x <= -B:
return Vmax
else:
return 0

def SE(z, p):
state0 = p[1]
state1 = (V(z) - E)*p[0]
return array([state0, state1])

def Wave_function():
return solve_ivp(SE, [-L, L], [0., 1.], max_step=2*L/N)

result = Wave_function()
plot(result.t, result.y[0], color='tab:blue')


gives you the "expected" output :



enter image description here






share|improve this answer















Not sure if it helps but it may gives you a hint.
It is not that solve_ivp doesn't work for -x to 0, but your function V may be wrong. I noticed that the wave begins to appear after that V decreases from Vmax to 0.



This code :



%matplotlib inline
from pylab import *
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
import numpy as np
import itertools

a=1.
B=4.
L= B+a
Vmax= 50.

N = 10000
E = 9.8

def V(x):
if -L <= x <= -B:
return Vmax
else:
return 0

def SE(z, p):
state0 = p[1]
state1 = (V(z) - E)*p[0]
return array([state0, state1])

def Wave_function():
return solve_ivp(SE, [-L, L], [0., 1.], max_step=2*L/N)

result = Wave_function()
plot(result.t, result.y[0], color='tab:blue')


gives you the "expected" output :



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 28 '18 at 17:57

























answered Nov 28 '18 at 17:52









Corentin LimierCorentin Limier

2,0711611




2,0711611













  • "I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

    – user169808
    Nov 28 '18 at 19:56











  • @user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

    – Corentin Limier
    Nov 28 '18 at 20:01











  • I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

    – user169808
    Nov 28 '18 at 20:09



















  • "I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

    – user169808
    Nov 28 '18 at 19:56











  • @user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

    – Corentin Limier
    Nov 28 '18 at 20:01











  • I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

    – user169808
    Nov 28 '18 at 20:09

















"I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

– user169808
Nov 28 '18 at 19:56





"I noticed that the wave begins to appear after that V decreases from Vmax to 0" well that is to be expected because I'm modeling an infinite square well, ie vmax = $infty$. I'll add a picture of what the potential function should look like, and this is what my V(x) is giving me

– user169808
Nov 28 '18 at 19:56













@user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

– Corentin Limier
Nov 28 '18 at 20:01





@user169808 if that is expected why did you say that the left part of the graph is wrong ? Your wave starts when v decreases (at t=a=1)

– Corentin Limier
Nov 28 '18 at 20:01













I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

– user169808
Nov 28 '18 at 20:09





I added a few images which I think will clear somethings up, since everything is symmetric the wave for x<=0 has to be similar to the wave for x>=0 (page 19 and 20 from this article can illustrate physics.utah.edu/~lebohec/P3740/…)

– user169808
Nov 28 '18 at 20:09













0














Your code seems Okay in general. However, given your figure for the potential energy, the value for Vo should be *Vo = 10. In addition, in your main function your are only plotting the wave function as the solution of the Schrodinger Equation. Bellow, is what I am proposing you as a possible solution to your problem assuming that I properly understood your concern:



import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import numpy as np

a=1
B=4
L= B+a
Vmax= 50


N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = np.array([0,1]) # Wave function initial states
Vo = 10 # Not 50, in order to conform your figure of the potential energy
E = 0.0 # global variable Energy needed for Sch.Eq, changed in
# function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = np.linspace(-L, L, N) # linspace(-B-a, L, N) # x-axis


def V(x):
'''
Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<= -L: # -a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
plt.figure()
plt.subplot(121)
plt.plot(x, Wave_function(9.8)[0][:1000])
plt.grid()
plt.title("Wave function")
plt.xlabel(r"$ x $")
plt.ylabel(r"$psi(x)$")
plt.subplot(122)

potential = np.vectorize(V) # Make the function 'V(x)' to also work on array

pot = potential(x) # Potential ernergy in the defined domain of 'x'
t = [-L, -a, a, L] # the singular value of x
y = potential(t) # the potential energy at thos singular value of 'x'
# But to conform your figure I'll just do y = 0 * y
plt.plot(x, pot, t, 0*y, 'ko')
plt.title("Potential Energy")
plt.xlabel(r"$ x $")
plt.ylabel(r"$V(x)$")
plt.show()

if __name__ == "__main__":
main()


The output figure is the following:



enter image description here






share|improve this answer
























  • my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

    – user169808
    Nov 29 '18 at 14:16
















0














Your code seems Okay in general. However, given your figure for the potential energy, the value for Vo should be *Vo = 10. In addition, in your main function your are only plotting the wave function as the solution of the Schrodinger Equation. Bellow, is what I am proposing you as a possible solution to your problem assuming that I properly understood your concern:



import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import numpy as np

a=1
B=4
L= B+a
Vmax= 50


N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = np.array([0,1]) # Wave function initial states
Vo = 10 # Not 50, in order to conform your figure of the potential energy
E = 0.0 # global variable Energy needed for Sch.Eq, changed in
# function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = np.linspace(-L, L, N) # linspace(-B-a, L, N) # x-axis


def V(x):
'''
Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<= -L: # -a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
plt.figure()
plt.subplot(121)
plt.plot(x, Wave_function(9.8)[0][:1000])
plt.grid()
plt.title("Wave function")
plt.xlabel(r"$ x $")
plt.ylabel(r"$psi(x)$")
plt.subplot(122)

potential = np.vectorize(V) # Make the function 'V(x)' to also work on array

pot = potential(x) # Potential ernergy in the defined domain of 'x'
t = [-L, -a, a, L] # the singular value of x
y = potential(t) # the potential energy at thos singular value of 'x'
# But to conform your figure I'll just do y = 0 * y
plt.plot(x, pot, t, 0*y, 'ko')
plt.title("Potential Energy")
plt.xlabel(r"$ x $")
plt.ylabel(r"$V(x)$")
plt.show()

if __name__ == "__main__":
main()


The output figure is the following:



enter image description here






share|improve this answer
























  • my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

    – user169808
    Nov 29 '18 at 14:16














0












0








0







Your code seems Okay in general. However, given your figure for the potential energy, the value for Vo should be *Vo = 10. In addition, in your main function your are only plotting the wave function as the solution of the Schrodinger Equation. Bellow, is what I am proposing you as a possible solution to your problem assuming that I properly understood your concern:



import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import numpy as np

a=1
B=4
L= B+a
Vmax= 50


N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = np.array([0,1]) # Wave function initial states
Vo = 10 # Not 50, in order to conform your figure of the potential energy
E = 0.0 # global variable Energy needed for Sch.Eq, changed in
# function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = np.linspace(-L, L, N) # linspace(-B-a, L, N) # x-axis


def V(x):
'''
Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<= -L: # -a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
plt.figure()
plt.subplot(121)
plt.plot(x, Wave_function(9.8)[0][:1000])
plt.grid()
plt.title("Wave function")
plt.xlabel(r"$ x $")
plt.ylabel(r"$psi(x)$")
plt.subplot(122)

potential = np.vectorize(V) # Make the function 'V(x)' to also work on array

pot = potential(x) # Potential ernergy in the defined domain of 'x'
t = [-L, -a, a, L] # the singular value of x
y = potential(t) # the potential energy at thos singular value of 'x'
# But to conform your figure I'll just do y = 0 * y
plt.plot(x, pot, t, 0*y, 'ko')
plt.title("Potential Energy")
plt.xlabel(r"$ x $")
plt.ylabel(r"$V(x)$")
plt.show()

if __name__ == "__main__":
main()


The output figure is the following:



enter image description here






share|improve this answer













Your code seems Okay in general. However, given your figure for the potential energy, the value for Vo should be *Vo = 10. In addition, in your main function your are only plotting the wave function as the solution of the Schrodinger Equation. Bellow, is what I am proposing you as a possible solution to your problem assuming that I properly understood your concern:



import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import numpy as np

a=1
B=4
L= B+a
Vmax= 50


N = 1000 # number of points to take
psi = np.zeros([N,2]) # Wave function values and its derivative (psi and psi')
psi0 = np.array([0,1]) # Wave function initial states
Vo = 10 # Not 50, in order to conform your figure of the potential energy
E = 0.0 # global variable Energy needed for Sch.Eq, changed in
# function "Wave function"
b = L # point outside of well where we need to check if the function diverges
x = np.linspace(-L, L, N) # linspace(-B-a, L, N) # x-axis


def V(x):
'''
Potential function in the finite square well.
'''
if -a <=x <=a:
val = Vo
elif x<= -L: # -a-B:
val = Vmax
elif x>=L:
val = Vmax
else:
val = 0
return val

def SE(z, p):
state0 = p[1]
state1 = 1.0*(V(z) - E)*p[0]
return array([state0, state1])

def Wave_function(energy):
global E
E = energy
psi = solve_ivp(SE, [-B-a, L], psi0, max_step = ((B+a+L)/(N)))
return psi.y

def main():
# main program
plt.figure()
plt.subplot(121)
plt.plot(x, Wave_function(9.8)[0][:1000])
plt.grid()
plt.title("Wave function")
plt.xlabel(r"$ x $")
plt.ylabel(r"$psi(x)$")
plt.subplot(122)

potential = np.vectorize(V) # Make the function 'V(x)' to also work on array

pot = potential(x) # Potential ernergy in the defined domain of 'x'
t = [-L, -a, a, L] # the singular value of x
y = potential(t) # the potential energy at thos singular value of 'x'
# But to conform your figure I'll just do y = 0 * y
plt.plot(x, pot, t, 0*y, 'ko')
plt.title("Potential Energy")
plt.xlabel(r"$ x $")
plt.ylabel(r"$V(x)$")
plt.show()

if __name__ == "__main__":
main()


The output figure is the following:



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 29 '18 at 13:19









eapetchoeapetcho

42727




42727













  • my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

    – user169808
    Nov 29 '18 at 14:16



















  • my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

    – user169808
    Nov 29 '18 at 14:16

















my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

– user169808
Nov 29 '18 at 14:16





my problem is that the graph of psi(x) should be similar to the last image in my post. the amplitude should be the same for both sides of the barrier.

– user169808
Nov 29 '18 at 14:16


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431271%2fsolve-ivp-from-x-to-x%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)