Related
I was reading this article and I trying to follow their code example but I think I am missing a library.
They have this :
First, let's create a 2D matrix with some random data. We'll use the
System.Random class to generate pseudo-random numbers:
var rand = new Random();
var matrix = new double[5, 5];
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
matrix = rand.NextDouble() * 100;
}
}
Now that we have our data, we can calculate the mean and standard deviation:
double mean = matrix.Average();
double stdDev = Math.Sqrt(matrix.Variance());
but when I tried that in C# does, I get this compile time error:
Severity Code Description Project File Line Suppression State
Error CS1061 'double[,]' does not contain a definition for 'Variance' and no
accessible extension method 'Variance' accepting a first argument of type 'double[,]'
could be found (are you missing a using directive or an assembly reference?)
I tried adding
using System.Numerics;
but it did not help
In case you want to apply Linq method to 2D array T[,] items, you can use OfType() (or Cast<T>()) to obtain a enumeration IEnumeration<T>.
For instance, in your case with Average() you can put it as
using System.Linq;
...
var matrix = new double[5,5];
...
double mean = matrix
.OfType<double>()
.Average();
Since standard Linq doesn't have (at least in .Net 6) Variance method, we should do a simple statistics. Having a sequence of x = {x_1, x_2, x_3, ..., x_N} of N items the variance will be
Var(x) = Sum(x * x) / N - Sum(x) * Sum(x) / N / N
In our case it can be a simple Aggregate:
// Let's compute all required statistics
// n - number of items
// s - sum of items
// s - sum of items squared
// in one go with a help of Aggregate
var stat = matrix
.OfType<double>()
.Aggregate((n: 0, s: 0.0, ss: 0.0), (s, a) => (s.n + 1, s.s + a, s.ss + a * a));
double stdDev = Math.Sqrt(stat.ss / stat.n - stat.s * stat.s / stat.n / stat.n);
In order not to deal with such constructions, you can implement extension methods:
public static partial class Array2dExtensions {
public static double Average(this double[,] matrix) {
if (matrix == null)
throw new ArgumentNullException(nameof(matrix));
return matrix
.OfType<double>()
.Average();
}
public static double Variance(this double[,] matrix) {
if (matrix == null)
throw new ArgumentNullException(nameof(matrix));
var stat = matrix
.OfType<double>()
.Aggregate((n: 0, s: 0.0, ss: 0.0), (s, a) =>
(s.n + 1, s.s + a, s.ss + a * a));
return stat.ss / stat.n - stat.s * stat.s / stat.n / stat.n;
}
}
Having this implemented you can put it as if array has Average and Variance methods:
double mean = matrix.Average();
double stdDev = Math.Sqrt(matrix.Variance());
I implemented my own Levy distribution for a program but it seems that I get wrong values from it and after spending some time, I still cannot find where I did wrong.
This is used to generate random uniform numbers (double here) as well as the normal.
public class RandomProportional : Random
{
protected override double Sample()
{
return Math.Sqrt(base.Sample());
}
public override double NextDouble()
{
return (double)(Sample());
}
public double NextStdNormal()
{
double d1 = NextDouble();
double d2 = NextDouble();
return (double)(Math.Sqrt(-2.0 * Math.Log(d1)) * Math.Sin(2.0 * Math.PI * d2));
}
}
Here is how I calculate Sigma for the Levy distribution:
static double sigma_lev = Math.Pow(var_class.Gamma(1.0 + var_class.beta) * Math.Sin(Math.PI * var_class.beta / 2.0) / (var_class.Gamma((1.0 + var_class.beta) / 2.0) * var_class.beta * Math.Pow(2.0, (var_class.beta - 1.0) / 2.0)), 1.0 / var_class.beta);
Where var_class.Gamma(double x) is calculated using the code found here : Gamma function
Where var_class.beta = 1.5 (all the time)
The actual function:
public static double[] levy(int n)
{
RandomProportional randObj = new RandomProportional();
double[] step = new double[n];
for (int i = 0; i < n; ++i)
{
step[i] = var_class.gam * randObj.NextStdNormal() * sigma_lev / Math.Pow(Math.Abs(randObj.NextStdNormal()), 1.0 / var_class.beta);
}
return step;
}
Where var_class.gam
0.075
I'm using this formula for implementation:
Some examples of the results I get:
From there I guess I did something wrong but still cannot find what.
I'm working on a Midpoint Riemann Sum program, and it finds the integral of a randomly generated function called f.
Here's what wrote:
public static double FindIntegral (double start, double end, function f)
{
double sum = 0;
double stepsize = 1E-2;
int numSteps = (int)((end - start) / stepsize);
for (int i = 0; i < numSteps; i++)
{
sum += f(start + (stepsize * (i + 0.5)));
}
return sum * stepsize;
}
The function returns numbers that are too low (I have a reliable checking mechanism).
I put in x^3 for f, and I got the right answer. I tried a couple of more integrable functions and got a good answer. But somehow once I put in f it doesn't work.
I got the math formula for "Riemann Midpoint Sum" from here.
My implementation below seems to get the right answer (using the example function on the page). I used a class because 1) I could make the algorithm work specifying either the step size or the number of rectangles (I preferred the latter) and 2) I didn't see any reason to hard-code either into the algorithm.
As it turns out your code seemed to work just fine (see below); Make sure the code you have here in your question is what you're executing and make sure your expected result is accurate and that you're supplying good inputs (i.e. you don't have start and end backwards or the wrong function f or something). In other words what you provided in your question looks fine. Note double is approximate in C# (floating point arithmetic, in general) so to compare equality you can't use == unless you want exact if you're using unit tests or something.
public class Program
{
public static void Main()
{
function f = x => 50 / (10 + x * x);
// 9.41404285216233
Console.Out.WriteLine(new RiemannMidpointSum(6).FindIntegral(1, 4, f));
// 9.41654853716462
Console.Out.WriteLine(new RiemannMidpointSum(1E-2).FindIntegral(1, 4, f));
// 9.41654853716462
Console.Out.WriteLine(Program.FindIntegral(1, 4, f));
}
// This is your function.
public static double FindIntegral (double start, double end, function f)
{
double sum = 0;
double stepsize = 1E-2;
int numSteps = (int)((end - start) / stepsize);
for (int i = 0; i < numSteps; i++)
{
sum += f(start + (stepsize * (i + 0.5)));
}
return sum * stepsize;
}
}
public delegate double function(double d);
public class RiemannMidpointSum
{
private int? _numberOfRectangles;
private double? _widthPerRectangle;
public RiemannMidpointSum(int numberOfRectangles)
{
// TODO: Handle non-positive input.
this._numberOfRectangles = numberOfRectangles;
}
public RiemannMidpointSum(double widthPerRectangle)
{
// TODO: Handle non-positive input.
this._widthPerRectangle = widthPerRectangle;
}
public double FindIntegral(double a, double b, function f)
{
var totalWidth = b - a;
var widthPerRectangle = this._widthPerRectangle ?? (totalWidth / this._numberOfRectangles.Value);
var numberOfRectangles = this._numberOfRectangles ?? ((int)Math.Round(totalWidth / this._widthPerRectangle.Value, 0));
double sum = 0;
foreach (var i in Enumerable.Range(0, numberOfRectangles))
{
var rectangleMidpointX = a + widthPerRectangle * i + widthPerRectangle / 2;
var rectangleHeightY = f(rectangleMidpointX);
var rectangleArea = widthPerRectangle * rectangleHeightY;
sum += rectangleArea;
}
return sum;
}
}
I have point A (35.163 , 128.001) and point B (36.573 , 128.707)
I need to calculate the points lies within point A and point B
using the standard distance formula between 2 points, I found D = 266.3
each of the points lies within the line AB (the black point p1, p2, ... p8) are separated with equal distance of d = D / 8 = 33.3
How could I calculate the X and Y for p1 , p2, ... p8?
example of Java or C# language are welcomed
or just point me a formula or method will do.
Thank you.
**The above calculation is actually used to calculate the dummy point for shaded level in my map and working for shaded area interpolation purpose*
that's easy but you need some math knowledge.
PointF pointA, pointB;
var diff_X = pointB.X - pointA.X;
var diff_Y = pointB.Y - pointA.Y;
int pointNum = 8;
var interval_X = diff_X / (pointNum + 1);
var interval_Y = diff_Y / (pointNum + 1);
List<PointF> pointList = new List<PointF>();
for (int i = 1; i <= pointNum; i++)
{
pointList.Add(new PointF(pointA.X + interval_X * i, pointA.Y + interval_Y*i));
}
Straitforward trigonometric solution could be something like that:
// I've used Tupple<Double, Double> to represent a point;
// You, probably have your own type for it
public static IList<Tuple<Double, Double>> SplitLine(
Tuple<Double, Double> a,
Tuple<Double, Double> b,
int count) {
count = count + 1;
Double d = Math.Sqrt((a.Item1 - b.Item1) * (a.Item1 - b.Item1) + (a.Item2 - b.Item2) * (a.Item2 - b.Item2)) / count;
Double fi = Math.Atan2(b.Item2 - a.Item2, b.Item1 - a.Item1);
List<Tuple<Double, Double>> points = new List<Tuple<Double, Double>>(count + 1);
for (int i = 0; i <= count; ++i)
points.Add(new Tuple<Double, Double>(a.Item1 + i * d * Math.Cos(fi), a.Item2 + i * d * Math.Sin(fi)));
return points;
}
...
IList<Tuple<Double, Double>> points = SplitLine(
new Tuple<Double, Double>(35.163, 128.001),
new Tuple<Double, Double>(36.573, 128.707),
8);
Outcome (points):
(35,163, 128,001) // <- Initial point A
(35,3196666666667, 128,079444444444)
(35,4763333333333, 128,157888888889)
(35,633, 128,236333333333)
(35,7896666666667, 128,314777777778)
(35,9463333333333, 128,393222222222)
(36,103, 128,471666666667)
(36,2596666666667, 128,550111111111)
(36,4163333333333, 128,628555555556)
(36,573, 128,707) // <- Final point B
Subtract A from B, component-wise, to get the vector from A to B. Multiply that vector by the desired step value and add it to A. (Note that with eight intermediate steps as you've illustrated, the step distance is 1.0 / 9.0.) Something like this, assuming you really want seven points:
vec2 A = vec2 (35.163, 128.001);
vec2 B = vec2 (36.573, 128.707);
vec2 V = B - A;
for (i = 1; i < 8; i++) {
vec2 p[i] = A + V * (float)i / 8.0;
}
(Sorry, don't know any Java or C#.)
let A be point (xa, ya), and B be point (xb, yb)
alpha = tan-1((yb - ya)/(xb - xa))
p1 = (xa + d * cos(alpha), ya + d * sin(alpha))
pk = (xa + kd * cos(alpha), ya + kd * sin(alpha)), k = 1 to 7
(An equivalent way would be to use vector arithmetic)
At first find the slope of AB line. Get help and formula from here: http://www.purplemath.com/modules/slope.htm
Then consider a triangle of Ap1E(think there is a point E which is right to A and below to p1).
You already know the angle AEp1 is 90degree. and you have calculated angle p1AE(from the slope of AB).
Now find AE and Ep1.
Xp1=Xa+AE and Yp1=Ya+Ep1
This will not be very difficult in C# or java.
Once you understand the logic, you will find pleasure implementing on your own way.
I'm trying to implement a Discrete Fourier Transformation algorithm for a project I'm doing in school. But creating a class is seeming to be difficult(which it shouldn't be).
I'm using Visual Studio 2012.
Basically I need a class called Complex to store the two values I get from a DFT; The real portion and the imaginary portion.
This is what I have so far for that:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoundEditor_V3
{
public class Complex
{
public double real;
public double im;
public Complex()
{
real = 0;
im = 0;
}
}
}
The problem is that it doesn't recognize the constructor as a constructor, I'm just learning C#, but I looked it up online and this is how it's supposed to look.
But it recognizes my constructor as a method.
Why is that?
Am I creating the class wrong?
It's doing the same thing for my Fourier class as well. So each time I try to create a
Fourier object and then use it's method...there is no such thing.
example, I do this:
Fourier fou = new Fourier();
fou.DFT(s, N, amp, 0);
and it tells me fou is a 'field' but is used like a 'type'
why is it saying that?
Here is the code for my Fourier class as well:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoundEditor_V3
{
public class Fourier
{
//FOURIER
//N = number of samples
//s is the array of samples(data)
//amp is the array where the complex result will be written to
//start is the where in the array to start
public void DFT(byte[] s, int N, ref Complex[] amp, int start)
{
Complex tem = new Complex();
int f;
int t;
for (f = 0; f < N; f++)
{
tem.real = 0;
tem.im = 0;
for (t = 0; t < N; t++)
{
tem.real += s[t + start] * Math.Cos(2 * Math.PI * t * f / N);
tem.im -= s[t + start] * Math.Sin(2 * Math.PI * t * f / N);
}
amp[f].real = tem.real;
amp[f].im = tem.im;
}
}
//INVERSE FOURIER
public void IDFT(Complex[] A, ref int[] s)
{
int N = A.Length;
int t, f;
double result;
for (t = 0; t < N; t++)
{
result = 0;
for (f = 0; f < N; f++)
{
result += A[f].real * Math.Cos(2 * Math.PI * t * f / N) - A[f].im * Math.Sin(2 * Math.PI * t * f / N);
}
s[t] = (int)Math.Round(result);
}
}
}
}
I'm very much stuck at the moment, any and all help would be appreciated. Thank you.
edit:
this is where I'm trying to access all my classes:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SoundEditor_V3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string filename;
NAudio.Wave.WaveStream waveStream;
private NAudio.Wave.DirectSoundOut sout = null;
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Wave File (*.wav)|*.wav";
if (open.ShowDialog() != DialogResult.OK)
{
return;
}
waveStream = new NAudio.Wave.WaveFileReader(open.FileName);
filename = open.FileName;
sout = new NAudio.Wave.DirectSoundOut();
sout.Init(new NAudio.Wave.WaveChannel32(waveStream));
}
//Play
private void Play_btn_Click(object sender, EventArgs e)
{
sout.Play();
}
//Stop
private void Stop_btn_Click(object sender, EventArgs e)
{
sout.Stop();
waveStream.Position = 0;
}
//Pause
private void Pause_btn_Click(object sender, EventArgs e)
{
sout.Pause();
}
//display fourier
//N = number of samples(length of array)
//s is the array of samples(data)
//amp is the array where the complex result will be written to
//start is the where in the array to start
static int N = 8;
byte[] s = {1,2,3,4,5,6,7,8};
Complex[] amp = new Complex[N];
Fourier xfo = new Fourier();
//xfo.DFT(s, N, amp, 0);
}
}
This call should be inside a method. As of now, it looks its directly under a class.
//xfo.DFT(s, N, amp, 0);
Also add ref for amp. (As the void DFT(...., ref Complex[] amp,....) takes a ref amp parameter.
xfo.DFT(s, N, ref amp, 0);
Oh boy, so much room to improve.
First you are using the class Complex as a struct, in fact there is no need for it to be a class, so make it a struct:
public struct Complex
{
public double Imaginary;
public double Real;
}
No constructor needed, the default constructor (which the compilers add) will set the fields to their default value according to their type, and for double the default value is 0.0 (which is what you are assigning to them anyway*).
I have also renamed im to Imaginary, and don't tell me you have to type more because you got intellisense. If you didn't go download Mono Develop or Visual Studio Express. Oh, I can feel your thinking: we shouldn't relay on the tools. Well, that's right, and that is another reason to write code that is easy to read, even for those unfamiliar with the concepts (it also makes searching easier).
*: I want to note that 0 is a intenger literal and 0.0 is double, but the compiler reconizes this and optimizes the conversion away, so it is the same for practical purposes.
Let's move to your fourier class, first the method DFT, which I copy below (with the names of the fields of Complex renamed):
//FOURIER
//N = number of samples
//s is the array of samples(data)
//amp is the array where the complex result will be written to
//start is the where in the array to start
public void DFT(byte[] s, int N, ref Complex[] amp, int start)
{
Complex tem = new Complex();
int f;
int t;
for (f = 0; f < N; f++)
{
tem.real = 0;
tem.im = 0;
for (t = 0; t < N; t++)
{
tem.real += s[t + start] * Math.Cos(2 * Math.PI * t * f / N);
tem.im -= s[t + start] * Math.Sin(2 * Math.PI * t * f / N);
}
amp[f].real = tem.real;
amp[f].im = tem.im;
}
}
The first thing to notice is that you say that N is the number of samples and s is the samples array. Well, if you have an array you can query the size of the array, which is a good idea even if you want to allow to only process a portion of the array (I think you want that). But, really N and s?
Look, it's like magic:
//FOURIER
//amp is the array where the complex result will be written to
//start is the where in the array to start
public void DFT(byte[] samples, int samplesCount, ref Complex[] amp, int start)
{
Complex tem = new Complex();
int f;
int t;
for (f = 0; f < samplesCount; f++)
{
tem.Real = 0;
tem.Imaginary = 0;
for (t = 0; t < samplesCount; t++)
{
tem.Imaginary += samples[t + start] * Math.Cos(2 * Math.PI * t * f / samplesCount);
tem.Imaginary -= samples[t + start] * Math.Sin(2 * Math.PI * t * f / samplesCount);
}
amp[f].Real = tem.Real;
amp[f].Imaginary = tem.Imaginary;
}
}
Ok, next you say that amp is the output. Well if it is the output, why don't you make it te method return it?
Bam!
//FOURIER
//start is the where in the array to start
Complex[] DFT(byte[] samples, int samplesCount, int start)
{
var = new Complex[samplesCount];
Complex tem = new Complex();
int f;
int t;
for (f = 0; f < samplesCount; f++)
{
tem.Real = 0;
tem.Imaginary = 0;
for (t = 0; t < samplesCount; t++)
{
tem.Imaginary += samples[t + start] * Math.Cos(2 * Math.PI * t * f / samplesCount);
tem.Imaginary -= samples[t + start] * Math.Sin(2 * Math.PI * t * f / samplesCount);
}
result[f].Real = tem.Real;
result[f].Imaginary = tem.Imaginary;
}
return result;
}
Does it really need to be an array? I think this is a good oportunity to use the yield keyword and return IEnumerable<Complex>. But I'll take that you want, in deed, an array.
Now, may be you didn't want to return an array. May be you want to just modify portions of a preexisting array. In that case you should start checking your bounds. And even if that were true, you don't need ref at all! because the array is a reference type. It is a reference passed by value, if you cannot wrap your mind around that idea, just trust me, you can modify the contents of an array and see that reflected outside without ref... passing a reference by reference allows you to change the reference by another one, and you are not doing that.
To demostrate:
void Main()
{
var x = new int[1];
Do(x);
Console.WriteLine(x);
}
void Do (int[] array)
{
array[0] = 1;
}
The output of the previous program (compiled with LinqPad) is "1".
But let's get back to your code, shall we?
I don't know what are f and t. Thankfully I knew that im was imaginary (it was, right?). So I'll not rename them. But I'll move their definition to the loops:
Complex[] DFT(byte[] samples, int samplesCount, int start)
{
var result = new Complex[samplesCount];
Complex tem = new Complex();
for (int f = 0; f < samplesCount; f++)
{
tem.Real = 0;
tem.Imaginary = 0;
for (int t = 0; t < samplesCount; t++)
{
tem.Imaginary += samples[t + start] * Math.Cos(2 * Math.PI * t * f / samplesCount);
tem.Imaginary -= samples[t + start] * Math.Sin(2 * Math.PI * t * f / samplesCount);
}
result[f].Real = tem.Real;
result[f].Imaginary = tem.Imaginary;
}
return result;
}
Note my use of the var keyword. With it the compiler assigns the type of the variable to the type of what I'm using to initialize it. So in this case result is a Complex[] but I did not have to write that twice in the code.
And finally, that part where you copy the contents of the Complex object, well, I'll change that too. Why? Because Complex now is a struct, and structs are valuetypes. So it's content gets copied instead of a reference.
//FOURIER
//start is the where in the array to start
Complex[] DFT(byte[] samples, int samplesCount, int start)
{
var result = new Complex[samplesCount];
Complex tem = new Complex();
for (int f = 0; f < samplesCount; f++)
{
tem.Real = 0;
tem.Imaginary = 0;
for (int t = 0; t < samplesCount; t++)
{
tem.Imaginary += samples[t + start] * Math.Cos(2 * Math.PI * t * f / samplesCount);
tem.Imaginary -= samples[t + start] * Math.Sin(2 * Math.PI * t * f / samplesCount);
}
result[f] = tem;
}
return result;
}
I know you really want to proccess just a part of your array. But bear with me... you will learn a few things and that code will be useful anyway.
The next thing I want is to return an IEnumerable<Complex> which is an interface that represents anything that can be iterated to get objects of type Complex. I'll also use the yield keyword.
Additionally I've got rid of sampleCount and use samples.Length instead.
Just look how beautiful it gets:
//FOURIER
public IEnumerable<Complex> DFT(byte[] samples, int startIndex)
{
int samplesLength = samples.Length;
for (int f = 0; f < samplesLength; f++)
{
Complex resultItem = new Complex();
for (int t = 0; t < samplesLength; t++)
{
resultItem.Real += samples[t + startIndex] * Math.Cos(2 * Math.PI * t * f / samplesLength);
resultItem.Imaginary -= samples[t + startIndex] * Math.Sin(2 * Math.PI * t * f / samplesLength);
}
yield return resultItem;
}
}
In fact, I'll get rid of startIndex too (we are not checking bounds anyway*).
*: that is, we are not checking if the index are inside the array size. I know, I know, you was going to add them later... probably.
Anyway, you are learning some C# here.
//FOURIER
public IEnumerable<Complex> DFT(byte[] samples)
{
int samplesLength = samples.Length;
for (int f = 0; f < samplesLength; f++)
{
Complex resultItem = new Complex();
for (int t = 0; t < samplesLength; t++)
{
resultItem.Real += samples[t] * Math.Cos(2 * Math.PI * t * f / samplesLength);
resultItem.Imaginary -= samples[t] * Math.Sin(2 * Math.PI * t * f / samplesLength);
}
yield return resultItem;
}
}
Well, the next thing that bothers me is the fact that the class Fourier has no state (it has no fields, or any variable which value is persisted... somehow). So, make it a static class with a static method:
public static class Fourier
{
//FOURIER
public static IEnumerable<Complex> DFT(byte[] samples)
{
int samplesLength = samples.Length;
for (int f = 0; f < samplesLength; f++)
{
Complex resultItem = new Complex();
for (int t = 0; t < samplesLength; t++)
{
resultItem.Real += samples[t] * Math.Cos(2 * Math.PI * t * f / samplesLength);
resultItem.Imaginary -= samples[t] * Math.Sin(2 * Math.PI * t * f / samplesLength);
}
yield return resultItem;
}
}
}
Of course you notice I haven't added IDFT. That one is homework.
Now, let's see how you use it. In my case I created a ConsoleApplication, just to have it up and running fast (no time wasted designing a GUI).
What I want is to call Fourier.DFT which I can without an object of type Fourier because it is static (In fact I cannot create an object of type Fourier because it is static).
This method recieves an argument of type byte[]. That one will be new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }. And that method will return something I can use to iterate over to get objects of type Complex. So I want to put it a loop.
This is how my code looks like:
class Program
{
static void Main(string[] args)
{
//display fourier
foreach (var item in Fourier.DFT(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }))
{
Console.WriteLine(item);
}
}
}
Now... the output is... drum roll...
Well, I can't see it, I forgot Console.ReadLine(); but after adding that the output is...
Namespace.Complex
Namespace.Complex
Namespace.Complex
Namespace.Complex
Namespace.Complex
Namespace.Complex
Namespace.Complex
Namespace.Complex
Wait, what? It happens that I haven't told it how to convert an object of type Complex to string. So let's add that:
public struct Complex
{
public double Imaginary;
public double Real;
public override string ToString()
{
return string.Format("Complex [Real: {0}, Imaginary: {1}]", Real, Imaginary);
}
}
Now my output is:
Complex [Real: 36, Imaginary: 0]
Complex [Real: -4, Imaginary: 9,65685424949238]
Complex [Real: -4, Imaginary: 4]
Complex [Real: -4, Imaginary: 1,65685424949239]
Complex [Real: -4, Imaginary: -3,91874033223161E-15]
Complex [Real: -4,00000000000001, Imaginary: -1,65685424949239]
Complex [Real: -4,00000000000002, Imaginary: -4,00000000000001]
Complex [Real: -3,99999999999997, Imaginary: -9,65685424949237]
Is the output correct? I have no freaking idea! I have to learn more about Fourier (but it looks legit).
After verification, the output is correct.
One final note: Step trhoug the code with a debuger, you may find a surprise (hint: yield).
You need a method, try this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoundEditor_V3
{
public class Complex
{
public double real;
public double im;
public Complex()
{
real = 0;
im = 0;
}
public Setval (double newReal, double newIm)
{
real = newReal;
im = newIm;
}
}
}
In regards to your other class, where is the constructor? ;)
Thank you for all your help; I actually ended up figuring everything out.
I couldn't access methods in the area I was trying to access them in. I had to put them inside a method block because this was all being coded inside a form.
That's my understanding anyway.
But again, thank you for all your suggestions, they were all helpful.