简体   繁体   中英

Changing the Heaviside function at origin

is there any way to change the value of heaviside function at zero in matlab 2014b? because I have to change the value from 0.5 to 1.

You can use the 'HeavisideAtOrigin' preference of sympref to set a custom value at the origin:

sympref('HeavisideAtOrigin',1);
one = heaviside(-1:1)
sympref('HeavisideAtOrigin',0.5);
pointFive= heaviside(-1:1)

...

one =

     0     1     1


pointFive =

         0    0.5000    1.0000

The above was introduced in R2015a . For pre-R2015a, you'll have to build your own fix for this, eg:

% heavisideOrigin1.m
function y = heavisideOrigin1(x)
    y = round(heaviside(x));
end

% ...
y = heavisideOrigin1(-1:1)

% prints
y =

     0     1     1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM