Quantum control for arbitrary linear and quadratic potentials