working on sweeping instead of optimization
final MATLAB script without comments