MATLAB: Having Trouble with My Input Argument!

input error

function output=myfun(x)
x=3
if x<-2
output=-x^2;
elseif (-2<=x)&&(x<0)
output=-2*x;
elseif (0<=x)&& (x<=2)
output=2*x;
elseif x>2
output=x^2;
end

Best Answer

  • function output=myfun(x)
    if x<-2
    output=-x^2;
    elseif -2<=x && x<0
    output=-2*x;
    elseif 0<=x && x<=2
    output=2*x;
    elseif x>2
    output=x^2;
    end