MATLAB: How to change the heaviside function — and how to use the new function with symbolic objects

changefunctions function syms mupad mapleheavisideheaviside functionMATLABsymbolic math

Hi.
I created this function (it is equal to the heaviside function):
function Y = fzine( X )
Y = zeros(size(X));
Y(X > 0) = 1;
eng = symengine;
if strcmp(eng.kind,'maple')
Y(X == 0) = nan;
else
Y(X == 0) = 0;
end
Now, why if
syms x
I get:
>> heaviside(x)
ans =
heaviside(x)
BUT
>> fzine(x) ??? Error using ==> sym.sym>notimplemented at 2621 Function 'gt' is not implemented for MuPAD symbolic objects.
Error in ==> sym.sym>sym.gt at 801 notimplemented('gt');
Error in ==> fzine at 7 Y(X > 0) = 1;
The two functions (fzine and heaviside) share the same code…?

Best Answer

Yes...
and using heaviside is very fast, I wrote also this (very fast):
function Y = fzine( X )
%FZINE Summary of this function goes here
% Restituisce 0 quando X<0 oppure X==0
% Restituisce 1 quando X>0
Y = heaviside(X);
if Y==0.5
Y=0;
end