Hi guys, I am trying to produce or develop this equation below using an effective way.
I have two arrays or two dictionaries that i need to get the summation of. R
Review below and also the print screen in the below attachment.
How to write the below equation in code. The below equation should give a single value
output = (Summation ( Array1 * Array2)) / (Summation (Array1)
Keep in mind:
Array1 contains values below
Array1[0] = 1.0;
Array1[1] = 2.0;
Array1[2] = 3.0;
Array1[3] = 4.0;
Array1[4] = 5.0;
Array2 contains values below
Array2 [0] = 2.0;
Array2 [1] = 3.0;
Array2 [2] = 4.0;
Array2 [3] = 5.0;
Array2 [4] = 5.0;
Loading

VulpesRank #55 · 29.2K reputationPosted Jan 22, 2012, 2:51 AM EST
As the first items in the tuples don't appear to figure in the calculations, I've set them all to zero:
Karthik AgarwalRank #2,270 · 620 reputationPosted Jan 17, 2012, 11:37 PM EST
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace interest_calculation
{
class Program
{
static void Main(string[] args)
{
int i = 0;
Console.Write("Enter the array size : ");
i = Convert.ToInt32(Console.ReadLine());
Double[] array1 = new Double[i];
Double array1_summation = 0;
for (int index = 0; index < array1.Length; index++)
{
Console.Write("\nEnter the " + index + "th array element : ");
array1[index] = Convert.ToDouble(Console.ReadLine());
array1_summation = array1_summation + array1[index];
}
Console.WriteLine("array1 summation is :" + array1_summation);
Console.WriteLine("Enter the 2nd array elements");
Double[] array2 = new Double[i];
Double array2_summation = 0;
for (int index1 = 0; index1 < array2.Length; index1++)
{
Console.Write("\nEnter the " + index1 + "th array element : ");
array2[index1] = Convert.ToDouble(Console.ReadLine());
array2_summation = array2_summation + array2[index1];
}
Console.WriteLine("array2 summation is :" + array2_summation);
Double summation_result = array1_summation * array2_summation;
Console.WriteLine("summation of array1 and array2 is :" + summation_result);
Double result = summation_result / array1_summation;
Console.WriteLine("final result :" + result);
Console.ReadLine();
}
}
}
Karthik AgarwalRank #2,270 · 620 reputationPosted Jan 17, 2012, 11:38 PM EST
David SmithRank #999 · 2K reputationPosted Jan 18, 2012, 9:30 AM EST
so I want to use linq instead, can you help me produce the linq instead.
so basically i truly have is below
enum ArrayType
{
Array1,
Array2,
}
Dictionary< ArrayType, List
foreach( var arrayItem in Enum.GetValues(ArrayType))
{
dictionaryItems[arrayItem].Add(item1, item2);
}
Now you notice everything is in the dictionaryItems, i want to come up with good link to figure out the summation below
After that, I want to produce the logic to to the summation of arrays below. review equation again and and also review attachment to look at the formula i am trying to apply in code for the Arrays. My output is a single value.
output = (Summation ( Array1 * Array2)) / (Summation (Array1)
VulpesRank #55 · 29.2K reputationPosted Jan 18, 2012, 10:43 AM EST
David SmithRank #999 · 2K reputationPosted Jan 18, 2012, 11:21 AM EST
Its not working for me, how would you apply that using the
Hi , I was looking more of link to this, because im ultimately going to be dealing with 6 arrays,
so I want to use linq instead, can you help me produce the linq instead.
so basically i truly have is below
enum ArrayType
{
Array1,
Array2,
Array3,
Array4
}
Dictionary< ArrayType, List
foreach( var arrayItem in Enum.GetValues(ArrayType))
{
dictionaryItems[arrayItem].Add(item1, item2);
}
Now you notice everything is in the dictionaryItems, i want to come up with good link to figure out the summation below
After that, I want to produce the logic to to the summation of arrays below. review equation again and and also review attachment to look at the formula i am trying to apply in code for the Arrays. My output is a single value.
output = (Summation ( Array1 * Array2)) / (Summation (Array1)
VulpesRank #55 · 29.2K reputationPosted Jan 18, 2012, 12:28 PM EST
David SmithRank #999 · 2K reputationPosted Jan 18, 2012, 1:37 PM EST
review early posts i define Arrays, let me know if the early examples are not clear. i will try and send again
David SmithRank #999 · 2K reputationPosted Jan 18, 2012, 1:37 PM EST
review early posts i define Arrays, let me know if the early examples are not clear. i will try and send again
David SmithRank #999 · 2K reputationPosted Jan 18, 2012, 1:37 PM EST
review early posts i define Arrays, let me know if the early examples are not clear. i will try and send again
VulpesRank #55 · 29.2K reputationPosted Jan 20, 2012, 12:28 AM EST
It's not clear to me how this formula is to be applied to the complex Dictionary you're using rather than a simple array.
If it's to be applied to the values which are of type List
Also what are 'Tuples' and 'doubles' - are they custom types you've defined?
David SmithRank #999 · 2K reputationPosted Jan 21, 2012, 9:17 PM EST
enum ArrayType
{
Array1,
Array2,
Array3,
Array4
}
Dictionary< ArrayType, List
foreach( var arrayItem in Enum.GetValues(ArrayType))
{
dictionaryItems[arrayItem].Add(item1, item2);
}
review next reply. I am breaking everything up into two replies.
David SmithRank #999 · 2K reputationPosted Jan 21, 2012, 9:18 PM EST
Lets Begin.
Formula: Summation ( Array1 * Array2) Top Numerator
----------------------------- = ------- = ----------- = Output
Summation ( Array1 ) Bottom Denominator
Since we are using a dictionary list of tuples, we are using item 2 of the tuple arrays or tuple item. We are multiplying item2 of each array. Let me know if this clear. Don't get to caught at the moment why i am using a dictionary list of tuples.
1. Multiply Array1.item2 * Array2.item2
(Array1[0].item2 = 1.0; * Array2[0].item2 = 1.0;) = 1
(Array1[1].item2 = 2.0; * Array2[1].item2 = 2.0;) = 4
(Array1[2].item2 = 3.0; * Array2[2].item2 = 3.0;) = 9
(Array1[3].item2 = 4.0; * Array2[3].item2 = 4.0;) = 16
(Array1[4].item2 = 5.0; * Array2[3].item2 = 5.0;) = 25
--------------------------------------------------
Summation Total = 55
2. Take the Summation of the (Array1.item2 * Array2.item2) output
Numerator Summation Total = 55
3. For the numerator of the formula take the Summation of the (Array1.item2) output
Array1 [0].item2 = 1.0;
Array1 [1].item2 = 2.0;
Array1 [2].item2 = 3.0;
Array1 [3].item2 = 4.0;
Array2 [4].item2 = 5.0;
------------------
Denominator summation total = 15
4. Divide Top / Bottom = Final output 3.65
David SmithRank #999 · 2K reputationPosted Jan 22, 2012, 6:38 AM EST
David SmithRank #999 · 2K reputationPosted Jan 22, 2012, 12:10 PM EST
So if someone were to execute CalcaluteArrayExpression function and they enter 2 for lowLimit put and 4 for highLimit input. That means to calculate all elements in the array from range of 2 to 4. Below you will see the example thats highlighted thats needed to be evaluted. The highlighted section of the array is the range from the input. Can someone help me
void CalcaluteArrayExpression(LowLimit, HighLimit)
{
}
1. Multiply Array1.item2 * Array2.item2
(Array1[0].item2 = 1.0; * Array2[0].item2 = 1.0;) = 1
(Array1[1].item2 = 2.0; * Array2[1].item2 = 2.0;) = 4
(Array1[2].item2 = 3.0; * Array2[2].item2 = 3.0;) = 9
(Array1[3].item2 = 4.0; * Array2[3].item2 = 4.0;) = 16
(Array1[4].item2 = 5.0; * Array2[3].item2 = 5.0;) = 25
--------------------------------------------------
Summation Total = 50
Array1 [0].item2 = 1.0;
Array1 [1].item2 = 2.0;
Array1 [2].item2 = 3.0;
Array1 [3].item2 = 4.0;
Array1 [4].item2 = 5.0;
------------------
Denominator summation total = 12
4. Divide Top / Bottom = Final output 3.65
VulpesRank #55 · 29.2K reputationPosted Jan 22, 2012, 2:11 PM EST