Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Programming Euler's Method into Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82167] Programming Euler's Method into Mathematica
  • From: Tara.Ann.Lorenz at gmail.com
  • Date: Sat, 13 Oct 2007 04:03:15 -0400 (EDT)

I am trying to use Euler's Update Method to Numerically Integrate a
Function (I know how to use NDSolve for this case, but I want to
demonstrate an approximation method as well).  For those familiar with
neuroscience, I am trying to model the Hodgkin Huxley Equations.  I
have four ordinary differential equations (ODE) that I have written in
discrete form  using Euler's Method.  I am trying to solve for one of
these discrete equations, V, which is a function of the other three
differential equations (n, m, and h). All four equations are also a
function of time. Essentially, the command for NDSolve for this case
is in the following form: NDSolve[{ODE1, ODE2, ODE3, ODE4,
V[0]==0,n[0]==1, m[0]==2, h[0]==3},{V,n,m,h},{t,0,50},MaxSteps->1000]

Instead of the above ODE input, I want to use Euler's Method. (i.e. V(t
+delta_t)=V(t)+delta_t("stuff").  Now, the code below works for a
function of x and y. MY QUESTION IS: how would I change this code to
apply to my situation in which I want to solve for V[t] but it is a
function of n[t], m[t], and h[t].

I would appreciate any hints/clues/suggested programs.  I know that
Mathematica has a built-in "Explicit Euler" Method, but I would like
to develop the program myself. I believe I am making a small mistake
that is preventing my success.

Thank you,
Tara

The following program code works for a function f(x,y):
euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:=

Block[{	xold=x0,
        yold=y0,
        sollist={{x0,y0}},
        x,y,h
      },

      h=N[(xn-x0)/steps];

      Do[ xnew=xold+h;
          ynew=yold+h*(f/.{x->xold,y->yold});
          sollist=Append[sollist,{xnew,ynew}];
          xold=xnew;
          yold=ynew,
          {steps}
      ];

      Return[sollist]



  • Prev by Date: RE: Quantum Algebra
  • Next by Date: Re: HELP: How to do count to the SUB-LIST
  • Previous by thread: Lynch "Dynamical Systems...Using Mathematica" available
  • Next by thread: Re: Programming Euler's Method into Mathematica