The error message is usually the result of syntax. When plotting using plot(), you can either give an expression and explicitly state the variable and range, or provide a function/procedure with an implicit range. Please try the following:
restart; f := x -> sin(x); a, b := -Pi, Pi; plot( f(x), a..b ); # "Error, (in plot) procedure expected, as range contains no plotting variable" plot( f, x=a..b ); # "Error, (in plot) expected a range but received x = -Pi .. Pi" plot( f(x), x=a..b ); # no error plot( f, a..b ); # no error
Tips:
-
It is common for users to define a function/procedure from an expression, but then evaluate it to pass as an expression to plot. To be more efficient, though, you can just work with the original expression:
f := x^2; plot( f, x=0..1 );
-
A common pitfall of plotting procedures as an expression is that Maple first evaluates the argument to plot() before substituting values in the range. This can be a problem, for instance, if the procedure needs specific values to compute the output. You can work around this by either using the operator version of plotting, or delaying the evaluation:
f := proc( x :: numeric ) if x >= 0 then return x: else return -x: end if: end proc: plot( f(x), x=0..1 ); # error plot( 'f(x)', x=-1..1 ); # fine plot( f, -1..1 ); # fine