imaginary numbers

This is a discussion on imaginary numbers within the C++ Programming forums, part of the General Programming Boards category; what kind of variable would you use to represent these?...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    57

    imaginary numbers

    what kind of variable would you use to represent these?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    an imaginary one?

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    is there a type of variable you could use to represent them? i dont really know a lot about imaginary numbers and i need to use them in a program i have to write

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    not that i can remember, but what is stopping you from creating your own class to represent imaginary numbers?
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    ok you got me.......i feel like an idiot but what exactly is an imaginary number?

  6. #6
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    std::complex maybe?

    For imaginary numbers only i suppose you could set the real part to zero. Ive only used i as part of a complex number never alone.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I think the proper way to think about it is that an imaginary number is a complex number that isn't a real number, so it is always a complex number, regardless if the real part of it is zero or not.

    ...edit...

    maybe not, the FAQ above explains:

    "Imaginary numbers are numbers that can be written as a real number times i."

    "Complex numbers are numbers like 7 + .4i; they're a real number plus an imaginary number."

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    ok i get what imaginary numbers are now. i have to write a program that solves the quadratic formula and i need to include imaginary numbers in the program......what do these numbers have to do with solving the quadratic formula?

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Think of this. The square root of a negative number has to be imaginary. So
    y=4a+3b+4 would be written.
    Code:
    (-3(+/-)(sqrt((squared(3))-(4*4*4))))/(4*2)
    
    assume #define squared(x) x*x
    Use what you learned in those tutorials to figure out how you would evaluate the problem above.
    Last edited by Extol; 04-17-2003 at 04:24 PM.

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2
    The quadratic formula will tell you the two roots of the equation. For example, for the quadratic y = x^2 - 1, the graph would intersect the x-axis at -1 and 1. These are the roots. If the graph were y = x^2 + 1 on the other hand, there would be no real roots because the graph of the quadratic doesn't intersect the x-axis. In this case you would have two imaginary roots, -i and i. We get this from the quadratic formula:

    -b +/- sqrt( b^2 -4(a)(c)) / 2a
    =
    +/- sqrt(-4) / 2 = +/- 2i / 2 = +/- i
    (remember i is the sqrt(-1))

    I'm a beginner at programming myself, so I don't know which header it is that has support for complex numbers, but this is why you would need them.

    Extol: remember that in your example, 4, 3, and 4 are equal to a, b, and c. I believe you want x's where you have your a and b

  13. #13
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    so to declare an imaginary number......i could just do this right?

    double i = sqrt(-1);

  14. #14
    Registered User
    Join Date
    Sep 2002
    Posts
    70
    Oh gosh. Yea, isn't it 4x^2+3x+4 even. I don't remember.

  15. #15
    Registered User
    Join Date
    Feb 2003
    Posts
    57
    alright i think i actually need to use complex numbers......is therea way to declare these?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Absolute value of imaginary numbers?
    By cpjust in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 08-11-2008, 06:52 PM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 06:20 AM
  3. Real and Imaginary numbers
    By tetra in forum C++ Programming
    Replies: 13
    Last Post: 02-03-2003, 11:49 AM
  4. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21