Skip to content

Instantly share code, notes, and snippets.

@internetsadboy
Created May 1, 2014 05:09
Show Gist options
  • Select an option

  • Save internetsadboy/9e82cc0ab11dbc8810f2 to your computer and use it in GitHub Desktop.

Select an option

Save internetsadboy/9e82cc0ab11dbc8810f2 to your computer and use it in GitHub Desktop.
// Euler's Method
// http://en.wikipedia.org/wiki/Euler_method
// user input: n, d, x, and poly
// poly: dx/dt == f(t,x)
// n: # of steps
// d: domain a <= t <= b
// x: initial value
// h: step size
// t: the delta of current steps taken
var n = 4
var d = [0,2];
var x = 0.5;
var h = (d[0]+d[1])/n;
var t = 0;
function poly(x,t) {
return x - Math.pow(t,2) + 1;
}
function EulersMethod() {
for(var k = 0; k < n; k++) {
t = k*h;
x = h*poly(x,t)+x;
}
return x;
}
EulersMethod(); // 4.4375
@internetsadboy
Copy link
Copy Markdown
Author

Numerical Analysis -- pg 266, 267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment