How to use heaviside function in Octave/Matlab?

496 Views Asked by At

I am just trying to plot a simple function. Why doesn't it work? In Octave it says "syntax error" and points to the plot(x,y). Matlab complains about unbalanced parenthesis.

a=1
x=-2:0.1:2;
A=1;
B=1;
k=1;

figure(1)
y=heaviside(a-x).*A.*exp(k*x)...
+(heaviside(x+a)-heaviside(x-a)).*(B*(exp(k*x)+exp(-k*x)))...
+heaviside(x-a).*A*exp(-k*x)

/Edited: Removed simple parenthesis balancing error
Matlab error:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function
first to substitute values for variables.

Octave error:
error: __go_line__: invalid value for array property "xdata", unable to create graphics handle
error: called from
    __plt__>__plt2ss__ at line 365 column 10