Hi!

I am new to this, and new to the programming. To be honest, it's not easy.

I am having this problem with doing Complex numbers. Basically, I have to write a program to show the Amplitude and Phase of a Complex object. First, because Amplitudes are usually absolute values, how do you write a absolute value equation in C++.net? Also, how do you show the phase?

Also, if anyone out there is a college student, or was a college student, maybe there is a better way to absorb this material. I read the book, but it tends to be too technical to understand. Anyone got any suggestions?

From what I've read on Wikipedia, it looks like you want the magnitude and the argument of a complex number. Suppose the real part is stored in re and the imaginary part is stored in im (both doubles, presumably). Then

``double amplitude = sqrt( re * re + im …``

## All 3 Replies

From what I've read on Wikipedia, it looks like you want the magnitude and the argument of a complex number. Suppose the real part is stored in re and the imaginary part is stored in im (both doubles, presumably). Then

``````double amplitude = sqrt( re * re + im * im);
double phase = atan2( re, im);``````

Amplitude is the absolute value in the sense that it is the distance of the complex number from the origin.

What book is this?

If you are coding in c++, The standard library provides a template class for complex numbers.

``````#include <complex>

...

complex<double> z1( 2.7, 3.4);

double phase=arg(z1);
double magnitude=abs(z1);``````

Amplitude is the absolute value in the sense that it is the distance of the complex number from the origin.

What book is this?

The book we are using in class is called Visual C++.net by DEITEL. I think the book is ok, but it is hard to understand, maybe considering that I am not a programmer. Thanks for the assistance!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.