By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,183 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,183 IT Pros & Developers. It's quick & easy.

Math functions in VB (or even a dll somewhere) Options

P: n/a
Hello. If this is the wrong group for this, please let me know.
I'll
post it somewhere else.

I've been doing data imports into MS Excel (ver 2007) and using the
CORREL function. What I was wondering was is there anything like
this
in Visual Basic or C#? Or even a DLL? I've got VS2008 and I really
don't want to code the CORREL function by hand if I can just pass off
2 or more array's to a function that already exists.
I've googled and went through the MSDN library and didn't find
anything. Maybe I'm searching wrong, I don't know. Any help would
be
greatly appreciated.
TIA!
Nov 29 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,
If you are using C# this is the correct group.

First of all you should try to explain what Correl does. Make it easy to the
person trying to help you ;)

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Nondisclosure007" <no**************@gmail.comwrote in message
news:cd**********************************@g30g2000 hsb.googlegroups.com...
Hello. If this is the wrong group for this, please let me know.
I'll
post it somewhere else.

I've been doing data imports into MS Excel (ver 2007) and using the
CORREL function. What I was wondering was is there anything like
this
in Visual Basic or C#? Or even a DLL? I've got VS2008 and I really
don't want to code the CORREL function by hand if I can just pass off
2 or more array's to a function that already exists.
I've googled and went through the MSDN library and didn't find
anything. Maybe I'm searching wrong, I don't know. Any help would
be
greatly appreciated.
TIA!

Nov 29 '07 #2

P: n/a
Correlation Coefficient (C#):

public double GetCorrelation(double[] num1, double[] num2)
{
double denominator = (num1.Length - 1) * GetStandardDeviation(num1) *
GetStandardDeviation(num2);
double sumxy = 0;
for (int i=0; i<num1.Length; i++)
{
sumxy += num1[i] * num2[i];
}
double numerator = sumxy - num1.Length * GetAvg(num1) * GetAvg(num2);
return numerator / denominator;
}

public static double GetStandardDeviation(ArrayList num)
{
double SumOfSqrs = 0;
double avg = GetAvg(num);
for (int i=0; i<num.Count; i++)
{
SumOfSqrs += Math.Pow(((double)num[i] - avg), 2);
}
double n = (double)num.Count;
return Math.Sqrt(SumOfSqrs/(n-1));
}

public static double GetStandardDeviation(double[] num)
{
double Sum = 0.0, SumOfSqrs = 0.0;
for (int i=0; i<num.Length; i++)
{
Sum += num[i];
SumOfSqrs += Math.Pow(num[i], 2);
}
double topSum = (num.Length * SumOfSqrs) - (Math.Pow(Sum, 2));
double n = (double)num.Length;
return Math.Sqrt( topSum / (n * (n-1)) );
}

public static double GetStandardDeviation(double[,] num, int col)
{
double Sum = 0.0, SumOfSqrs = 0.0;
int len = num.GetLength(0);
for (int i=0; i<len; i++)
{
Sum += num[i,col];
SumOfSqrs += Math.Pow(num[i,col], 2);
}
double topSum = (len * SumOfSqrs) - (Math.Pow(Sum, 2));
double n = System.Convert.ToDouble(len);
return Math.Sqrt( topSum / (n * (n-1)) );
}

public double GetAvg(double[] num)
{
double sum = 0.0;
for (int i=0; i<num.Length; i++)
{
sum += num[i];
}
double avg = sum / System.Convert.ToDouble(num.Length);

return avg;
}

public double GetAvg(int[] num)
{
double sum = 0.0;
for (int i=0; i<num.Length; i++)
{
sum += num[i];
}
double avg = sum / System.Convert.ToDouble(num.Length);

return avg;
}

public double GetAvg(ArrayList num)
{
double sum = 0.0;
for (int i=0; i<num.Count; i++)
{
sum += (double)num[i];
}
double avg = sum / System.Convert.ToDouble(num.Count);

return avg;
}

-- Have fun!
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com

"Nondisclosure007" wrote:
Hello. If this is the wrong group for this, please let me know.
I'll
post it somewhere else.

I've been doing data imports into MS Excel (ver 2007) and using the
CORREL function. What I was wondering was is there anything like
this
in Visual Basic or C#? Or even a DLL? I've got VS2008 and I really
don't want to code the CORREL function by hand if I can just pass off
2 or more array's to a function that already exists.
I've googled and went through the MSDN library and didn't find
anything. Maybe I'm searching wrong, I don't know. Any help would
be
greatly appreciated.
TIA!
Nov 29 '07 #3

P: n/a
Not that I know, for those who want more information, I have searched for it
on the microsoft website.

http://office.microsoft.com/en-gb/ex...090231033.aspx

Cor

Nov 29 '07 #4

P: n/a
http://www.google.com/search?sourcei...n+coefficient+

See if this helps

Regards,

Trevor Benedict
MCSD
"Nondisclosure007" <no**************@gmail.comwrote in message
news:cd**********************************@g30g2000 hsb.googlegroups.com...
Hello. If this is the wrong group for this, please let me know.
I'll
post it somewhere else.

I've been doing data imports into MS Excel (ver 2007) and using the
CORREL function. What I was wondering was is there anything like
this
in Visual Basic or C#? Or even a DLL? I've got VS2008 and I really
don't want to code the CORREL function by hand if I can just pass off
2 or more array's to a function that already exists.
I've googled and went through the MSDN library and didn't find
anything. Maybe I'm searching wrong, I don't know. Any help would
be
greatly appreciated.
TIA!

Nov 29 '07 #5

P: n/a
On Nov 29, 4:25 pm, "Trevor Benedict" <TrevorN...@yahoo.comwrote:
http://www.google.com/search?sourcei...8&rls=GGLG,GGL...

See if this helps

Regards,

Trevor Benedict
MCSD

"Nondisclosure007" <nondisclosure...@gmail.comwrote in message

news:cd**********************************@g30g2000 hsb.googlegroups.com...
Hello. If this is the wrong group for this, please let me know.
I'll
post it somewhere else.
I've been doing data imports into MS Excel (ver 2007) and using the
CORREL function. What I was wondering was is there anything like
this
in Visual Basic or C#? Or even a DLL? I've got VS2008 and I really
don't want to code the CORREL function by hand if I can just pass off
2 or more array's to a function that already exists.
I've googled and went through the MSDN library and didn't find
anything. Maybe I'm searching wrong, I don't know. Any help would
be
greatly appreciated.
TIA!- Hide quoted text -

- Show quoted text -
Thank you for everyone replying. I was kind of looking for something
like a stats.dll that I could use pre-coded functions.

But thanks anyways! I appreciate the code!
Nov 30 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.