Skip to content

Instantly share code, notes, and snippets.

@firejox
Last active October 25, 2017 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firejox/3a26ba68cce537dce31db113e1ef38a4 to your computer and use it in GitHub Desktop.
Save firejox/3a26ba68cce537dce31db113e1ef38a4 to your computer and use it in GitHub Desktop.
midpoint method
function y = my_midpoint_method(f, y0, a, b, n)
h = (b - a) / n
y = 0:n
y(0) = y0
for i = 1:n
y(i) = y(i - 1) + h * f(a + h*(i - 1) + h*0.5, y(i - 1) + 0.5*h*f(a + h*(i - 1), y(i - 1)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment