# Gauss solver for IIR filter

I write a piece of code in online GDB using c++, the code calculates some coefficients for a IIR filter which tries to approximate a fractional derivative and integral for a fractional PID control. The code works as expected in the online IDE, but when I try to execute it in a Arduino Due, the results and only overflows and nan, and really don't know what's the problem so,

Here is the code in GDB online https://onlinegdb.com/rycwt62XL which gives the expected results:

Array A, Array B

1.41421,1

-0.707107,0.5

-2.12132,-1.5

0.883883,-0.625

0.883883,0.625

-0.265165,0.1875

-0.0883883,-0.0625

0.0110485,-0.0078125

And here is the code for the Arduino Due, which only change the printing method using the serial commands, https://onlinegdb.com/ByAs5xyVU, and the results are:

Array A, Array B

ovf,1.00

ovf,ovf

ovf,0.00

inf,ovf

ovf,0.00

inf,ovf

ovf,3.89

inf,ovf

And really don't know where to start for fix this results, thanks. The Method is exactly the same.

• Works fine on every piece of hardware I have tested, except the Due. I've never liked the Due - the compilation has always been really really shaky... – Majenko Feb 22 '20 at 20:03
• Majenko, I tested on the arduino Mega and works really well, but I've donde all the programming in the Due, but thanks – user2461687 Feb 22 '20 at 22:48

I can't find the root cause of the problem - it's probably because the Due is possibly the worst board that Arduino ever made, and the compiler / linker / support libraries barely work at the best of times.

However, some things you need to look at in your code:

``````    double* h = new double[L];
for(int n = 0; n <= L; n++){
for(int k = 0; k <= n; k++){
}
}
``````

There you allocate `L` (15) doubles in an array. But then you go on to access array slices 0-15. That's 16 entries in an array of size 15, so you're overflowing it and corrupting other memory.

Also you have no `delete` to balance the `new`, so you have a memory leak. You would be better using:

``````double h[L+1];
``````

instead of `new`.

• You are right, I avoid using arrays with variable size and works, thanks so much – user2461687 Feb 22 '20 at 23:22