where z_1 and z_2 are the real and imaginary parts, respectively. For a "complex" number in n dimensions (e.g. quaternion, octonion, etc.) the magnitude works in a similar way:
You'll have to provide how to minimize/maximize z, because I need to know what context or parameters you are referring to.