Question

So im trying to plot f(t) which is a piecewise function using heaviside and ezplot functions in MATLAB. Now im not very familiar with MATLAB at all. If anyone knows why im getting this error it would be helpful.

f = '12+(-2t+8)*heaviside(t-2)+(2t-12)*heaviside(t-6)'

f = 12+(-2t+8)*heaviside(t-2)+(2t-12)*heaviside(t-6)

ezplot(f)

Error using inlineeval (line 15) Error in inline expression ==> 12+(-2t+8).*heaviside(t-2)+(2t-12).*heaviside(t-6) Error: Unexpected MATLAB expression.

Error in inline/feval (line 34) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);

Error in ezplotfeval (line 52) z = feval(f,x(1));

Error in ezplot>ezplot1 (line 469) [y, f, loopflag] = ezplotfeval(f, x);

Error in ezplot (line 145) [hp, cax] = ezplot1(cax, f{1}, vars, labels, args{:});

Was it helpful?

Solution

You need to tell Matlab to multiply explicitly, use 2*t instead of 2t.

syms t real
f = 12+(-2*t+8)*heaviside(t-2)+(2*t-12)*heaviside(t-6)
ezplot(f,[0 10])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top