Euler Method - Using the Method with Mathematica
Numerical Methods for Solving Differential Equations
Euler's Method
Using the Method withÌýMathematica
(continued fromÌýlast page...)
Reminder: theÌýeulerÌýprogram that we've taken so long to analyze looks like this:
euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:=
Block[{ xold=x0,
ÌýÌýÌýÌý²â´Ç±ô»å=²â0,
ÌýÌýÌýÌý²õ´Ç±ô±ô¾±²õ³Ù=µ÷µ÷³æ0,²â0°¨°¨,
ÌýÌýÌýÌý³æ,²â,³ó
ÌýÌý°¨,
ÌýÌý³ó=±·°Ú(³æ²Ô-³æ0)/²õ³Ù±ð±è²õ±Õ;
ÌýÌýDo[ xnew=xold+h;
ÌýÌýÌýÌý²â²Ô±ð·É=²â´Ç±ô»å+³ó*(´Ú/.µ÷³æ-&²µ³Ù;³æ´Ç±ô»å,²â-&²µ³Ù;²â´Ç±ô»å°¨);
ÌýÌýÌýÌý²õ´Ç±ô±ô¾±²õ³Ù=´¡±è±è±ð²Ô»å°Ú²õ´Ç±ô±ô¾±²õ³Ù,µ÷³æ²Ô±ð·É,²â²Ô±ð·É°¨±Õ;
ÌýÌýÌýÌý³æ´Ç±ô»å=³æ²Ô±ð·É;
ÌýÌýÌýÌý²â´Ç±ô»å=²â²Ô±ð·É,
ÌýÌýÌýÌý²õ³Ù±ð±è²õ
ÌýÌý±Õ;
ÌýÌý¸é±ð³Ù³Ü°ù²Ô°Ú²õ´Ç±ô±ô¾±²õ³Ù±Õ
]
CopyÌýthe program from here and then switch toÌýMathematicaÌý²¹²Ô»åÌýPasteÌýand execute it. Return here once you have done this. . .
Your output from this command should have beenÌýnothing at all!ÌýAfter all, we didn't actuallyÌýrunÌýtheÌýeulerÌýprogram, we simply toldÌýMathematicaÌýhow it works. Let's nowÌýmove onÌýand try using it.
Ìý