Can I use "not" as a discrete Dirac delta function in Matlab?

Can I use not as a discrete delta dirac function in Matlab?

The definition for the discrete Dirac delta function is that for argument 0 it returns 1, and otherwise it returns 0. But this is the same as the not function in Matlab!

Do you see any problems if I use not instead of writing my own delta dira function? I know that Matlab has a dirac function, but this is a continuous version - it returns infinity for 0 instead of 1.

+6
source share
3 answers

I think everything is fine, but note that the output of not is a logical s array:

Example:

 a = [0, 1, pi] b = not(a) c = double(b) whos 

Output:

 a = 0.00000 1.00000 3.14159 b = 1 0 0 c = 1 0 0 Variables in the current scope: Attr Name Size Bytes Class ==== ==== ==== ===== ===== a 1x3 24 double b 1x3 3 logical c 1x3 24 double Total is 9 elements using 51 bytes 

So, if the inputs are double s, I would define the discrete Dirac delta function as follows:

 ddirac = @(x) double(not(x)); 

or

 function y = ddelta(x) y = double(not(x)); 
+7
source

For clarity, I would define

 diracdelta = @not; 

so that it is clear in the code that you want to use the delta function of the dirac, and not make a logical negation. When you review your code after six months, you will thank me for additional clarity.

+6
source

As if quickly, if you try to evaluate this (or any Dirac function) for numbers with a large number of significant digits, it will not be correctly evaluated due to (im) the precision of the floating point numbers.

 x = [-2e-6:0.5e-6:2e-6] y = (x - 0.5e-6) ~y 

However, the element x, which appears to be zero, will not be zero.

 y(6) = 1.0588e-22 

Therefore, I propose a function that will return 1 if x is really, really close to zero; closer than floating point precision:

  epsdirac = @(x) double(abs(x) < eps) 
0
source

Source: https://habr.com/ru/post/952218/


All Articles