MATLAB Matlab Help: EZplot for x^2 – 6x – 12

  • Thread starter Thread starter mech-eng
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion revolves around an error encountered while using the MATLAB function ezplot to graph a quadratic equation defined as d = x^2 - 6*x - 12. The error message indicates that the input character is invalid, which stems from the incorrect format of the equation. To resolve this, the equation must be defined either as a function handle or as a string. The correct formats are provided: using a function handle with d = @(x) x.^2 - 6.*x - 12; or as a string with d = 'x^2 - 6*x - 12'; both of which can be successfully plotted using ezplot. The discussion emphasizes the importance of adhering to MATLAB's syntax requirements for plotting functions.
mech-eng
Messages
825
Reaction score
13
d = x^2 –6*x – 12;

>> ezplot(d)
Error using inlineeval (line 15)
Error in inline expression ==> x.^2 –6.*x – 12
Error: The input character is not valid in MATLAB statements or
expressions.

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{:});


what is the problem here?
 
Physics news on Phys.org
From the doc:

"ezplot(fun) plots the expression fun(x) over the default domain -2π < x < 2π, where fun(x) is an explicit function of only x.

fun can be a function handle or a string."

What you input is neither a function handle:

d = @(x) x.^2 - 6.*x -12;
ezplot(d)nor a string:

d = 'x^2 - 6*x-12';
ezplot(d)

http://www.mathworks.com/help/matlab/ref/ezplot.html
 

Similar threads

Replies
1
Views
5K
Replies
8
Views
14K
Replies
12
Views
16K
Replies
3
Views
27K
Replies
2
Views
6K
Back
Top