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

  • Context: MATLAB 
  • Thread starter Thread starter mech-eng
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
SUMMARY

The discussion addresses an error encountered while using the MATLAB function ezplot with the expression d = x^2 - 6*x - 12. The error arises because the input is neither a valid function handle nor a string, which are the required formats for ezplot. The correct implementations are provided: using a function handle d = @(x) x.^2 - 6.*x - 12; or a string d = 'x^2 - 6*x - 12'; to successfully plot the function.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with function handles in MATLAB
  • Knowledge of plotting functions in MATLAB
  • Basic algebraic manipulation of expressions
NEXT STEPS
  • Learn how to create and use function handles in MATLAB
  • Explore the ezplot function documentation for advanced usage
  • Investigate other MATLAB plotting functions such as fplot and plot
  • Understand error handling in MATLAB to troubleshoot common issues
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly students and professionals in engineering and data analysis, who are looking to effectively plot mathematical functions and troubleshoot related errors.

mech-eng
Messages
826
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 ·
Replies
1
Views
5K
  • · Replies 8 ·
Replies
8
Views
14K
Replies
7
Views
9K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 12 ·
Replies
12
Views
16K
  • · Replies 3 ·
Replies
3
Views
28K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K