Evaluating a formular with the imaginary number 'i'

Hi C++ coders

I am trying to access the Complex <> class from the C++ standard Library and struggling to evaluate a formula which contains the imaginary number 'i'.

The formula I'm trying to evaluate is

g = (b-p*h*i+d)/(b-p*h*i-d)

where b,p,h and d are all known constants.

How do I access the complex library, create a complex class and then initialise i as imaginary to be used in the above?
1
2
3
4
5
6
7
8
9
10
11
#include <complex>
#include <iostream>

int main(){
    double b = 5, p = 2, h = 1, d = 7;
    std::complex<double> i(0, 1);
    std::complex<double> g = (b-p*h*i+d)/(b-p*h*i-d);
    std::cout << g;
    std::cin.get();
    return 0;
};
Thanks Hamsterdam!

I had something similiar but didn't realise g was complex too. makes sense.
Topic archived. No new replies allowed.