This project is read-only.
2

Closed

Can't calculate this det(({{1, 3}, {2, 4}}*2))

description

Hey Dmitry,

Why I can't calculate this?
It raises an exception.

Edit:
I've fixed it with modification of the Determinate-Class. I should do this also for Transpose and Inverse.
Another thing was the implementation of the ToString()-Method of these matrix-functions.
    public override object Calculate(ExpressionParameters parameters)
    {
        if (argument is Matrix) {
            return ((Matrix)argument).Determinant (parameters);
        } else {
            return ((Matrix)argument.Calculate (parameters)).Determinant (parameters);
        }
    }
Here is my Transpose-Calculate-Method
    public override object Calculate(ExpressionParameters parameters)
    {
        var vector = argument as Vector;
        if (vector != null)
            return vector.Transpose();
        var matrix = argument as Matrix;
        if (matrix != null)
            return matrix.Transpose();

        var arg = argument.Calculate (parameters);
        matrix = arg as Matrix;
        if (matrix != null)
            return matrix.Transpose ();

        vector = arg as Vector;
        if (vector != null)
            return vector.Transpose ();

        throw new NotSupportedException();
    }
And here is my Abs-Calculation of a Vector. Sorry, at the Moment I can't do a pull request.
    /// <summary>
    /// Calculates this Absolute expression.
    /// </summary>
    /// <param name="parameters">An object that contains all parameters and functions for expressions.</param>
    /// <returns>
    /// A result of the calculation.
    /// </returns>
    /// <seealso cref="ExpressionParameters" />
    public override object Calculate (ExpressionParameters parameters) {
        if (argument is Vector) {
            return AbsVector ((Vector)argument, parameters);
        } else {
            var arg = argument.Calculate (parameters);
            if (arg is Double)
                return Math.Abs ((double)arg);
            else if (arg is Vector) {
                return AbsVector ((Vector)arg, parameters);
            }
        }
        throw new NotSupportedException ();
    }

    static double AbsVector ( Vector vec, ExpressionParameters parameters ) {
        var sum = 0.0;
        foreach (var a in vec.Arguments)
            sum += Math.Pow (
                (double)a.Calculate (parameters), 2);

        return Math.Sqrt (sum);
    }

Regards
Ronny
Closed May 30, 2014 at 8:34 AM by sys_27

comments

sys_27 wrote May 29, 2014 at 5:08 PM

I'll fix it. Need to change a few lines.

sys_27 wrote May 29, 2014 at 6:15 PM

Fixed.