added relative error output
added malloc for array allocation