enum ArrayType
{
Array1,
Array2,
Array3
}
public Dictionary
public void ConstructArray(double[] array1, double[] array2, double[] array3)
{
foreach (ArrayType arrayItem in Enum.GetValues(typeof(ArrayType)))
{
ArrayDictionary.Add(arrayItem .ToString(), new List
switch (opticalArrayItem)
{
case ArrayType.Array1:
foreach (double arrayItem in array1)
{
// Add to ArrayDictionary
}
break;
case ArrayType.Array2:
foreach (double arrayItem in array1)
{
// Add to ArrayDictionary b
}
break;
case ArrayType.Array3:
foreach (double arrayItem in array1)
{
// Add to ArrayDictionary
}
break;
}
}
}

VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 11:10 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 22, 2012, 11:42 PM EST
David SmithRank #999 · 2K reputationPosted Jan 22, 2012, 11:59 PM EST
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 12:02 AM EST
Because the Dictionary's value is a List of double arrays, you can simply add a double array to the list for a given key.
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 12:12 AM EST
public Dictionary
public void ConstructArray(double[] array1, double[] array2, double[] array3)
{
ArrayDictionary = new Dictionary
foreach (ArrayType arrayItem in Enum.GetValues(typeof(ArrayType)))
{
ArrayDictionary.Add(arrayItem.ToString(), new List
switch (arrayItem)
{
case ArrayType.Array1:
foreach( var item in array1)
{
ArrayDictionary[arrayItem.ToString()].Add(item );
}
break;
case ArrayType.Array2:
foreach( var item in array2)
{
ArrayDictionary[arrayItem.ToString()].Add(item );
}
break;
case ArrayType.Array3:
foreach( var item in array3)
{
ArrayDictionary[arrayItem.ToString()].Add(item );
}
break;
}
}
}
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 12:21 AM EST
You'll be informed that List.Add has some invalid arguments - argument 1 cannot convert from double to double[].
If it's any help to you, here's a little program I did to test my own code and make sure the Dictionary could be iterated subsequently:
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 1:28 AM EST
now that we have all the arrays i need to multiply all the array into one array, how to do this using linq, review below.
Output[] = Array1[] * Array2[] * Array3[]
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 2:12 AM EST
Here's the code for both:
// using traditional approach
The output in either case will be :
28
80
162
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 2:18 AM EST
Output[] =( Array1[] * Array2[] * Array3[])
Output [] will not be a single bracket, it will be the array output of ( Array1[] * Array2[] * Array3[])
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 2:39 AM EST
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 2:50 AM EST
Output[] =( (Array1[] * Array2[] * Array3[] ( Array1[] * Array2[] ) )+ Array1[] )
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 2:57 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 3:10 AM EST
Output[] =( (Array1[] * Array2[] * Array3[] + ( Array1[] * Array2[] ) )+ Array1[] )
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 3:23 AM EST
OutPut[i]=(( ArrayDictionary [Array1][i] * ArrayDictionary [Array2][i] * ArrayDictionary [Array3][i]
* (ArrayDictionary Array2][i] - ArrayDictionary [Array1][i]))
+ ArrayDictionary [Array1][i]);
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 3:49 AM EST
I've also included an alternative approach using LINQ which is closer to the traditional approach and therefore more efficient than using Zip:
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 6:37 AM EST
{
NewArray[] = (Array1[i] + Array2[i]) + (Math.Pow(WaveLength, 5)) - Output2[i] )
}
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 6:52 AM EST
So that would give:
double[] Output2 = new double[Array1.Length];
double[] NewArray = new double[Array1.Length];
for(int i = 0; i < Array1.Length; i++)
{
Output2[i] = Array1[i] * Array2[i] * Array3[i] * (Array2[i] - Array1[i]) + Array1[i];
NewArray[] = Array1[i] + Array2[i] + Math.Pow(i + 1.3, 5) - Output2[i];
}
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 9:20 AM EST
I cant go into detail but , I am going to use 3 to 4 arrays only like we have been. We are on track, just got to re think the logic to get to the final output.
I am still using the
enum ArrayType
{
Array1,
Array2,
Array3
}
Dictionary
double[] GivenArray1{ get; set; }
double[] GivenArray2{ get; set; }
double[] GivenArray3{ get; set; }
1. Construct all ways from 1.30 to 5.30 by 10 nano meters by given formula below
Note: wavelength is the values changing from 1.30 to 5.30 by 10 nano meters
NewArray1 [] = ((GivenArray1[] * GivenArray2[] * GivenArray2[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) ))
NewArray2 [] = ((GivenArray1[] * GivenArray2[] * GivenArray2[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) )) + NewArray1 []);
NewArray3 [] = ((GivenArray1[] * GivenArray2[] * GivenArray2[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) )) + NewArray3 [] );
2. After constructing each given array , Each array will construct another output Array from 1.30 to 5.30 by 10 nano meters by formula given.
3. There will be a total of 7 arrays, need to get to the final single output double value.
double finalOutput = (Summation (NewArray1 [] * NewArray2 [] * NewArray3 [])) / (Summation (NewArray1 []))
VulpesRank #55 · 29.2K reputationPosted Jan 23, 2012, 9:48 AM EST
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 10:39 AM EST
NewArray1 [] = ((GivenArray1[] * GivenArray2[] * GivenArray3[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) )) + GivenArray2[] );
NewArray2 [] = ((GivenArray1[] * GivenArray2[] * GivenArray3[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) )) + NewArray1 []);
NewArray3 [] = ((GivenArray1[] * GivenArray2[] * GivenArray3[] ( GivenArray2[] - GivenArray2[] (Math.Pow(
waveLength ,5) )) + NewArray3 [] );
David SmithRank #999 · 2K reputationPosted Jan 23, 2012, 11:35 AM EST