Vuples where are you lololol?
using linq i want multilpty to multiply (Aarray1 * Array2) from 2.3 to 2.05 then i want to sum the output array base upon the range , can some help me
Array1[0] = {( 2.00, 1.00 )} * Array2[0] = {( 2.00, 2.00 )} = 2
Array1[1] = {( 2.01, 2.00 )} * Array2[1] = {( 2.01, 3.00 )} = 6
Array1[2] = {( 2.02, 3.00 )} * Array2[2] = {( 2.02, 4.00 )} = 12
Array1[3] = {( 2.03, 4.00 )} * Array2[3] = {( 2.03, 5.00 )} = 20
Array1[4] = {( 2.04, 5.00 )} * Array2[4] = {( 2.04, 6.00 )} = 30
Array1[5] = {( 2.05, 6.00 )} * Array2[5] = {( 2.05, 7.00 )} = 42
Array1[6] = {( 2.06, 7.00 )} * Array2[6] = {( 2.06, 8.00 )} = 56
-----------------------------------------------------------------------
Output[0] = {( 2.03, 20)}
Output[1] = {( 2.04, 30 )}
Output[2] = {( 2.05, 42 )}
double result = Output.Sum();
result = 92
Loading

VulpesRank #55 · 29.2K reputationPosted Jan 30, 2012, 4:55 AM EST
David SmithRank #999 · 2K reputationPosted Jan 30, 2012, 5:21 AM EST
Where(a => a[0] >= 2.03 && a[0]
VulpesRank #55 · 29.2K reputationPosted Jan 30, 2012, 5:26 AM EST
They therefore implement IEnumerable
As each element in the sequence is an array ('a') and we're interested in the first element, we therefore use a[0].
David SmithRank #999 · 2K reputationPosted Jan 30, 2012, 11:11 AM EST
double output = ArrayDictionary[ArrayType.Array1.ToString()].Where(a => a[0] >= LowLimit && a[0] <=
HighLimit).Zip(ArrayDictionary[ArrayType.Array1.ToString()].to.Where(a => a[0] >= 2.03 && a[0] <=
2.(t1, t2) => t1[1].Item2 * t2[1].Item2).Sum();
VulpesRank #55 · 29.2K reputationPosted Jan 30, 2012, 12:00 PM EST
David SmithRank #999 · 2K reputationPosted Jan 30, 2012, 12:24 PM EST
for (waveLength = 2.00, index = 0; waveLength <= 5.00; waveLength += 0.01, index++)
{
Output[index] = (ArrayDictionary[ArrayType.Array1.ToString()][index].Item2 * ArrayDictionary[ArrayType.Array2.ToString()][index].Item2);
ArrayDictionary[ArrayType.ArrayType.ToString()].Add(new Tuple
}
double output = ArrayDictionary[ArrayType.Array1.ToString()].Where(a => a[0] >= LowLimit && a[0] <=
HighLimit).Zip(ArrayDictionary[ArrayType.Array2.ToString()].to.Where(a => a[0] >= 2.03 && a[0] <=
2.(t1, t2) => t1[1].Item2 * t2[1].Item2).Sum();
David SmithRank #999 · 2K reputationPosted Jan 30, 2012, 3:06 PM EST
VulpesRank #55 · 29.2K reputationPosted Jan 31, 2012, 12:43 AM EST
Here's a version of the program which should work for your ArrayDictionary:
David SmithRank #999 · 2K reputationPosted Jan 31, 2012, 3:18 AM EST
Array1[3] = {( 2.03, 4.00 )} * Array2[3] = {( 2.03, 5.00 )} = 20
Array1[4] = {( 2.04, 5.00 )} * Array2[4] = {( 2.04, 6.00 )} = 30
Array1[5] = {( 2.05, 6.00 )} * Array2[5] = {( 2.05, 7.00 )} = 42
--------------------------------------------------------------------
Array1[3] = {( 2.03, 4.00 )}
Array1[4] = {( 2.04, 5.00 )}
Array1[5] = {( 2.05, 6.00 )}
92 / 15 = 6.1333333333
output = 6.13333333
VulpesRank #55 · 29.2K reputationPosted Jan 31, 2012, 3:54 AM EST
David SmithRank #999 · 2K reputationPosted Jan 31, 2012, 3:59 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 31, 2012, 4:16 AM EST
BTW, it's not good coding practice IMO to always cram everything into a single LINQ query. Remember you (or somebody else) may have to maintain this stuff months or years down the line.
Whilst LINQ is a powerful tool, it can produce some very complex expressions and it may therefore be better to break them up into bits that are easy to understand.
David SmithRank #999 · 2K reputationPosted Jan 31, 2012, 4:33 AM EST