In order not to litter this issue and not to violate the rules and topics, I create a new

Start from here Get rid of the implicit conversion

It was said To restore the waveform you need, in addition to amplitude, also the phase (c) Pavel_Mayorov

My approximate ALGORITHM

I upload all my complex functions to the collection.

Then, using ForEach, I want to split into parts, namely Imaginary and Real, and immediately get the arctangent.

Guided by this formula

enter image description here

Thereby I receive a phase (According to the theory) I implement it all in the code.

public static double getfaza(int frc, int frc1, double T, double U) { int frequency, counter; List<Complex> values = new List<Complex>(); for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { values.Add(GetSpectralDensity(U, frequency, T)); } return values.ForEach(x1 => Math.Atan(x1.Real/x1.Imaginary)); } 

I substitute the obtained phase into the formula for the inverse Fourier transform. 0 and Tau I left as the limits of integration in order to later look at the change in the results.

 public static Complex reverstrans(double U, double anguarFrequency, double T,int frc,int frc1) { NumericalIntegration integration = new NumericalIntegration(); if (anguarFrequency == 0)// Учитываем деление на 0 return new Complex(U * T, 0); return (1 / 2 * Math.PI) * integration.Calculate(w => Math.Cos(GetSpectralDensityOfAmplitude(GetSpectralDensity(U, anguarFrequency, T)) * getfaza(frc, frc1, T, U)), 0, T) + Complex.ImaginaryOne * (1 / 2 * Math.PI) * integration.Calculate(w => Math.Sin(GetSpectralDensityOfAmplitude(GetSpectralDensity(U, anguarFrequency, T)) * getfaza(frc, frc1, T, U)), 0, T); } 

This is still in theory I can not find.

In this case, the function U (w) is even (always) - and therefore the imaginary part of u (t) goes to zero (mathematically), only the real one remains. This is what you need to draw. The imaginary part u (t) can be used to estimate the accuracy of the integration (c) Pavel_Mayorov

Current issues

 return values.ForEach(x1 => Math.Atan(x1.Real/x1.Imaginary));-Неявное преобразование типа "void" в "double" невозможно 

Here I am at a dead end. As you can see there is no void there, the values collection is declared as Complex, all the operations on it I carry out as a complex number. I use values.ForEach to get a phase from each complex

And again she (but if I decide the 1st formula, I think the 2nd will disappear)

 list.Add(angularFrequency, reverstrans(U, anguarFrequency, T,frc,frc1)); - Аргумент "2": преобразование типа из "System.Numerics.Complex" в "double" невозможно 

UPD:

Unfortunately, I'm just starting to get acquainted with Select and the acquaintance is so far unfortunate.

 public static double getfaza(int frc, int frc1, double T, double U) { int frequency, counter; List<Complex> values = new List<Complex>(); for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { values.Add(GetSpectralDensity(U, frequency, T)); } return values.Select((value,x1) => new {Math.Atan(x1.Real/x1.Imaginary)}); } 

new {Math.Atan(x1.Real/x1.Imaginary)} -Invalid definition of a member of an anonymous type. Members of an anonymous type must be declared by assigning a member, simple name, or access to a member.

Please do not minus. I really want to quickly deal with it, do it all. And learn other interesting sections in programming.

  • one
    By the way, (1 / 2 * Math.PI) is 0. Right (1/2π) will be (1 / (2 * Math.PI)) . - i-one

1 answer 1

Your code is trying to return the result of running ForEach. The problem is that ForEach returns nothing. He runs through the collection, calls a function for each element, and throws the result. This is an analogue foreach loop.

The method that runs through the collection, and makes of it a new collection called Select. Use it instead of ForEach.

  • Most likely, you should leave ForEach here, and return values ​​after it - Grundy
  • @grundy I honestly do not quite imagine what is happening there. But there is no sense to leave there for each - it doesn’t change anything. - PashaPash
  • And, it is me, it means that I also looked bad :) it seemed to me that, as a matter of fact, it changes - Grundy
  • Unfortunately, this is probably my first experience with Select. Does it allow formulas to calculate and memorize what is received? I updated the beginner code
  • 2
    @beginner Are you trying to write code at random? Unfortunately, this is just a waste of time. By using Select instead of ForEach I meant exactly the replacement of the name of the method. Why did you add new {}? And even after that - you will receive a sequence (several) double at the output of the select. Method getfaza should return one of them? The average? Amount? - PashaPash