]> gitweb.michael.orlitzky.com - octave.git/blobdiff - forward_euler1.m
Add the forward_euler1 function and a test for it.
[octave.git] / forward_euler1.m
diff --git a/forward_euler1.m b/forward_euler1.m
new file mode 100644 (file)
index 0000000..3e1061d
--- /dev/null
@@ -0,0 +1,20 @@
+function y = forward_euler1(x0, y0, f, h)
+  ## Compute one iteration of the forward Euler method.
+  ##
+  ## INPUT:
+  ##
+  ##   * ``x0`` - The initial x-coordinate.
+  ##
+  ##   * ``y0`` - The initial value y(x0).
+  ##
+  ##   * ``f`` - The function y' = f(x,y) of two variables.
+  ##
+  ##   * ``h`` - The step size.
+  ##
+  ## OUTPUT:
+  ##
+  ## The approximate value of y(x) at x = x0+h.
+  ##
+  y_prime = f(x0,y0);
+  y = y0 +  h * y_prime;
+end