Khaled Saleh
Khaled Saleh

Reputation: 1

Trigonometric and hyperbolic functions for complex number in c++

iam working on my own class for complex numbers which add,subtract,multiply,divide 2 complex numbers and besides this behavior it also get Trigonometric and hyperbolic functions for complex numbers can you help me please in implementing this Trigonometric and hyperbolic functions

and this is my behaviors including sine function is this implementation is true ??

void complex::get(){

cout<<"Real part is:"<<real<<"\n"<<"Imaginary part is:"<<imag<<"\n";

} void complex::add(complex &sum ,const complex &num1,const complex &num2 ) {

sum.real=num1.real+num2.real;
sum.imag=num1.imag+num2.imag;

}

void complex::sub (complex &subt,const complex &num1,const complex &num2 ) {

subt.real=num1.real-num2.real;

subt.imag=num1.imag-num2.imag;

}

void complex::multi (complex &product,const complex &num1,const complex &num2)

{

product.real=(num1.real*num2.real)-(num1.imag*num2.imag);

product.imag=(num1.real*num2.imag)+(num1.imag*num2.real);

}

void complex::div (complex &divis,const complex &num1,const complex &num2)

{

divis.real=((num1.realnum2.real)+(num1.imagnum2.imag))/((num2.realnum2.real)+(num2.imagnum2.imag));

divis.imag=((num1.imagnum2.real)-(num1.realnum2.imag))/((num2.realnum2.real)+(num2.imagnum2.imag));

}

complex complex::_sin(void)

{ complex a; complex temp; temp.real=sin(a.real)*cosh(a.imag); temp.imag=cos(a.real)*sinh(a.imag);

return temp;

}

Upvotes: 0

Views: 1171

Answers (3)

Ben Voigt
Ben Voigt

Reputation: 283773

Since the trigonometric and hyperbolic functions are defined in terms of complex exponentiation, start by implementing Euler's identity (which produces a complex result using only real trigonometric functions).

Upvotes: 0

rubenvb
rubenvb

Reputation: 76720

This smells like homework, but in this case the Standard Library has already done the work for you in the <complex> header.

If you really want to reimplement them, see Jacob's answer, which will have the small gorey details.

Upvotes: 1

Jacob
Jacob

Reputation: 34621

This page talks about how you can easily define trig functions with the real and complex parts of your number.

This page starts with sinh and cosh (defined in terms of e so you can use the exp function for that) which allows you to define the other hyperbolic functions.

Upvotes: 3

Related Questions