1

I am using Advanced Matrix Library in C#. NET@ http://www.codeproject.com/KB/recipes/AdvancedMatrixLibrary.aspx?msg=4042613#xx4042613xx.

library css file is like

using System;

namespace MatrixLibrary
{
public class Matrix
    {
      private double[,] in_Mat;
            public Matrix(int noRows, int noCols)
    {
        this.in_Mat = new double[noRows, noCols];
    }
            public Matrix(double [,] Mat)
    {
        this.in_Mat = (double[,])Mat.Clone();
    }

        public static double[,] Identity(int n)
        {
            double[,] temp = new double[n,n];
            for (int i=0; i<n;i++) temp[i,i] = 1;
            return temp;
        }

public static double[,] ScalarDivide(double Value, double[,] Mat)
    {
        int i, j, Rows, Cols;
        double[,] sol;

        try  {Find_R_C(Mat, out Rows, out Cols);}
        catch{throw new MatrixNullException();}

        sol = new double[Rows+1, Cols+1];

        for (i = 0; i<=Rows;i++)
            for (j = 0; j<=Cols;j++)
                sol[i, j] = Mat[i, j] / Value;

        return sol;
    }


}}

I am trying to get identity matrix and getting error of type conversion. Could some one please guide me.

Matrix id_mat = MatrixLibrary.Matrix.Identity(6);

Can't implicity convert typedouble[,] to Matrix.

But

Matrix B = new Matrix(4, 4);
 Random rnd = new Random();
            for (int i = 0; i < B.NoRows; i++)
                for (int j = 0; j < B.NoCols; j++)
                    B[i, j] = 2 * rnd.NextDouble();

Matrix E = Matrix.ScalarDivide(2, B);

It works and I can Have a matrix. Please guide me?

regards,

1
  • Your returning a double[,] but the variable your assigning it to is of Matrix type. Without more code it's hard to say but you probably want to return a Matrix type filled in with the double array. Commented Oct 4, 2011 at 14:14

3 Answers 3

2

Read the error message.

You have a method that returns double[,] and you are trying to store the reference in a variable for Matrix. There is no implicit conversion from a multidimensional array of doubles to a Matrix.

To use that method, you would write

double[,] id_max = MatrixLibrary.Maxtrix.Identify(6);

If you actually need to store it as a Matrix, you need to define the appropriate conversion to do so.

Sign up to request clarification or add additional context in comments.

Comments

0

The function returns a 2D array "double[,]" and you're trying to assign it to a "Matrix". There isn't an implicit conversion that does this. Does Matrix have a constructor that accepts a "double[,]"? Maybe you could use that.

EDIT: You might also find that a different matrix library would suit you better than one pulled off of CodeProject. Math.NET Numerics is a good one that I've used that's also open source: http://numerics.mathdotnet.com/

Comments

0

You need an implicit cast.

public static implicit operator Matrix(double[,] m) 
{
  // code to convert 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.