Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Complex numbers <-> Real Numbers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 jasonf   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 April 2000 - 10:03 AM

Anyone know how to implement complex numbers in c and then change them back into real numbers when needed?

Sponsor:

#2 NickGA   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 April 2000 - 10:40 AM

Hmmm... converting complex to real... well I think I understand what you mean... here''s my 2 cents
------------------------------------------
say you had a complex number c = a + bi
you can find the magnitude
/c/ = sqrt(a^2 + b^2)
and the angle
angle = atan2(b,a)
------------------------------------------
or from angle and /c/ (the other way around)
c = /c/*cos(angle) + /c/*sin(angle)i
--------------------------------------------
one way to implement a complex number in C would be
to define a structure
typedef complexnumber
{
int a; // real part
int b; // imaginary part
} complexnumber, *complexnumber_ptr;

complexnumber myfirstcomplexno;

myfirstcomplexno.a = 10;
myfirstcomplexno.b = 3;
---------------------------------------
so the number would be c = a + bi = 10 + 3i
and write functions to convert and perform operations

Hope this helps,

Nick

"... you act as if stupidity were a virtue."
-- Flight of the Phoenix

#3 ga   Members   -  Reputation: 126

Like
Likes
Like

Posted 30 April 2000 - 10:41 AM

NickGA, ints are no good idea for a and b; they should be real.

typedef complexnumber
{
float a; // real part
float b; // imaginary part
} complexnumber, *complexnumber_ptr;

btw, ln(a+bi) = sqrt(a^2+b^2) + i*arctan(b/a)
logc+di(a+bi) = ln(a+bi)/ln(c+di)
e^(a+bi) = e^a*(cos(b) + i*sin(b))
(c+di)^(a+bi) = e^(ln(c+di)*(a+bi))
sin(a+bi) = sin(a)cosh(b) + i*cos(a)sinh(b)
cos(a+bi) = cos(a)cosh(b) - i*sin(a)sinh(b)
....
all those functions are defined in the complex numbers, but I don''t think you''ll need them *g*

Visit our homepage: www.rarebyte.de.st

GA




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS