function [y_ext, x_ext] = extrema(y, x) y_switch = switchsign( deriv(y, x) ); y_ext = nonzeros(y_switch .* y); x_ext = nonzeros(y_switch .* x); end