Beispiel #1
0
            public void adding_null_vector_throws()
            {
                var     left  = new VectorD(3);
                VectorD right = null;

                Assert.Throws <ArgumentNullException>(() => left.Add(right));
            }
Beispiel #2
0
            public void adding_vectors_of_different_size_throws()
            {
                var left  = new VectorD(3);
                var right = new VectorD(4);

                Assert.NotEqual(left.Dimensions, right.Dimensions);

                Assert.Throws <ArgumentOutOfRangeException>(() => left.Add(right));
            }
Beispiel #3
0
    public static VectorD operator /(VectorD a, float b)
    {
        VectorD result = new VectorD();

        for (int i = 0; i < a.Count; ++i)
        {
            result.Add(a[i] / b);
        }

        return(result);
    }
Beispiel #4
0
    public static VectorD operator *(float a, VectorD b)
    {
        VectorD result = new VectorD();

        for (int i = 0; i < b.Count; ++i)
        {
            result.Add(a * b[i]);
        }

        return(result);
    }
Beispiel #5
0
    public static VectorD operator +(VectorD a, VectorD b)
    {
        Debug.Assert(a.Count == b.Count);

        VectorD result = new VectorD();

        for (int i = 0; i < a.Count; ++i)
        {
            result.Add(a[i] + b[i]);
        }

        return(result);
    }
Beispiel #6
0
            public void can_add_vectors_of_same_size()
            {
                var actual = new VectorD(3);

                actual.Set(0, 1);
                actual.Set(1, 3);
                actual.Set(2, -4);
                var right = new VectorD(3);

                right.Set(0, -10);
                right.Set(1, 4);
                right.Set(2, -20);
                var expected = new VectorD(3);

                expected.Set(0, -9);
                expected.Set(1, 7);
                expected.Set(2, -24);

                actual.Add(right);

                Assert.Equal(expected, actual);
            }
Beispiel #7
0
        static void Main()
        {
            M2k ctx = libm2k.m2kOpen();

            ctx.calibrateADC();
            ctx.calibrateDAC();

            M2kAnalogIn        ain  = ctx.getAnalogIn();
            M2kAnalogOut       aout = ctx.getAnalogOut();
            M2kHardwareTrigger trig = ain.getTrigger();

            // Setup analog in
            ain.enableChannel(0, true);
            ain.enableChannel(1, true);
            ain.setSampleRate(100000);
            ain.setRange((ANALOG_IN_CHANNEL)0, -10.0, 10.0); // nu are idxchannel
            ain.setRange((ANALOG_IN_CHANNEL)1, M2K_RANGE.PLUS_MINUS_25V);

            // Uncomment the following block to enable triggering
            // trig.setAnalogSource(M2K_TRIGGER_SOURCE.CHANNEL_1);
            // trig.setAnalogCondition(0, M2K_TRIGGER_CONDITION.RISING_EDGE);
            // trig.setAnalogLevel(0, 0.5);
            // trig.setAnalogDelay(0);
            // trig.setAnalogMode(0, M2K_TRIGGER_MODE.ALWAYS);

            // setup analog output
            aout.setSampleRate(0, 750000);
            aout.setSampleRate(1, 750000);
            aout.enableChannel(0, true);
            aout.enableChannel(1, true);

            // create output buffers
            var ch1  = new VectorD();
            var ch2  = new VectorD();
            var both = new VectorVectorD();

            for (int i = 0; i < 1024; i++)
            {
                double val = 4.0;
                ch1.Add(val);
                ch2.Add(3.0);
            }

            both.Add(ch1);
            both.Add(ch2);

            aout.setCyclic(true);
            aout.push(both);

            var data = ain.getSamples(1024);

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(data[0][i] + " ");
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(data[1][i] + " ");
            }

            aout.stop();
            libm2k.contextClose(ctx);
        }