.NET Matrix Library
DoubleFunction2Dbl Delegate
See Also  "Example" Send comments on this topic


value1
value2
A delegate to a method that takes two double parameters and returns a double.

Syntax

Visual Basic (Declaration) 
Public Delegate Function DoubleFunction2Dbl( _
   ByVal value1 As Double, _
   ByVal value2 As Double _
) As Double
C# 
public delegate double DoubleFunction2Dbl( 
   double value1,
   double value2
)
C++/CLI 
public delegate double DoubleFunction2Dbl( 
   double value1,
   double value2
)

Parameters

value1
value2

Example

The following example uses the ApplyFunction method in order to apply the Math.Sqrt and Math.Round functions to a matrix and it demonstrates also how to apply a custom function to the matrix's elements. The DoubleFunction1DblDoubleFunction1Dbl1Int and DoubleFunction2Dbl delegates are used to represent those functions.
Visual BasicCopy Code
Imports System
Imports Bluebit.MatrixLibrary

Class Test

    Public Shared Sub Main()

        'Declaring a 4x4 Matrix with random elements
        Dim A As New Matrix(4, 4)
        A.FillRandom()
        Console.WriteLine("Matrix A:")
        Console.WriteLine(A)

        'Applying the Math.Sqrt function to A
        Dim dlg1 As New DoubleFunction1Dbl(AddressOf Math.Sqrt)
        Dim B As Matrix = A.ApplyFunction(dlg1)
        'This can also be done without using the delegate
        'Dim B As Matrix = A.ApplyFunction(AddressOf Math.Sqrt)
        Console.WriteLine("Matrix B now contains the square roots of A")
        Console.WriteLine(B)

        'Round the elements of matrix B to 2 decimal digits
        Dim dlg2 As New DoubleFunction1Dbl1Int(AddressOf Math.Round)
        Dim C As Matrix = B.ApplyFunction(dlg2, 2)
        Console.WriteLine("Matrix C = B rounded to 2 decimal digits")
        Console.WriteLine(C)

        'Applying a custom function to matrix A
        Dim dlg3 As New DoubleFunction2Dbl(AddressOf MyCustomFunction1)
        Dim D As Matrix = A.ApplyFunction(dlg3, 1.527)
        'This can also be done without using the delegate
        'Dim D As Matrix = A.ApplyFunction(AddressOf MyCustomFunction1, 1.527)
        Console.WriteLine("D(i,k) = A(i,k) * A(i,k) + 1.527")
        Console.WriteLine(C)

        Console.Read()

    End Sub

    Private Shared Function MyCustomFunction1(ByVal param1 As Double, ByVal param2 As Double) As Double
        Return param1 * param1 + param2
    End Function


End Class
C#Copy Code
using System;
using Bluebit.MatrixLibrary;

class Test
{
    static void Main(string[] args)
    {
        //Declaring a 4x4 Matrix with random elements
        Matrix A = new Matrix(4, 4);
        A.FillRandom();
        Console.WriteLine("Matrix A:");
        Console.WriteLine(A);

        //Applying the Math.Sqrt function to A
        DoubleFunction1Dbl dlg1 = new DoubleFunction1Dbl(Math.Sqrt);
        Matrix B = A.ApplyFunction(dlg1);
        Console.WriteLine("Matrix B now contains the square roots of A");
        Console.WriteLine(B);

        //Round the elements of matrix B to 2 decimal digits
        DoubleFunction1Dbl1Int dlg2 = new DoubleFunction1Dbl1Int(Math.Round);
        Matrix C = B.ApplyFunction(dlg2, 2);
        Console.WriteLine("Matrix C = B rounded to 2 decimal digits");
        Console.WriteLine(C);

        //Applying a custom function to matrix A
        DoubleFunction2Dbl dlg3 = new DoubleFunction2Dbl(MyCustomFunction1);
        Matrix D = A.ApplyFunction(dlg3, 1.527);
        Console.WriteLine("D(i,k) = A(i,k) * A(i,k) + 1.527");
        Console.WriteLine(D);

        Console.Read();
    }

    static double MyCustomFunction1(double param1, double param2)
    {
        return param1 * param1 + param2;
    }

}
C++Copy Code
#include "stdafx.h"

using namespace System;
using namespace Bluebit::MatrixLibrary;

ref class Test
{
    public:
    double static MyCustomFunction1(double param1, double param2)
    {
        return param1 * param1 + param2;
    }
};

int main(array<System::String ^> ^args)
{
    //Declaring a 4x4 Matrix with random elements
    Matrix^ A = gcnew Matrix(4, 4);
    A->FillRandom();
    Console::WriteLine("Matrix A:");
    Console::WriteLine(A);

    //Applying the Math.Sqrt function to A
    DoubleFunction1Dbl^ dlg1 = gcnew DoubleFunction1Dbl(&Math::Sqrt);
    Matrix^ B = A->ApplyFunction(dlg1);
    Console::WriteLine("Matrix B now contains the square roots of A");
    Console::WriteLine(B);
    
    //Round the elements of matrix B to 2 decimal digits
    DoubleFunction1Dbl1Int^ dlg2 = gcnew DoubleFunction1Dbl1Int(&Math::Round);
    Matrix^ C = B->ApplyFunction(dlg2, 2);
    Console::WriteLine("Matrix C = B rounded to 2 decimal digits");
    Console::WriteLine(C);       

    //Applying a custom function to matrix A
    DoubleFunction2Dbl^ dlg3 = gcnew DoubleFunction2Dbl(&Test::MyCustomFunction1);
    Matrix^ D = A->ApplyFunction(dlg3, 1.527);
    Console::WriteLine("D(i,k) = A(i,k) * A(i,k) + 1.527");
    Console::WriteLine(D);

    Console::Read();
    
	return 0;
}

Requirements

Namespace: Bluebit.MatrixLibrary

Platforms: Windows 7, Windows Vista, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows 2000

Assembly: Bluebit.MatrixLibrary (in Bluebit.MatrixLibrary.dll)

See Also

.NET Matrix Library Documentation