This function computes the modulus of
z = a + ib and
returns the double
.
//====================================================//
// //
// modulus //
// //
//====================================================//
double modulus(const MYCOMPLEX &w)
{
double modulus = w.real*w.real + w.imaginary*w.imaginary;
return (sqrt(modulus));
}
\subsection{The Argument of a Complex Number:}
The complex number $z = a + ib$ cna be written in the
form $z = r e ^{i\theta}$, where $r$ is the modulus of $z$
and $\theta$ is the argument of $z$. We compute a particular
branch of this argument by restricting our attentions to
arguments given by the default range of the built in
function $atan2()$.
\small \begin{verbatim}
//====================================================//
// //
// arg //
// //
//====================================================//
double arg(const MYCOMPLEX &w)
{
if(w.imaginary == 0.0){
if(w.real>0.0) return(0.0);
else if (w.real < 0.0) return(PI);
else{
cout << "Arg for w = 0+0i is undefined";
cout << " returning arg = 10^6" << endl;
return(1.0e6);
}
}
else if(w.real == 0.0){
if(w.imaginary>0.0) return(.5*PI);
else if (w.imaginary < 0.0) return(1.5*PI);
else{
cout << "Arg for w = 0+0i is undefined";
cout << " returning arg = 10^6" << endl;
return(1.0e6);
}
}
else{
return(atan2(w.imaginary,w.real));
}
}