Skip to content

Instantly share code, notes, and snippets.

@tofikhidayatxyz
Created April 2, 2019 02:38
Show Gist options
  • Select an option

  • Save tofikhidayatxyz/a16c4fe9c049bfa9c01c4877e8462bdb to your computer and use it in GitHub Desktop.

Select an option

Save tofikhidayatxyz/a16c4fe9c049bfa9c01c4877e8462bdb to your computer and use it in GitHub Desktop.
function numerical_int(dx, y_array) {
var maxy = Math.max.apply(null, y_array);
var dy_array = y_array.map(function(num) {
return Math.abs(maxy - num);
});
var profile_integral = 0;
var n = dy_array.length;
for (i = 1; i < n; i++) {
var dy_init = dy_array[i - 1];
var dy_end = dy_array[i];
var darea = dx * (dy_init + dy_end) / 2.;
profile_integral = profile_integral + darea;
}
return profile_integral;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment