How to solve this differential equation numerically in Python?
$begingroup$
I am trying to solve a differential equation in Python:
$$y'' + 2frac{y'}{x} + (1 - frac{e^{-x}}{x} - frac{l(l+1)}{x^2})y = 0$$
I have initial conditions at $x=0$ as:
$$y(0) = a$$
$$y'(0) = b$$
$a$ and $b$ are some known constants and they will be constrained by $l$. I tried using Euler forward method but solution was unstable. I tried Runge-Kutta 2nd order method but again the solution was unstable. What method should I use so that I will get a stable solution?
ordinary-differential-equations numerical-methods python
$endgroup$
add a comment |
$begingroup$
I am trying to solve a differential equation in Python:
$$y'' + 2frac{y'}{x} + (1 - frac{e^{-x}}{x} - frac{l(l+1)}{x^2})y = 0$$
I have initial conditions at $x=0$ as:
$$y(0) = a$$
$$y'(0) = b$$
$a$ and $b$ are some known constants and they will be constrained by $l$. I tried using Euler forward method but solution was unstable. I tried Runge-Kutta 2nd order method but again the solution was unstable. What method should I use so that I will get a stable solution?
ordinary-differential-equations numerical-methods python
$endgroup$
1
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
1
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06
add a comment |
$begingroup$
I am trying to solve a differential equation in Python:
$$y'' + 2frac{y'}{x} + (1 - frac{e^{-x}}{x} - frac{l(l+1)}{x^2})y = 0$$
I have initial conditions at $x=0$ as:
$$y(0) = a$$
$$y'(0) = b$$
$a$ and $b$ are some known constants and they will be constrained by $l$. I tried using Euler forward method but solution was unstable. I tried Runge-Kutta 2nd order method but again the solution was unstable. What method should I use so that I will get a stable solution?
ordinary-differential-equations numerical-methods python
$endgroup$
I am trying to solve a differential equation in Python:
$$y'' + 2frac{y'}{x} + (1 - frac{e^{-x}}{x} - frac{l(l+1)}{x^2})y = 0$$
I have initial conditions at $x=0$ as:
$$y(0) = a$$
$$y'(0) = b$$
$a$ and $b$ are some known constants and they will be constrained by $l$. I tried using Euler forward method but solution was unstable. I tried Runge-Kutta 2nd order method but again the solution was unstable. What method should I use so that I will get a stable solution?
ordinary-differential-equations numerical-methods python
ordinary-differential-equations numerical-methods python
asked May 29 '18 at 9:57
Yaman SanghaviYaman Sanghavi
1876
1876
1
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
1
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06
add a comment |
1
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
1
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06
1
1
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
1
1
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
This equation is stiff for $xll1$ because the dominant term is the first derivative (you can check the coefficients w.r.t. the first one, which is one).
The Runge-Kutta methods are explicit and they are not suitable to solve these kind of stiff equations (however, for $xgg 1$ they fit perfectly).
You should go for implicit methods. Try the simplest one: backward Euler method.
$endgroup$
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2800359%2fhow-to-solve-this-differential-equation-numerically-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
This equation is stiff for $xll1$ because the dominant term is the first derivative (you can check the coefficients w.r.t. the first one, which is one).
The Runge-Kutta methods are explicit and they are not suitable to solve these kind of stiff equations (however, for $xgg 1$ they fit perfectly).
You should go for implicit methods. Try the simplest one: backward Euler method.
$endgroup$
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
add a comment |
$begingroup$
This equation is stiff for $xll1$ because the dominant term is the first derivative (you can check the coefficients w.r.t. the first one, which is one).
The Runge-Kutta methods are explicit and they are not suitable to solve these kind of stiff equations (however, for $xgg 1$ they fit perfectly).
You should go for implicit methods. Try the simplest one: backward Euler method.
$endgroup$
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
add a comment |
$begingroup$
This equation is stiff for $xll1$ because the dominant term is the first derivative (you can check the coefficients w.r.t. the first one, which is one).
The Runge-Kutta methods are explicit and they are not suitable to solve these kind of stiff equations (however, for $xgg 1$ they fit perfectly).
You should go for implicit methods. Try the simplest one: backward Euler method.
$endgroup$
This equation is stiff for $xll1$ because the dominant term is the first derivative (you can check the coefficients w.r.t. the first one, which is one).
The Runge-Kutta methods are explicit and they are not suitable to solve these kind of stiff equations (however, for $xgg 1$ they fit perfectly).
You should go for implicit methods. Try the simplest one: backward Euler method.
answered May 29 '18 at 10:28
HBRHBR
1,69359
1,69359
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
add a comment |
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
$begingroup$
It is not only stiff, but downright singular at $x=0$.
$endgroup$
– LutzL
Dec 10 '18 at 14:39
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2800359%2fhow-to-solve-this-differential-equation-numerically-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
$begingroup$
The "industry standard" is Runge-Kutta 4. Have you tried that?
$endgroup$
– Arthur
May 29 '18 at 10:02
$begingroup$
@Arthur I haven't tried. I just want to ask, because I am new in this,, that does that work in such cases?
$endgroup$
– Yaman Sanghavi
May 29 '18 at 10:20
$begingroup$
See dopri5 option at docs.scipy.org/doc/scipy-0.13.0/reference/generated/…
$endgroup$
– J.G.
May 29 '18 at 10:32
1
$begingroup$
You asked about the same differential equation in MSE question 2785298 but using Mathematica instead.
$endgroup$
– Somos
May 29 '18 at 11:52
$begingroup$
@Somos Yeah, and it worked on mathematica. But, I wanted to know that how would I implement it on python. Because mathematica doesn't show the method it used.
$endgroup$
– Yaman Sanghavi
May 29 '18 at 16:06