# NMath User's Guide

25.1 Creating Multivariate Functions (.NET, C#, CSharp, VB, Visual Basic, F#)

A is constructed from a Func<DoubleVector, double>, a delegate that takes a single DoubleVector parameter and returns a double. For example, suppose you wish to encapsulate this function:

Code Example – C# multivariate functions

```public double MyFunction( DoubleVector v )
```
```{
```
```     return ( NMathFunctions.Sum( v * v ) );
```
```}
```

Code Example – VB multivariate functions

```Function MyFunction(V As DoubleVector) As Double
```
```  Return (NMathFunctions.Sum(V * V))
```
```End Function
```

First, create a delegate for the MyFunction() method:

Code Example – C# multivariate functions

```var d = new Func<DoubleVector, double>( MyFunction );
```

Code Example – VB multivariate functions

```Dim D As New Func(Of DoubleVector, Double)(AddressOf MyFunction)
```

Then construct a MultiVariableFunction encapsulating the delegate:

Code Example – C# multivariate functions

```var f = new MultiVariableFunction( d );
```

Code Example – VB multivariate functions

```Dim F As New MultiVariableFunction(D)
```

A Func<DoubleVector, double> is also implicitly converted to a MultiVariableFunction. Thus:

Code Example – C# multivariate functions

```MultiVariableFunction f = d;
```

Code Example – VB multivariate functions

```Dim F = D
```

Class MultiVariableFunction provides a Function property that gets the encapsulated function delegate after construction.

Top

Top