Created a list into which I will upload my values.

List<double> moduls = new List<double>(); 

I load my values ​​from the method

  for (int frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { moduls.Add(GetSpectralDensityOfAmplitude(GetSpectralDensity(U, frequency, T))); } 

And now the most interesting thing is how to multiply each element of the list by cosine

  public static Complex reverstrans(double U, double anguarFrequency, double T,int frc,int frc1,double shag)///Обратное преобразование Фурье { NumericalIntegration integration = new NumericalIntegration(); int t = 1; List<double> moduls = new List<double>(); for (int frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { moduls.Add(GetSpectralDensityOfAmplitude(GetSpectralDensity(U, frequency, T))); } return (1 / 2 * Math.PI) * integration.Calculate(w => moduls.ForEach(x1 => x1 * Math.Cos(anguarFrequency * t)),0, T); ----Проблемная строка } 

The question is

How to multiply and add each element of the list through ForEach? The problem is that swears

 Ошибка 1 В качестве оператора могут использоваться только выражения присваивания, вызова, инкремента, декремента и ожидания 

Here is the Calculate method.

 class TrapezoidalRule : NumericalIntegrationRule { public double Calculate(Func<double,double> func, double min, double max, double subintervalsCount) { double result = 0; double step = (max - min) / subintervalsCount; for (double i = min; i < max; i += step) result += ((func(i) + func(i + step)) / 2) * step; return result; } } 

It will not be possible to bring the ForEach integration limits inside, since then you will have to redo the Calculate method and it is tied to many things.

And if I work without creating a List <>, then I have only zeros. Through List <> I can see my values ​​and navigate when debugging

How can this problem be solved?

And why do I need it

This is what I need to get results that will allow me to derive approximately such a schedule.

enter image description here

  • ForEach returns nothing, this time, apparently, the number of required parameters in Calculate and transmitted is different: 4 is required (func, min, max, subintervalsCount), 3 is transmitted (w => moduls.ForEach (x1 => x1 * Math.Cos (anguarFrequency * t)), 0, T), that is, there are two more errors from the question - Grundy
  • well, the error itself says what permissions operations, in this case, multiplication is neither an assignment, nor a function call, an increment, decrement, await or the creation of a new object - Grundy
  • You have an error in the implementation of some formulas. You have received a list of points, depending on the frequency. Then you try to integrate this list of points in time dependence. Even if you enter a function that will return the point depending on the time, in my opinion, it will be crazy. Show that you are still trying to implement. - skubarenko
  • @ nuts119 I updated the question. I need to bring the schedule, the head said to act in the manner described above. 2 weeks I suffer with the schedule. - beginner
  • @beginner, what's on this graph? Dependence of what on what? - skubarenko

1 answer 1

Somehow you want everything to be difficult to do. It is necessary to multiply by the cosine - so multiply by the cosine.

 // Обратное преобразование Фурье public static Complex reverstrans( double U, double anguarFrequency, double T, int frc, int frc1, double shag) { NumericalIntegration integration = new NumericalIntegration(); int t = 1; List<double> moduls = new List<double>(); for (int frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) { moduls.Add(GetSpectralDensityOfAmplitude(GetSpectralDensity(U, frequency, T))); } // умножаем на косинус for (int i = 0; i < moduls.Length; i++) { // поскольку у вас t нигде не меняется, вычисление косинуса можно // вообще вынести за цикл moduls[i] *= Math.Cos(anguarFrequency * t); } // на месте вопросительных знаков вам нужна функция из double в double, // её у вас там не было, подставляйте её! return (1 / 2 * Math.PI) * integration.Calculate(???, 0, T); }