# Calculation error in bilinear transformation with alglib in C#

For a project I am trying a transformation from the z-transforms to s-transforms. For this I wrote the code that uses the bilinear transformation and checked the results with Matlab. Unfortunately they are wrong and I don't see the error. Maybe someone can help me on the hint.

```
public double[] BiliTransf(double[] a, double Ts)
{
int n = a.Length;
double[] bil_p = { 2, Ts };
double[] bil_m = { 2, -Ts };
init[0] = 1;
for (int i = 1; i < n; i++)
{
init[i] = 0;
}
int j;
for (int i=0; i<n; i++)
{
// (1+s)^i
s_p = init;
for (j = 0; j < i; j++)
{
alglib.convr1d(s_p, 1+j, bil_p, 2, out s2_p);
s_p = s2_p;
}
// (1-s)^n-1-i
s_m = init;
for (j = 0; j < n-1-i; j++)
{
alglib.convr1d(s_m, 1+j, bil_m, 2, out s2_m);
s_m = s2_m;
}
// s_m * s_p
alglib.convr1d(s_m, s_m.Length, s_p, s_p.Length, out s2_m);
VektorMulti(ref s2_m, a[n-1-j]);
VektorAddV2ToV1(ref a_cont, ref s2_m);
}
return a_cont;
}
```

Call C# Fbk:

```
a_tf = sv.BiliTransf(new double { 1, 0.5, 0.1}, 0.05);
a_tf[0]/a_tf[0] ; a_tf[0]/a_tf[1] ; a_tf[0]/a_tf[2]);
```

Result: a0: 1 / a1: -35,56 / a2: 4266,67

Call Matlab:

```
H = tf([1 0.5 0.1],[1 0.5 0.1 ],0.05)
sysc = d2c(H, 'tustin')
```

Result: a0: 1 / a1: 120/ a2: 4267