-2

how to normalize the complex numbers in c#?when i have saved the text file of complex number in notepad.then i want to use these complex numbers in my c# code.And can be read text file of complex number in c#?

Current code used:

  using (TextReader reader = File.OpenText("a.txt"))
  { 
      var lineCount1 = File.ReadLines("a.txt").Count(); 
      x1 = new double[lineCount1, 512]; 
      for (int i = 0; i < lineCount1; i++) 
      {
         for (int j = 0; j < 512; j++) 
             { 
              string line = reader.ReadLine(); 
              string[] bits = line.Split(' '); 
              x1[i, j] = double.Parse(bits[j]);
              }
       }
    }

its not working.!!! error in last line.

HEKTO
  • 3,876
  • 2
  • 24
  • 45
Ara
  • 11
  • 2

1 Answers1

0

Perhaps you should have something like this:

    static void Main(string[] args)
    {
        var lines = File.ReadAllLines("a.txt");
        var complexes = new Complex[lines.Length];
        for (int i = 0; i < complexes.Length; i++)
        {
            complexes[i] = Parse(lines[i]);
        }
    }

    private static Complex Parse(string s)
    {
        var split = s.Split(new char[' '], StringSplitOptions.RemoveEmptyEntries); // I guess string is something like "12 54". If you have "12 + 54i" you'l get an exception here
        return new Complex(double.Parse(split[0]), double.Parse(split[1]));
    }
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
  • but how can be normalize the complex numbers.i have a 512 complex numbers,i want to normalize these numbers. – Ara Dec 02 '14 at 09:31