开发者

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=(nu开发者_如何学Pythonm1.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;

}


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜