How to apply improved Euler method to a systems of differential equation?
$begingroup$
I have the following problem (linearized pendulum problem):
$x_1'=x_2$
$x_2'=-frac{g}{L}*sin(x_1)$
with the following initial condition:
$x_1(t_0)=0$
$x_2(t_0)=0$
Improved Euler Method says that:
$Y_{k+1}=Y_k+frac{h}{2}*[f(t_k, Y_k)+f(t_{k+1}, Y_k+h*f(t_k, Y_k))]$
In this case I have done the following:
$x_{1, k+1}=x_{1, k}+frac{h}{2}*[x_{1, k}+(x_{1, k}+h*x_{1, k})]$
$x_{2, k+1}=x_{2, k}+frac{h}{2}*[-frac{g}{L}*sin(x_{1, k})+-frac{g}{L}*sin(x_{1, k}+h*(-frac{g}{L}*sin(x_{1, k}))))]$
Where is my mistake?
numerical-methods
$endgroup$
add a comment |
$begingroup$
I have the following problem (linearized pendulum problem):
$x_1'=x_2$
$x_2'=-frac{g}{L}*sin(x_1)$
with the following initial condition:
$x_1(t_0)=0$
$x_2(t_0)=0$
Improved Euler Method says that:
$Y_{k+1}=Y_k+frac{h}{2}*[f(t_k, Y_k)+f(t_{k+1}, Y_k+h*f(t_k, Y_k))]$
In this case I have done the following:
$x_{1, k+1}=x_{1, k}+frac{h}{2}*[x_{1, k}+(x_{1, k}+h*x_{1, k})]$
$x_{2, k+1}=x_{2, k}+frac{h}{2}*[-frac{g}{L}*sin(x_{1, k})+-frac{g}{L}*sin(x_{1, k}+h*(-frac{g}{L}*sin(x_{1, k}))))]$
Where is my mistake?
numerical-methods
$endgroup$
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27
add a comment |
$begingroup$
I have the following problem (linearized pendulum problem):
$x_1'=x_2$
$x_2'=-frac{g}{L}*sin(x_1)$
with the following initial condition:
$x_1(t_0)=0$
$x_2(t_0)=0$
Improved Euler Method says that:
$Y_{k+1}=Y_k+frac{h}{2}*[f(t_k, Y_k)+f(t_{k+1}, Y_k+h*f(t_k, Y_k))]$
In this case I have done the following:
$x_{1, k+1}=x_{1, k}+frac{h}{2}*[x_{1, k}+(x_{1, k}+h*x_{1, k})]$
$x_{2, k+1}=x_{2, k}+frac{h}{2}*[-frac{g}{L}*sin(x_{1, k})+-frac{g}{L}*sin(x_{1, k}+h*(-frac{g}{L}*sin(x_{1, k}))))]$
Where is my mistake?
numerical-methods
$endgroup$
I have the following problem (linearized pendulum problem):
$x_1'=x_2$
$x_2'=-frac{g}{L}*sin(x_1)$
with the following initial condition:
$x_1(t_0)=0$
$x_2(t_0)=0$
Improved Euler Method says that:
$Y_{k+1}=Y_k+frac{h}{2}*[f(t_k, Y_k)+f(t_{k+1}, Y_k+h*f(t_k, Y_k))]$
In this case I have done the following:
$x_{1, k+1}=x_{1, k}+frac{h}{2}*[x_{1, k}+(x_{1, k}+h*x_{1, k})]$
$x_{2, k+1}=x_{2, k}+frac{h}{2}*[-frac{g}{L}*sin(x_{1, k})+-frac{g}{L}*sin(x_{1, k}+h*(-frac{g}{L}*sin(x_{1, k}))))]$
Where is my mistake?
numerical-methods
numerical-methods
asked Jan 12 at 11:33
user2235427user2235427
1083
1083
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27
add a comment |
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips
The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference

$endgroup$
add a comment |
$begingroup$
You have to use the correct right side for the increments of the variables. If
$$
x_1'=f(x_2)\
x_2'=g(x_1)
$$
then the method step reads
$$
x_{1,k+1}=x_{1,k}+frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\
x_{2,k+1}=x_{2,k}+frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\
$$
To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods,
begin{align}
Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\
Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\[2em]hline
x_{1,k+1}&=x_{1,k}+frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+frac{Δ_1x_2+Δ_2x_2}2.
end{align}
$endgroup$
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%2f3070811%2fhow-to-apply-improved-euler-method-to-a-systems-of-differential-equation%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
$begingroup$
One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips
The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference

$endgroup$
add a comment |
$begingroup$
One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips
The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference

$endgroup$
add a comment |
$begingroup$
One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips
The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference

$endgroup$
One of the most common problems in numerical integration is the time step. Make sure it is small enough so the system does not explode. Beyond that here are a couple of tips
The system has a fixed point at $(x_1, x_2) = 0$. That means that if your initial condition starts there, the system will not move
Define a function that takes
x(array) and returnsdx(array) withdx[1] = x[2]anddx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debugHere's a solution using $h = 0.01$ in python, just for reference

answered Jan 12 at 12:18
caveraccaverac
14.8k31130
14.8k31130
add a comment |
add a comment |
$begingroup$
You have to use the correct right side for the increments of the variables. If
$$
x_1'=f(x_2)\
x_2'=g(x_1)
$$
then the method step reads
$$
x_{1,k+1}=x_{1,k}+frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\
x_{2,k+1}=x_{2,k}+frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\
$$
To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods,
begin{align}
Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\
Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\[2em]hline
x_{1,k+1}&=x_{1,k}+frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+frac{Δ_1x_2+Δ_2x_2}2.
end{align}
$endgroup$
add a comment |
$begingroup$
You have to use the correct right side for the increments of the variables. If
$$
x_1'=f(x_2)\
x_2'=g(x_1)
$$
then the method step reads
$$
x_{1,k+1}=x_{1,k}+frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\
x_{2,k+1}=x_{2,k}+frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\
$$
To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods,
begin{align}
Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\
Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\[2em]hline
x_{1,k+1}&=x_{1,k}+frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+frac{Δ_1x_2+Δ_2x_2}2.
end{align}
$endgroup$
add a comment |
$begingroup$
You have to use the correct right side for the increments of the variables. If
$$
x_1'=f(x_2)\
x_2'=g(x_1)
$$
then the method step reads
$$
x_{1,k+1}=x_{1,k}+frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\
x_{2,k+1}=x_{2,k}+frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\
$$
To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods,
begin{align}
Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\
Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\[2em]hline
x_{1,k+1}&=x_{1,k}+frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+frac{Δ_1x_2+Δ_2x_2}2.
end{align}
$endgroup$
You have to use the correct right side for the increments of the variables. If
$$
x_1'=f(x_2)\
x_2'=g(x_1)
$$
then the method step reads
$$
x_{1,k+1}=x_{1,k}+frac h2[f(x_{2,k})+f(x_{2,k}+hg(x_{1,k}))]\
x_{2,k+1}=x_{2,k}+frac h2[g(x_{1,k})+g(x_{1,k}+hf(x_{1,k}))]\
$$
To keep track of these mixings you can either use a vector-based code or compute the steps like in the standard formulation of Runge-Kutta methods,
begin{align}
Δ_1x_1 &= f(x_{2,k})Δt,& Δ_1x_2 &= g(x_{1,k})Δt,\
Δ_2x_1 &= f(x_{2,k}+Δ_1x_2)Δt,& Δ_2x_2 &= g(x_{1,k}+Δ_1x_1)Δt,\[2em]hline
x_{1,k+1}&=x_{1,k}+frac{Δ_1x_1+Δ_2x_1}2,&x_{2,k+1}&=x_{2,k}+frac{Δ_1x_2+Δ_2x_2}2.
end{align}
answered Jan 12 at 15:25
LutzLLutzL
59.6k42057
59.6k42057
add a comment |
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%2f3070811%2fhow-to-apply-improved-euler-method-to-a-systems-of-differential-equation%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
$begingroup$
Why do you think there's a mistake?
$endgroup$
– caverac
Jan 12 at 11:35
$begingroup$
@caverac: I've been using it in a MATLAB code and it differs very much from the exact solution. That's why I have supposed that the method I've written is mistaken.
$endgroup$
– user2235427
Jan 12 at 11:39
$begingroup$
How could you notice a difference? It should be all zero with these initial values.
$endgroup$
– LutzL
Jan 12 at 15:27