Complex numbers <-> Real Numbers
Anyone know how to implement complex numbers in c and then change them back into real numbers when needed?
Jason FeserCode Geek / Visuals Guyelasticmediaproductionshttp://www.elasticvisuals.com
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
------------------------------------------
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
"If you build it, it will crash."
NickGA, ints are no good idea for a and b; they should be real.
btw, ln(a+bi) = sqrt(a^2+b^2) + i*arctan(b/a)
log
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
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)
log
c+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
Visit our homepage: www.rarebyte.de.stGA
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement