How to implement boundary value in Python using spectral methodsNumerical methods for a second order PDE boundary value problemSpectral convergence for collocation methodsInitial&Boundary Value problem-FourierHow do I implement boundary conditions using separation of variablesBoundary Value Heat EquationBoundary-value problems using sympyFinding roots of algebraic equations using PythonHow to solve this differential equation numerically in Python?Applying neumann boundary conditions to diffusion equation solution in pythonErdős-Straus-conjecture using polynomials in Python

Justification failure in beamer enumerate list

Animating wave motion in water

Unfrosted light bulb

"Marked down as someone wanting to sell shares." What does that mean?

Why I don't get the wanted width of tcbox?

Print last inputted byte

When did hardware antialiasing start being available?

Why do I have a large white artefact on the rendered image?

Was World War I a war of liberals against authoritarians?

Should I be concerned about student access to a test bank?

Why doesn't the chatan sign the ketubah?

PTIJ: Which Dr. Seuss books should one obtain?

Do I need to convey a moral for each of my blog post?

How to balance a monster modification (zombie)?

Can other pieces capture a threatening piece and prevent a checkmate?

Exit shell with shortcut (not typing exit) that closes session properly

Hackerrank All Women's Codesprint 2019: Name the Product

Nested Dynamic SOQL Query

Do people actually use the word "kaputt" in conversation?

TDE Master Key Rotation

Have any astronauts/cosmonauts died in space?

Have the tides ever turned twice on any open problem?

What will the Frenchman say?

Weird lines in Microsoft Word



How to implement boundary value in Python using spectral methods


Numerical methods for a second order PDE boundary value problemSpectral convergence for collocation methodsInitial&Boundary Value problem-FourierHow do I implement boundary conditions using separation of variablesBoundary Value Heat EquationBoundary-value problems using sympyFinding roots of algebraic equations using PythonHow to solve this differential equation numerically in Python?Applying neumann boundary conditions to diffusion equation solution in pythonErdős-Straus-conjecture using polynomials in Python













1












$begingroup$


I want to solve the heat equation $$u_t=au_xx,quad 0leq t, 0leq xleqpi$$ in Python using spectral methods. I set $u(0,x)=sin(x)$ as initial value for the time and choose $a=2$. My Code:



import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from scipy.integrate import odeint
from scipy.fftpack import diff as psdiff

def GenerateID(x):
u = np.sin(x)
return u

def hEq(u, t, L, a):
uxx = psdiff(u, period=L, order=2)
dudt = a*uxx
return dudt

def hEq_solution(u0, t, L):
sol = odeint(hEq, u0, t, args=(L,a,), mxstep=5000)
return sol

if __name__ == "__main__":
L = np.pi
N = 1000
x = np.linspace(0, L, N)
a = 2
u0 = GenerateID(x)
Tfinal = 5.0
t = np.linspace(0.0, Tfinal, 1000)
sol = hEq_solution(u0, t, L)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sx, st = np.meshgrid(x, t)
ax.plot_surface(sx, st, sol, cmap='jet')
plt.xlabel('x')
plt.ylabel('t')
plt.show()


Which produces enter image description here
This seems kind of right. Now my question: If I want to introduce the boundary condition $$u(t,0)=u(t,pi)=0,$$ how would I do that? I know that considering all above conditions, the exact solution should be $$u(x,t)=exp[-2t]sin(x).$$










share|cite|improve this question











$endgroup$







  • 3




    $begingroup$
    In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
    $endgroup$
    – Ian
    Mar 13 at 7:48











  • $begingroup$
    Please use the Math forum only for Math questions
    $endgroup$
    – asdf
    Mar 13 at 13:33










  • $begingroup$
    Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
    $endgroup$
    – schoeni
    Mar 14 at 5:36
















1












$begingroup$


I want to solve the heat equation $$u_t=au_xx,quad 0leq t, 0leq xleqpi$$ in Python using spectral methods. I set $u(0,x)=sin(x)$ as initial value for the time and choose $a=2$. My Code:



import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from scipy.integrate import odeint
from scipy.fftpack import diff as psdiff

def GenerateID(x):
u = np.sin(x)
return u

def hEq(u, t, L, a):
uxx = psdiff(u, period=L, order=2)
dudt = a*uxx
return dudt

def hEq_solution(u0, t, L):
sol = odeint(hEq, u0, t, args=(L,a,), mxstep=5000)
return sol

if __name__ == "__main__":
L = np.pi
N = 1000
x = np.linspace(0, L, N)
a = 2
u0 = GenerateID(x)
Tfinal = 5.0
t = np.linspace(0.0, Tfinal, 1000)
sol = hEq_solution(u0, t, L)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sx, st = np.meshgrid(x, t)
ax.plot_surface(sx, st, sol, cmap='jet')
plt.xlabel('x')
plt.ylabel('t')
plt.show()


Which produces enter image description here
This seems kind of right. Now my question: If I want to introduce the boundary condition $$u(t,0)=u(t,pi)=0,$$ how would I do that? I know that considering all above conditions, the exact solution should be $$u(x,t)=exp[-2t]sin(x).$$










share|cite|improve this question











$endgroup$







  • 3




    $begingroup$
    In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
    $endgroup$
    – Ian
    Mar 13 at 7:48











  • $begingroup$
    Please use the Math forum only for Math questions
    $endgroup$
    – asdf
    Mar 13 at 13:33










  • $begingroup$
    Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
    $endgroup$
    – schoeni
    Mar 14 at 5:36














1












1








1


1



$begingroup$


I want to solve the heat equation $$u_t=au_xx,quad 0leq t, 0leq xleqpi$$ in Python using spectral methods. I set $u(0,x)=sin(x)$ as initial value for the time and choose $a=2$. My Code:



import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from scipy.integrate import odeint
from scipy.fftpack import diff as psdiff

def GenerateID(x):
u = np.sin(x)
return u

def hEq(u, t, L, a):
uxx = psdiff(u, period=L, order=2)
dudt = a*uxx
return dudt

def hEq_solution(u0, t, L):
sol = odeint(hEq, u0, t, args=(L,a,), mxstep=5000)
return sol

if __name__ == "__main__":
L = np.pi
N = 1000
x = np.linspace(0, L, N)
a = 2
u0 = GenerateID(x)
Tfinal = 5.0
t = np.linspace(0.0, Tfinal, 1000)
sol = hEq_solution(u0, t, L)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sx, st = np.meshgrid(x, t)
ax.plot_surface(sx, st, sol, cmap='jet')
plt.xlabel('x')
plt.ylabel('t')
plt.show()


Which produces enter image description here
This seems kind of right. Now my question: If I want to introduce the boundary condition $$u(t,0)=u(t,pi)=0,$$ how would I do that? I know that considering all above conditions, the exact solution should be $$u(x,t)=exp[-2t]sin(x).$$










share|cite|improve this question











$endgroup$




I want to solve the heat equation $$u_t=au_xx,quad 0leq t, 0leq xleqpi$$ in Python using spectral methods. I set $u(0,x)=sin(x)$ as initial value for the time and choose $a=2$. My Code:



import numpy as np
import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D
from scipy.integrate import odeint
from scipy.fftpack import diff as psdiff

def GenerateID(x):
u = np.sin(x)
return u

def hEq(u, t, L, a):
uxx = psdiff(u, period=L, order=2)
dudt = a*uxx
return dudt

def hEq_solution(u0, t, L):
sol = odeint(hEq, u0, t, args=(L,a,), mxstep=5000)
return sol

if __name__ == "__main__":
L = np.pi
N = 1000
x = np.linspace(0, L, N)
a = 2
u0 = GenerateID(x)
Tfinal = 5.0
t = np.linspace(0.0, Tfinal, 1000)
sol = hEq_solution(u0, t, L)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
sx, st = np.meshgrid(x, t)
ax.plot_surface(sx, st, sol, cmap='jet')
plt.xlabel('x')
plt.ylabel('t')
plt.show()


Which produces enter image description here
This seems kind of right. Now my question: If I want to introduce the boundary condition $$u(t,0)=u(t,pi)=0,$$ how would I do that? I know that considering all above conditions, the exact solution should be $$u(x,t)=exp[-2t]sin(x).$$







ordinary-differential-equations pde python fast-fourier-transform






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Mar 13 at 12:33









Brian

677115




677115










asked Mar 13 at 7:41









schoenischoeni

185




185







  • 3




    $begingroup$
    In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
    $endgroup$
    – Ian
    Mar 13 at 7:48











  • $begingroup$
    Please use the Math forum only for Math questions
    $endgroup$
    – asdf
    Mar 13 at 13:33










  • $begingroup$
    Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
    $endgroup$
    – schoeni
    Mar 14 at 5:36













  • 3




    $begingroup$
    In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
    $endgroup$
    – Ian
    Mar 13 at 7:48











  • $begingroup$
    Please use the Math forum only for Math questions
    $endgroup$
    – asdf
    Mar 13 at 13:33










  • $begingroup$
    Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
    $endgroup$
    – schoeni
    Mar 14 at 5:36








3




3




$begingroup$
In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
$endgroup$
– Ian
Mar 13 at 7:48





$begingroup$
In a spectral method the boundary conditions are baked into the choice of the basis functions ($sin(nx)$ in your case). Thus really the question is whether your fft is set up to do a sine transform or not which is now really a programming question.
$endgroup$
– Ian
Mar 13 at 7:48













$begingroup$
Please use the Math forum only for Math questions
$endgroup$
– asdf
Mar 13 at 13:33




$begingroup$
Please use the Math forum only for Math questions
$endgroup$
– asdf
Mar 13 at 13:33












$begingroup$
Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
$endgroup$
– schoeni
Mar 14 at 5:36





$begingroup$
Well, it is a math question now. @Ian I don't understand how the basis would do that. Also, can I influence that by calculating the fft and change the wave numbers?
$endgroup$
– schoeni
Mar 14 at 5:36











0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
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
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3146228%2fhow-to-implement-boundary-value-in-python-using-spectral-methods%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • 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.

Use MathJax to format equations. MathJax reference.


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%2fmath.stackexchange.com%2fquestions%2f3146228%2fhow-to-implement-boundary-value-in-python-using-spectral-methods%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

Moe incest case Sentencing See also References Navigation menu"'Australian Josef Fritzl' fathered four children by daughter""Small town recoils in horror at 'Australian Fritzl' incest case""Victorian rape allegations echo Fritzl case - Just In (Australian Broadcasting Corporation)""Incest father jailed for 22 years""'Australian Fritzl' sentenced to 22 years in prison for abusing daughter for three decades""RSJ v The Queen"

Daza language Contents Vocabulary Phonology References External links Navigation menudaza1242Daza"Dazaga"eeee178086576

Who is our nearest planetary neighbor, on average?Santa Claus flies to the South PoleSeven Spheres of Unequal Mass, a weighing problem with a twistDescribe a large integerFast Mental Calculation of $7.5^7$Math in Space (without the help of celebrities)Find the value of $bigstar$: Puzzle 8 - InequalityWho drinks beer while running anyway?A Crucial DeliveryRanking And AverageHow long will my money last at roulette?