Search code examples
matlabplotmatlab-figure

Graphing problems with a symfun


Currently writing a symfun with one input and three outputs. The equation is exp(x) -3*x.^2 +1. Input is x and the outputs are the equation itself (denoted by f), its first derivative (denoted by fp) and the second derivative (denoted by fpp). Trying to plot these three graphs on the interval [-5 5]. I am using fplot(fun[-5 5]);. The only graph shown is exp(x) -3*x.^2 +1. Any help would be appreciated.


Solution

  • Here is a code for that (no need for hold):

    syms x
    f = symfun(exp(x) -3*x.^2 +1,x);
    fp = diff(f);
    fpp = diff(fp);
    fplot([f,fp,fpp],[-5 5])
    legend({char(f),char(fp),char(fpp)})
    

    you need to put all functions in a vector (i.e. [f,fp,fpp]).

    The output:

    flpot