A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Imaginary and complex numbers

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    19

    Imaginary and complex numbers

    Hello,

    I am quite new to Flash and Actionscript. I was wondering if there is any way to use imaginary numbers in flash. How would I assign the value of sqrt(-1) to a variable? Also is it possible to perform complex number calculations in Flash?

    Thank you.

  2. #2
    Member
    Join Date
    Oct 2006
    Location
    Australia
    Posts
    56
    Hey, you can do some pretty complex number calculations in flash...
    Im not quite sure what you mean by imaginary numbers but you can assign almost anything to a variable

    myVar = Math.sqrt(100);

    trace (myVar)

    it wont allow you to use -1 as nothing squared can = -1 ;P
    Im not sure how new you are so all this means is
    myVar = Math.sqrt(100);
    this creates a variable called myVar and sets it value to the square root of 100

    trace (myVar)
    this just tells you what the value of myVar is... kinda like echo or print used in other languages.

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    6
    In math sqrt(-1) = i. so sqrt(-100) = 10i.

    but no, you can't sqrt(-1) just returns NaN (not a number).

    I'm not sure of what 'complex' numbers calculations are.

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    He's basically wondering if you can do math with imaginary numbers. Looking through the Math class, (go to the built-in flash help) all of the functions didn't involve an imaginary number. I very much doubt flash can do imaginary calculations. Except for a calculator I don't see what you want it for, care to indulge me?
    .

  5. #5
    Junior Member
    Join Date
    Mar 2007
    Posts
    19
    Thanks to everyone for replying!

    I am actually building an application to introduce acoustics to younger children. Thus, I am building a model of a simple trumpet and the calculations used to build the model involves imaginary numbers. None of the built-in functions of Flash supports imaginary numbers.

    DeMarHc

  6. #6
    Senior Member
    Join Date
    Mar 2000
    Posts
    472
    Hey DeMarHc!

    I have some information on your query ... checkout my dated-but-still-relevant AS2 Library for the class com.wis math.alg.Complex.as to explore a multitude of complex number methods.

    Examples that utilize the application of complex numbers:

    Complex Number Calculator
    Cubic Polynomial Equation - Cardan
    Quartic Polynomial Equation - Cardan

    Lifaros created an example tool to explore the various wave transforms Fourier Wave Generator

    Fourier Transform ... my class com/wis/math/calc/Fourier.as is a port of Paul Bourke's C implementation for discrete (dft) and fast (fft & fft2d) Fourier transforms that support digital signal processing applications. It's a bit hard to follow the code, but it's worth the effort to study these algorithms. They populate their own local complex objects as holders for signal transformation so you are able to follow the progression of the logic ... I plan to eventually refactor the Fourier class to extend the Complex class.

    Complex Numbers from wikipedia provides definition and summaries for the application of complex numbers in control theory, signal analysis, improper integrals, quantum mechanics, relativity, applied mathematics, fluid dynamics, and fractals.

    Richard

  7. #7
    Junior Member
    Join Date
    Mar 2007
    Posts
    19

    Thank you!

    Hi Richard!

    Thank you soooo much! You are a life saver! This is going to help me lots! Thank you!!

    DeMarHc

  8. #8
    Senior Member
    Join Date
    Mar 2000
    Posts
    472
    Ooops! I meant to include source links for the 3 examples above, but forgot to edit before posting.

    Complex Number Calculator: Source
    Cubic Polynomial Equation - Cardan: Source
    Quartic Polynomial Equation - Cardan: Source

  9. #9
    Senior Member
    Join Date
    Mar 2000
    Posts
    472
    Admin: I suggest you extend edit time a bit please.

    DeMarHc:

    I'll walk you through the 4 step 'i' cycle ... open the calculator:

    Press C to clear memory ...
    The left field is the real part and the right field is the imaginary part of the complex number input ...
    Each cycle's input should be 0 for the real and 1 for the imaginary, which represents the complex object 'i' ...

    0. Input/Enter ... = i
    1. Input/*/Enter ... i * i = -1
    2. Input/*/Enter ... -1 * i = -i
    3. Input/*/Enter ... -i * i = 1
    4. Input/*/Enter ... 1 * i = i
    ... ad infinitum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center