Search code examples
matlabgraphing

Plotting an equation from string form - MATLAB


I have an expression like this:

x = [40 50];
expression = -2.254443e-02*x^4 + 1.797023e+02*x^3 + -5.364190e+05*x^2 + 7.107614e+08*x + -3.527500e+11;

Now how do I plot this?

plot(x, expression)

Causes errors.


Solution

  • Use ezplot to plot from an expression string:

    x = [40 50];
    expression = '-2.254443e-02*x^4 + 1.797023e+02*x^3 + -5.364190e+05*x^2 + 7.107614e+08*x + -3.527500e+11';
    ezplot(expression, x);
    

    Please note the addition of single quotes around the expression to turn it into a string!