A General Method for Local Sensitivity Analysis With Application to Regression Models and Other Optimization Problems