Complex Numbers: better implementation

I've already created a Complex class, with all the mathematical methods necessary. But I've seen at the Internet several attempts to do such classes, and one preferred to make a compiler that accepts complex as a primitive type. And he's right. Creating a class to represent the complex numbers takes too much memory and time only to store two doubles. Using C/C++, complex numbers could be made with structs, and a Complex class would be used to implement the necessary methods, wrapping the complex type, like Double wraps a double.
So, I'd like to suggest a new type of class. This class would act like
an C/C++ struct, being able to store only fields and constructors. I believe that this way would make it waste less memory, and enable faster use of this class. It would work like this:
public value class complex {
  public double real;
  public double imag;
public class Complex {
  public static final complex I;
  I.real = 0; I.imag = 1;
}What do you guys think?

Creating a class to represent the complex
numbers takes too much memory and time only to store two doubles.If the only fields in the Complex object are two doubles, how much more memory does a Complex object take up? The methods would only appear in the Class object, not each Complex instance. Right?
I guess you have one reference on the stack and two doubles on the heap, as opposed to two doubles on the stack and nothing in the heap.
So, I'd like to suggest a new type of class. This
class would act like an C/C++ struct, being able to store only
fields and constructors. I believe that this way would
make it waste less memory, and enable faster use of this class.At this point I wonder whether there'd really be a big memory savings, and whether it would be worth watering down the OOP-ness of the language.
Defining a complex primitive is another issue.
Issues like ordering and equality would seem to make the problem really...complex... Perhaps any choice for those issues would only satisfy a third of the interested parties, and any design would satisfy no one.

Similar Messages

  • How do I write complex numbers to an excel or text spreadsheet file.

    I am performing an FFT on 3 channels of simultaneous analog input. I want to write the resultant 3 complex numbered arrays to a spreadsheet. Do I have to seperate the a and b*i components into r and theta and write two columns per array or is there a better way?

    Perhaps you can write it as a String..?
    Khalid

  • SVD with complex numbers

    I'm working on creating a SVD class using complex numbers. I have an adaptation of the Jama ( http://math.nist.gov/javanumerics/jama/ ) implementation coded which works great with complex numbers with only a real part, but fails when the imaginary is present. I also coded up a port of numerical recipes' ( http://www.nr.com ) implementation, but am unable to get it to converge. I'm 99.9% sure that the problem does not exist in my complex number class as it has worked fine up until now.
    Anyhow, what I'm wondering is if anyone has a Java SVD for complex matrices that I could look at and/or use?
    Thanks in advance,
    m

    It wasn't working when I tried it a few months ago. I found the bug in the database - it's been long-standing. Given that Sun doesn't appear to be supporting Java3D very well, I doubt it'll ever be fixed.
    Besides, that SVD algorithm is only for real matricies, I believe. - MOD

  • How to use RLS with complex numbers as the input?

    I import a file which have complex numbers, and I want to filter it using complex RLS adaptive filter, but it always freeze at the filtering and update then it returns one value in the matrix and all the other numbers are NaN, so how can I fix this.
    The second thing is when I use FBLMS, it always return error 42020 unless I specify the filter length= number of the input which is huge number, so how do I specify normal filter length.

    Hi engomar,
    There is a detailed description of how to choose filter length in the Adaptive Filter Tollkit Help file. 
    http://zone.ni.com/reference/en-XX/help/372357B-01/lvaftconcepts/aft_choose_filterlength/
    This page has several links to other important factors of what filter to choose. Under Computational Resource Requirements, it lists the memory usage for different filter types. RLS is the most memory intensive, which could be causing the freeze. Maybe try a LMS to see if this helps.
    Robert R. | Applications Engineer | National Instruments

  • In range and coerce with complex numbers?

    I have an array of complex numbers with these numbers I need to set to 0 all numbers whose real parts are negative. With "in range and coerce" I can split the array into real and imaginary then set all negative numbers to 0 then recombine the complex part but that still leaves me with 0+ai numbers that should be 0. How can I also set the complex part to zero for the negative numbers?

    Hello,
    You can use the following fonction in a for loop with your array.
    Michel

  • How can I insert reference to cell on a different sheet in Numbers beta?

    In Excel or Numbers for iPad, I start typing in a cell, switch to another sheet and click a cell or range, hit enter, and I'm back on the original sheet with the cell reference inserted.  I saw documentation that it works the same way in Numbers Beta on Mac, but it doesn't.  When I leave the sheet, I'm not editing the cell anymore.
    Very frustrating.   This function is often necessary, and long formulas are tedious on iPad.  So far the most reliable method is to export back to Excel, make the change, and re-export to iCloud.

    I struggled with this same issue until this week.  You have to actually type references in cell.  And spacing is the key to making it work.  Make sure to put a space before and after each double colon.
    =SheetName :: B3
    =08 20 14 :: B3
    I you are linking to a different table in a sheet, you have to include the table name also.
    =08 20 14 :: No Shows :: D5

  • Using complex numbers in Fletcher Reeves optimization method

    Hello,
    I would like to minimize a function of 4 complex variables with the Fletcher Reeves optimization method (Conjugate Gradient VI).
    Is it possible to do it with this VI or with HiQ4.5 ?
    (for S-parameters specialists) The purpose is to de-embed using optimization method.
    Thanks,
    Dze

    I believe that the "Conjugate Gradient nD.vi" and the optimize function in HiQ only work with real vectors. Most of the solve functions in HiQ work with complex numbers, and you may be able to create your own algorithm for the purpose, but I don't think that there is already a function that will do quite what you want.

  • Hp 35s integrating with complex numbers/functions

    Are there any examples of how to integrate a complex function for
    the HP 35s..the manual suggests its possible..but, I can not find one
    example...anywhere... I am just interested in testing.....I do
    not want to break things into parts etc...I just want to try
    e^z for example, where z is complex..any help?
    I have tried xiy, rTheta, x+iy...syntax errors or non existent..funny

    Hi,
    The manual states that complex numbers can be used with EXP(x), but it does not mention anything about using complex numbers for integration. Edit: I missed some text in the manual, see below.
    As far as I can tell it cannot do integration with complex numbers. (The 50g can do this.)
    However, you may get a more definitive answer if you ask your question here:
    http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi
    EDIT: that forum has moved to a new version:
    http://www.hpmuseum.org/forum/forum-4.html
    Note: I do not work for HP, I just like playing with calculators :-)

  • Complex Numbers problem

    I am having problems getting this Complex Numbers program to work correctly. i want to display using format a+bi the addition, subtraction and multiplication of 2 complex numbers.Can anyone reply today?
    class Complex
         private double realPart, imaginaryPart;
         public Complex()
              realPart = 0.0;
              imaginaryPart = 0.0;
         public static void main(String [] args)
              Complex c;
              double res;
              c = new Complex();
              Screen.message("-------------------MENU----------------------------");
              Screen.newline(2);
              Screen.message("Please enter a number: ");
              Keyboard.readDouble();
              res = c.get_realPart();
              Screen.newline();
              Screen.message("Please enter a second number: ");
              Keyboard.readDouble();
              res = c.get_imaginaryPart();
              Screen.newline(2);
              Screen.message("--------------------------------------------------");
              Screen.newline();
              Screen.message("     Designed by Niall Magner               ");
              Screen.newline();
              Screen.message("--------------------------------------------------");
              Screen.newline(2);
              Screen.writedouble(res);
              Screen.newline();
              Screen.writedouble(res);
              Screen.newline();
              Screen.writedouble(res);
              Screen.newline(2);
         public double get_realPart()
              return realPart;     
         public double get_imaginaryPart()
              return imaginaryPart;
         public void addComplexNum(Complex n1, Complex n2)
              realPart = n1.get_realPart() + n2.get_realPart();
              imaginaryPart = n1.get_imaginaryPart() + n2.get_imaginaryPart();
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
              Screen.message("Number 1 is: " + realPart);
              Screen.message(" + " + imaginaryPart + "i");
              Screen.newline();          
              Screen.message("Number 2 is: " + realPart);
              Screen.message(" + " + imaginaryPart + "i");
              Screen.newline();          
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
         public void subtractComplexNum(Complex n1, Complex n2)
              realPart = n1.get_realPart() - n2.get_realPart();
              imaginaryPart = n1.get_imaginaryPart() - n2.get_imaginaryPart();
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
              Screen.message("Number 1 is: " + realPart);
              Screen.message(" - " + imaginaryPart + "i");
              Screen.newline();
              Screen.message("Number 2 is: " + realPart);
              Screen.message(" - " + imaginaryPart + "i");
              Screen.newline();          
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
         public void multiplyComplexNum(Complex n1, Complex n2)
              realPart = n1.get_realPart() * n2.get_realPart();
              imaginaryPart = n1.get_imaginaryPart() * n2.get_imaginaryPart();
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
              Screen.message("Number 1 is: " + realPart);
              Screen.message(" * " + imaginaryPart + "i");
              Screen.newline();          
              Screen.message("Number 2 is: " + realPart);
              Screen.message(" * " + imaginaryPart + "i");
              Screen.newline();
              Screen.message("-----------------------------------------------");
              Screen.newline(2);
    Any help greatly appreciated.
    Niall Magner

    There are several problems with this code. You never call the add method, so the numbers are never going to be added. You never load up a complex number to add either.
    Try doing something a bit more like this:
      read a float from the keyboard
      read another float from the keyboard
      Create a complex number from this float
      Complex complex1 = new Complex();
      complex1.realPart = first number from above;
      complex1.imaginaryPart = second number from above;
      do this again to get the second complex number
      then add the numbers together
      Complex complexSum = new Complex
      complexSum.addComplexNum(complex1, complex2)
      print complexSum.realPart + "+i" + complexSum.imaginaryPart;
      then do the other operations you wantI would also advise that you take a course in Java Programming, cos the code you have posted is truely awful.

  • Copy style in numbers Beta

    How do I copy style in numbers Beta and paste

    bjgall35 wrote:
    I am working on a numbers CHECKING REGISTER document. The style of the print and the figures has always been clear and easy to read. Unfortunately the style has changed. It is not as easy to read and is out of character with the rest of the document. I am not sure what I have done to cause this. Can someone please help with some advice.
    Difficult to say without at least a few details as to what "the style of the print and figures...has changed." A screen shot would be useful. Take the screen shot by pressing shift-command-4, then dragging a rectangle to select the part of the screen to include. This will place a file containing the picture on your Desktop.
    Post screen shots by uploading them to a photo-sharing website such as Picasa, Photobucket or Flickr, then copying the HTML code provided by the website for sharing your photo and pasting that in your post here.
    Regards,
    Barry

  • Need help with complex numbers ..

    Hi!
    Just want to check if i got it right - if anyone could pls confirm:
    public void divComplex(Complex a, Complex b)
    x = ((a.x * b.x) + (a.y * b.y))/((b.x * b.x) + (b.y * b.y));
    y = ((a.y * b.x) + (a.x * b.x))/((b.x * b.x) + (b.y * b.y));
    public void multComplex(Complex a, Complex b)
    x = ((a.x * b.x) - (a.y * b.y));
    y = ((a.x * b.y) + (a.y * b.x));
    where:
    protected double x;
    protected double y;
    is declared to represent the complex number .
    Is this correct?
    Siw

    For the division you have,
    a/b = a*b'/b*b' = a*b'/|b|
    |b| = (b.x + ib.y)*(b.x - ib.y) = b.x*b.x + b.y*b.y
    a*b' = (a.x + ia.y)*(b.x - ib.y) =
    (a.x*b.x + a.y*b.y) + i(a.y*b.x - a.x*b.y)
    There seems to be a slight mistake in the imaginary part (y).
    y = a.y*b.x - a.x*b.y / (b.x*b.x + b.y*b.y);
    But don't take my word for it. It's been ages since I did complex numbers -:)

  • How to convert a waveform signal into array of complex numbers

    How to convert a waveform signal into array of complex numbers.

    Hi Chaks,
    try this:
    (Get Waveform components, convert to complex DBL)
    Message Edited by GerdW on 01-28-2008 09:23 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    ToCDB.png ‏1 KB

  • HP35s complex numbers

    My background is with the HP41C,CV,CX (41). I am now attempting to emulate routines I developed for the 41 for solutions on an HP35s (35) in RPN mode. My issue is with polar to rectangular conversion on the 35. The 41 had P-R and R-P keys. The 35 does not and wants to handle the conversion as “complex numbers”.The 41 key sequence is:RENTϴ (value)P-R X appears in x (stack) registerY appears in y (stack) registerThe stack contains two discrete values, x, y The 35 sequence is:Display .0Rϴ (key)ϴ (value)ENTx and y appear as x i y in the x registerCan I segregate x and y to complete the next 41 step? The next step in the 41 routine is Σ+.That operation generates cumulative Cartesian coordinates for each subsequent entry of R, ϴ in the Σx and Σy statistic registers Can that be emulated in the 35s?

    My background is with the HP41C,CV,CX (41). I am now attempting to emulate routines I developed for the 41 for solutions on an HP35s (35) in RPN mode. My issue is with polar to rectangular conversion on the 35. The 41 had P-R and R-P keys. The 35 does not and wants to handle the conversion as “complex numbers”.The 41 key sequence is:RENTϴ (value)P-R X appears in x (stack) registerY appears in y (stack) registerThe stack contains two discrete values, x, y The 35 sequence is:Display .0Rϴ (key)ϴ (value)ENTx and y appear as x i y in the x registerCan I segregate x and y to complete the next 41 step? The next step in the 41 routine is Σ+.That operation generates cumulative Cartesian coordinates for each subsequent entry of R, ϴ in the Σx and Σy statistic registers Can that be emulated in the 35s?

  • Having trouble converting array to spreadsheet string, storing the file and coverting back to array with complex numbers

    I am working with a network analyzer. I have arrays made of 5 columns the first consisting of an integer and the next four consisting of complex numbers. I am converting the array into a spreadsheet string and then saving the file using the write characters to a file VI. That seems to work well as when I open the file in Excel all the data is there. However when I try to reverse the process, open file and convert back to array, I loose some of the data. Specifically the imaginary parts of my complex numbers are all going to zero. I have narrowed down the problem to be in the conversion from spreadsheet string to array and vice versa. I
    think the problem may be with the 'format' input to the VI. I do not have an adequate resource for this so I am not sure what to put in to accomplish my task. Any takers?

    Hi Biz
    I don't think there is a direct way of converting a complex number to a
    string, so when you convert the array to a spreadsheet string, the
    numbers would be converted to real data.
    However, you could try separating the real and imaginary parts using the
    "Numeric: Complex to Re/Im" function, and then store these - either in
    separate files or in adjacent columns/rows in the same file. Then, when
    you read in the data again, use the "Numeric: Re/Im to Complex" function
    to put the two "halves" together.
    If you actually want Excel to interpret the numbers as imaginary, then
    you'll probably want to create a string for each complex number of the
    form "Re + Im*i" (after separating the Re and Im parts), by using
    "String:Format into String" with 2 numeric inputs and the format string
    "%f+%fi".
    Reading the data back into Labview then would require splitting the
    string into the 2 pieces by using "Stringcan from String" with 2
    numeric outputs (smae precision as original numbers specified by the 2
    Default Value inputs) and the same format string "%f+%fi", and then using
    the above-mentioned "Numeric: Re/Im to Complex" function. It worked for
    me, so if you can't follow what I am describing, send me an email and I
    can email you what I did (LV 5.1.1).
    Paul
    Biz wrote:
    > Having trouble converting array to spreadsheet string, storing the
    > file and coverting back to array with complex numbers
    >
    > I am working with a network analyzer. I have arrays made of 5 columns
    > the first consisting of an integer and the next four consisting of
    > complex numbers. I am converting the array into a spreadsheet string
    > and then saving the file using the write characters to a file VI. That
    > seems to work well as when I open the file in Excel all the data is
    > there. However when I try to reverse the process, open file and
    > convert back to array, I loose some of the data. Specifically the
    > imaginary parts of my complex numbers are all going to zero. I have
    > narrowed down the problem to be in the conversion from spreadsheet
    > string to array and vice versa. I think the problem may be with the
    > 'format' input to the VI. I do not have an adequate resource for this
    > so I am not sure what to put in to accomplish my task. Any takers?
    Research Assistant
    School of Physiotherapy, Curtin University of Technology
    Selby Street, Shenton Park, Western Australia, Australia. 6008
    email: [email protected]
    Tel. +61 8 9266 4657 Fax. +61 8 9266 3699
    "Everyone who calls on the name of the Lord will be saved." Romans 10:12
    "For all have sinned and fall short of the glory of God, and are
    justified freely by his grace through the redemption that came by Christ
    Jesus." Romans 3:23-4

  • Tdms does not support complex numbers?

    I can see that I can create and manipulate complex waveforms in Labview, but when I try to save such a waveform in a TDMS file, I get a run-time error that data format is not supported, forcing me to split the complex waveform into two separate waveforms for saving.
    Also, when I send a complex waveform to a Waveform Graph indicator, it truncates the imaginary part.
    Are there any plans to add native support for complex numbers in TDMS and graphing?

    Fedor wrote:
    I can see that I can create and manipulate complex waveforms in Labview, but when I try to save such a waveform in a TDMS file, I get a run-time error that data format is not supported, forcing me to split the complex waveform into two separate waveforms for saving.
    That's correct. TDMS does not support complex values.
    Also, when I send a complex waveform to a Waveform Graph indicator, it truncates the imaginary part.
    That's also correct. Think about it. What would you plot on a waveform graph? You could use something like an XY graph, with X being the real values and Y being the imaginary values. Or, you could use a polar plot (available as a picture indicator plot).
    Are there any plans to add native support for complex numbers in TDMS and graphing?
    If you wish to make a suggestion regarding this, then you can post in the LabVIEW Idea Exchange, where people can vote on the idea. You may need to submit this as two different ideas since it's covering two different components.

Maybe you are looking for

  • Any provision to configure Custom Duty or Excise Duty in Advanced Pricing

    Hi, Any provision to configure the 'Custom Duty' or 'Excise Duty' in Advanced Pricing ? Thanks!

  • Clearing document

    HI I have a question for A/R finance module: I create an invoice in a customer account i.e 180000000 in 5200000 a/c i received payment and make a deposit(same amount as invoice) in that customer a/c...  a 1400000000 is created i clear the 18 against

  • Y530 virtualization (Intel VT) [SOLVED]

    Hi all.I've developed VT activation procedure for Lenovo Ideapad Y530. But provided that your notebook corresponds to the following requirements: - Your CPU MUST support Intel virtualization Technology otherwise you'll get nonfunctioning laptop. - CP

  • What can I do: Macbook Battery need replace at 103 cycle

    I have my Macbook late-2006 and suddenly the battery do not charge at cycle 103. I tried to talk to guys at Apple Store but the only thing they can do is to sell me a new battery. In fact, the battery was in recall before 2009 but I was not be able t

  • Slow discovery of wifi networks

    Any suggestions on how to improve the discovery speed of known wifi networks?  I usually use a wired connection but when I do use wifi it can take 10+ minutes for my routers SSID to appear in the list of available networks. Other weaker nearby networ