Click here to Skip to main content
15,902,492 members
Home / Discussions / C#
   

C#

 
GeneralDifferences in Invoke() Pin
stancrm6-Mar-08 0:46
stancrm6-Mar-08 0:46 
GeneralRe: Differences in Invoke() Pin
Robert Rohde6-Mar-08 1:24
Robert Rohde6-Mar-08 1:24 
GeneralInvalidOperationException Pin
satheesh.yuva6-Mar-08 0:32
satheesh.yuva6-Mar-08 0:32 
GeneralRe: InvalidOperationException Pin
Gareth H6-Mar-08 2:08
Gareth H6-Mar-08 2:08 
GeneralREG_SZ String Value Pin
mjmim6-Mar-08 0:24
mjmim6-Mar-08 0:24 
GeneralRe: REG_SZ String Value Pin
led mike6-Mar-08 4:49
led mike6-Mar-08 4:49 
GeneralRe: REG_SZ String Value Pin
mjmim6-Mar-08 12:02
mjmim6-Mar-08 12:02 
Questionc# matrix problem Pin
nrg2225-Mar-08 23:25
nrg2225-Mar-08 23:25 
Ok, so this is the first time I am posting up an article about programming. After reading the help I understand that I am to post up my coding, point out the obvious and state my problem so i will do that now...

1- The code:

using System;
using System.Collections;
using System.Collections.Generic;

class ClassX
{

//receives the dependent 'y' variable and then the regressors in the cast: lists<double> only
public static Matrix beta(List<double> y, List<double> reg1, List<double> reg2, List<double> reg3, List<double> reg4, List<double> reg5, List<double> reg6)
{
int n = ret_nzd.Count;
//first get the regressors into a 2-D array and then matrix into a n*7 sized matrix
double[,] a = new double[n,7];
for(int iy=0;iy<7;iy++)
for (int ix = 0; ix<7; n; ix++)
{
if (iy == 0)
a[ix, iy] = 1.0;
if (iy == 1)
a[ix, iy] = reg1[ix];
if (iy == 2)
a[ix, iy] = reg2[ix];
if (iy == 3)
a[ix, iy] = reg3[ix];
if (iy == 4)
a[ix, iy] = reg4[ix];
if (iy == 5)
a[ix, iy] = reg5[ix];
if (iy == 6)
a[ix, iy] = reg6[ix];
}
//now get the dependent variable,y, into a n*1 array and then matrix
double[,] yarray = new double[n,1];
for (int ix = 0; ix<7; n; ix++)
yarray[ix,0] = y[ix];

//define new matrices

Matrix X = new Matrix(a);
Matrix Y = new Matrix(yarray);
Matrix BetaMatrix = new Matrix(7, 1);

Matrix XTemp = new Matrix(7,7);
Matrix XdashXInverse = new Matrix(7,7);
Matrix XTransY = new Matrix(7,1);


//X'X:
Matrix XTrans = X.Transpose();

for (int ix = 0; ix < 7; ix++)
{
for (int iy = 0; iy < 7; iy++)
{
for (int iz = 0; iz < 7; iz++)
{
XTemp[ix, iy] += XTrans[ix, iz] * X[iz, iy];
}
}
}


//(X'X)^-1:
XdashXInverse = XTemp.Inverse();

//X'Y = 7*1
for (int ix = 0; ix < 7; ix++)
{
for (int iz = 0; iz < n; iz++)
{
XTransY[ix, 0] = XTrans[ix, iz] * Y[iz, 0];
}
}

//(X'X)^-1 (X'Y):
for (int ix = 0; ix < 7; ix++)
{
for (int iz = 0; iz < n; iz++)
{
BetaMatrix[ix, 0] = XdashXInverse[ix,iz] * XTransY[iz, 0];
}
}

return BetaMatrix;
}


}

2- The obvious:

I am trying to obtain a linear multi-regression model in c# but I wanted to build most of the modeling myself in order to learn c#. What you can see so far is that my data is coming in the form of a list<double> where the dependent variable is labelled y and the regressors are named reg1,...,reg6 with a count of about a thousand data points. and i want a 2d array so that i can convert to a amtrix and hence do some matrix operations on.

3- The problem:

I am using a cs file (matrix class) produced by Syed Mehroz Alam where the article was produced on this forum titled 'Application of Fraction class: Matrix class in C#'. I will not show his code as I dont think it is appropriate for me to post something produced by someone else without their consent. My problem then becomes when i try running the programme. basically I get an error from the matric class stating:

catch (Exception)
{
throw new FractionException("Conversion not possible");
}

I am not sure what I am doing wrong to get this exception error message from the matrx class. Can anyone please help? Blush | :O
GeneralRe: c# matrix problem Pin
Christian Graus5-Mar-08 23:51
protectorChristian Graus5-Mar-08 23:51 
GeneralWrapper Creation Pin
Rahul.RK5-Mar-08 23:21
Rahul.RK5-Mar-08 23:21 
GeneralCross Post Pin
led mike6-Mar-08 4:51
led mike6-Mar-08 4:51 
General[Message Deleted] Pin
mohit ag5-Mar-08 23:06
mohit ag5-Mar-08 23:06 
GeneralRe: check for special charachter Pin
Christian Graus5-Mar-08 23:21
protectorChristian Graus5-Mar-08 23:21 
GeneralRe: check for special charachter Pin
Giorgi Dalakishvili5-Mar-08 23:24
mentorGiorgi Dalakishvili5-Mar-08 23:24 
GeneralRe: check for special charachter Pin
Christian Graus5-Mar-08 23:49
protectorChristian Graus5-Mar-08 23:49 
GeneralRe: check for special charachter Pin
Pete O'Hanlon6-Mar-08 5:18
mvePete O'Hanlon6-Mar-08 5:18 
GeneralAutomatic Properties Pin
GChannon5-Mar-08 22:58
GChannon5-Mar-08 22:58 
GeneralRe: Automatic Properties Pin
Christian Graus5-Mar-08 23:04
protectorChristian Graus5-Mar-08 23:04 
GeneralRe: Automatic Properties Pin
Robert Rohde6-Mar-08 1:18
Robert Rohde6-Mar-08 1:18 
GeneralRe: Automatic Properties Pin
GChannon6-Mar-08 1:20
GChannon6-Mar-08 1:20 
GeneralRe: Automatic Properties Pin
Pete O'Hanlon6-Mar-08 1:59
mvePete O'Hanlon6-Mar-08 1:59 
GeneralRe: Automatic Properties Pin
MaxRelaxman6-Mar-08 3:09
MaxRelaxman6-Mar-08 3:09 
GeneralRe: Automatic Properties Pin
Pete O'Hanlon6-Mar-08 4:46
mvePete O'Hanlon6-Mar-08 4:46 
GeneralRe: Automatic Properties Pin
led mike6-Mar-08 4:54
led mike6-Mar-08 4:54 
GeneralRe: Automatic Properties Pin
Robert Rohde6-Mar-08 9:11
Robert Rohde6-Mar-08 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.