Exemple #1
0
    public virtual Matrix invert()
    {
        Algebraic _det = det();

        if (_det.Equals(Zahl.ZERO))
        {
            throw new JasymcaException("Matrix not invertible.");
        }
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a.Length];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a.Length);
        if (a.Length == 1)
        {
            b[0][0] = Zahl.ONE.div(_det);
        }
        else
        {
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    b[i][k] = unterdet(k, i).div(_det);
                }
            }
        }
        return(new Matrix(b));
    }
Exemple #2
0
    public virtual Algebraic unterdet(int i, int k)
    {
        if (i < 0 || i > a.Length || k < 0 || k > a[0].Length)
        {
            throw new JasymcaException("Operation not possible.");
        }
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length-1][a[0].Length-1];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length - 1, a[0].Length - 1);
        int           i1, i2, k1, k2;

        for (i1 = 0, i2 = 0; i1 < a.Length - 1; i1++, i2++)
        {
            if (i2 == i)
            {
                i2++;
            }
            for (k1 = 0, k2 = 0; k1 < a[0].Length - 1; k1++, k2++)
            {
                if (k2 == k)
                {
                    k2++;
                }
                b[i1][k1] = this.a[i2][k2];
            }
        }
        Algebraic u = (new Matrix(b)).det2();

        if ((i + k) % 2 == 0)
        {
            return(u);
        }
        return(u.mult(Zahl.MINUS));
    }
Exemple #3
0
    public virtual Algebraic col(int k)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] c = new Algebraic[a.Length][1];
        Algebraic[][] c = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, 1);
        for (int i = 0; i < a.Length; i++)
        {
            c[i][0] = a[i][k - 1];
        }
        return((new Matrix(c)).reduce());
    }
Exemple #4
0
    public Matrix(Algebraic x, int nrow, int ncol)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: this.a = new Algebraic[nrow][ncol];
        this.a = RectangularArrays.ReturnRectangularAlgebraicArray(nrow, ncol);
        for (int i = 0; i < nrow; i++)
        {
            for (int k = 0; k < ncol; k++)
            {
                a[i][k] = x;
            }
        }
    }
Exemple #5
0
    public virtual Matrix adjunkt()
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a[0].Length][a.Length];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a[0].Length, a.Length);
        for (int i = 0; i < a.Length; i++)
        {
            for (int k = 0; k < a[0].Length; k++)
            {
                b[k][i] = a[i][k].cc();
            }
        }
        return(new Matrix(b));
    }
Exemple #6
0
    public override Algebraic map(LambdaAlgebraic f)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] cn = new Algebraic[a.Length][a[0].Length];
        Algebraic[][] cn = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
        for (int i = 0; i < a.Length; i++)
        {
            for (int k = 0; k < a[0].Length; k++)
            {
                cn[i][k] = f.f_exakt(a[i][k]);
            }
        }
        return(new Matrix(cn));
    }
Exemple #7
0
    public override Algebraic value(Variable @var, Algebraic x)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a[0].Length];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
        for (int i = 0; i < a.Length; i++)
        {
            for (int k = 0; k < a[0].Length; k++)
            {
                b[i][k] = a[i][k].value(@var, x);
            }
        }
        return(new Matrix(b));
    }
Exemple #8
0
    public static Matrix eye(int nr, int nc)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[nr][nc];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(nr, nc);
        for (int i = 0; i < nr; i++)
        {
            for (int k = 0; k < nc; k++)
            {
                b[i][k] = (i == k ? Zahl.ONE : Zahl.ZERO);
            }
        }
        return(new Matrix(b));
    }
Exemple #9
0
    public Matrix(double[][] b, int nr, int nc)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: a = new Algebraic[nr][nc];
        a  = RectangularArrays.ReturnRectangularAlgebraicArray(nr, nc);
        nr = Math.Min(nr, b.Length);
        nc = Math.Min(nc, b[0].Length);
        for (int i = 0; i < nr; i++)
        {
            for (int k = 0; k < nc; k++)
            {
                a[i][k] = new Unexakt(b[i][k]);
            }
        }
    }
Exemple #10
0
    public virtual Matrix copy()
    {
        int nr = nrow(), nc = ncol();

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[nr][nc];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(nr, nc);
        for (int i = 0; i < nr; i++)
        {
            for (int k = 0; k < nc; k++)
            {
                b[i][k] = a[i][k];
            }
        }
        return(new Matrix(b));
    }
Exemple #11
0
    public override Algebraic div(Algebraic x)
    {
        if (x.scalarq())
        {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a[0].Length];
            Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    b[i][k] = a[i][k].div(x);
                }
            }
            return(new Matrix(b));
        }
        return(mult((new Matrix(x)).pseudoinverse()));
    }
Exemple #12
0
    public override Algebraic map(LambdaAlgebraic f, Algebraic arg2)
    {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a[0].Length];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
        if (arg2 is Matrix && equalsized((Matrix)arg2))
        {
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    Algebraic c = ((Matrix)arg2).get(i, k);
                    object    r = a[i][k].map(f, c);
                    if (r is Algebraic)
                    {
                        b[i][k] = (Algebraic)r;
                    }
                    else
                    {
                        throw new JasymcaException("Cannot evaluate function to algebraic.");
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    object r = a[i][k].map(f, arg2);
                    if (r is Algebraic)
                    {
                        b[i][k] = (Algebraic)r;
                    }
                    else
                    {
                        throw new JasymcaException("Cannot evaluate function to algebraic.");
                    }
                }
            }
        }
        return(new Matrix(b));
    }
Exemple #13
0
    internal virtual void remove_col(int i)
    {
        if (i >= ncol())
        {
            return;
        }
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[nrow()][ncol()-1];
        Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(nrow(), ncol() - 1);
        for (int j = 0; j < nrow(); j++)
        {
            for (int k = 0; k < i; k++)
            {
                b[j][k] = a[j][k];
            }
            for (int k = i + 1; k < ncol(); k++)
            {
                b[j][k - 1] = a[j][k];
            }
        }
        a = b;
    }
Exemple #14
0
    public override Algebraic add(Algebraic x)
    {
        if (x.scalarq())
        {
            x = x.promote(this);
        }
        if (x is Matrix && equalsized((Matrix)x))
        {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a[0].Length];
            Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    b[i][k] = a[i][k].add(((Matrix)x).a[i][k]);
                }
            }
            return(new Matrix(b));
        }
        throw new JasymcaException("Wrong arguments for add:" + this + "," + x);
    }
Exemple #15
0
    public override Algebraic mult(Algebraic x)
    {
        if (x.scalarq())
        {
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][a[0].Length];
            Algebraic[][] b = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, a[0].Length);
            for (int i = 0; i < a.Length; i++)
            {
                for (int k = 0; k < a[0].Length; k++)
                {
                    b[i][k] = a[i][k].mult(x);
                }
            }
            return(new Matrix(b));
        }
        Matrix xm = new Matrix(x);

        if (ncol() != xm.nrow())
        {
            throw new JasymcaException("Matrix dimensions wrong.");
        }
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] b = new Algebraic[a.Length][xm.a[0].Length];
        Algebraic[][] b1 = RectangularArrays.ReturnRectangularAlgebraicArray(a.Length, xm.a[0].Length);
        for (int i = 0; i < a.Length; i++)
        {
            for (int k = 0; k < xm.a[0].Length; k++)
            {
                b1[i][k] = a[i][0].mult(xm.a[0][k]);
                for (int l = 1; l < xm.a.Length; l++)
                {
                    b1[i][k] = b1[i][k].add(a[i][l].mult(xm.a[l][k]));
                }
            }
        }
        return(new Matrix(b1));
    }
Exemple #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static Vektor horowitz(Algebraic p, Polynomial q, Variable x) throws JasymcaException
    public static Vektor horowitz(Algebraic p, Polynomial q, Variable x)
    {
        if (Poly.degree(p, x) >= Poly.degree(q, x))
        {
            throw new JasymcaException("Degree of p must be smaller than degree of q");
        }
        p = p.rat();
        q = (Polynomial)q.rat();
        Algebraic d = Poly.poly_gcd(q, q.deriv(x));
        Algebraic b = Poly.polydiv(q, d);
        int       m = b is Polynomial? ((Polynomial)b).degree():0;
        int       n = d is Polynomial? ((Polynomial)d).degree():0;

        SimpleVariable[] a = new SimpleVariable[m];
        Polynomial       X = new Polynomial(x);
        Algebraic        A = Zahl.ZERO;

        for (int i = a.Length - 1; i >= 0; i--)
        {
            a[i] = new SimpleVariable("a" + i);
            A    = A.add(new Polynomial(a[i]));
            if (i > 0)
            {
                A = A.mult(X);
            }
        }
        SimpleVariable[] c = new SimpleVariable[n];
        Algebraic        C = Zahl.ZERO;

        for (int i = c.Length - 1; i >= 0; i--)
        {
            c[i] = new SimpleVariable("c" + i);
            C    = C.add(new Polynomial(c[i]));
            if (i > 0)
            {
                C = C.mult(X);
            }
        }
        Algebraic r = Poly.polydiv(C.mult(b).mult(d.deriv(x)), d);

        r = b.mult(C.deriv(x)).sub(r).add(d.mult(A));
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: Algebraic[][] aik = new Algebraic[m+n][m+n];
        Algebraic[][] aik = RectangularArrays.ReturnRectangularAlgebraicArray(m + n, m + n);
        Algebraic     cf; Algebraic[] co = new Algebraic[m + n];

        for (int i = 0; i < m + n; i++)
        {
            co[i] = Poly.coefficient(p, x, i);
            cf    = Poly.coefficient(r, x, i);
            for (int k = 0; k < m; k++)
            {
                aik[i][k] = cf.deriv(a[k]);
            }
            for (int k = 0; k < n; k++)
            {
                aik[i][k + m] = cf.deriv(c[k]);
            }
        }
        Vektor s = LambdaLINSOLVE.Gauss(new Matrix(aik), new Vektor(co));

        A = Zahl.ZERO;
        for (int i = m - 1; i >= 0; i--)
        {
            A = A.add(s.get(i));
            if (i > 0)
            {
                A = A.mult(X);
            }
        }
        C = Zahl.ZERO;
        for (int i = n - 1; i >= 0; i--)
        {
            C = C.add(s.get(i + m));
            if (i > 0)
            {
                C = C.mult(X);
            }
        }
        co    = new Algebraic[2];
        co[0] = C.div(d);
        co[1] = A.div(b);
        return(new Vektor(co));
    }