How to apply improved Euler method to a systems of differential equation?












0












$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?










share|cite|improve this question









$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
















0












$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?










share|cite|improve this question









$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














0












0








0


1



$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?










share|cite|improve this question









$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






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










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


















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










2 Answers
2






active

oldest

votes


















1












$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




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


  2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug


  3. Here's a solution using $h = 0.01$ in python, just for reference



enter image description here






share|cite|improve this answer









$endgroup$





















    0












    $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}






    share|cite|improve this answer









    $endgroup$













      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%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









      1












      $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




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


      2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug


      3. Here's a solution using $h = 0.01$ in python, just for reference



      enter image description here






      share|cite|improve this answer









      $endgroup$


















        1












        $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




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


        2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug


        3. Here's a solution using $h = 0.01$ in python, just for reference



        enter image description here






        share|cite|improve this answer









        $endgroup$
















          1












          1








          1





          $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




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


          2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug


          3. Here's a solution using $h = 0.01$ in python, just for reference



          enter image description here






          share|cite|improve this answer









          $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




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


          2. Define a function that takes x (array) and returns dx (array) with dx[1] = x[2] and dx[2] = - g * sin(x[1]) / l. This way is simpler to evaluate the system, and your code is easier to debug


          3. Here's a solution using $h = 0.01$ in python, just for reference



          enter image description here







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Jan 12 at 12:18









          caveraccaverac

          14.8k31130




          14.8k31130























              0












              $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}






              share|cite|improve this answer









              $endgroup$


















                0












                $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}






                share|cite|improve this answer









                $endgroup$
















                  0












                  0








                  0





                  $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}






                  share|cite|improve this answer









                  $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}







                  share|cite|improve this answer












                  share|cite|improve this answer



                  share|cite|improve this answer










                  answered Jan 12 at 15:25









                  LutzLLutzL

                  59.6k42057




                  59.6k42057






























                      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%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





















































                      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

                      Questions related to Moebius Transform of Characteristic Function of the Primes

                      List of scandals in India

                      Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?