Search code examples
linuxplotgraphoctaveequation

Plotting graphs of differentiated functions on Octave


I learnt how to differentiate on octave through this. But I now want to plot graph of the same function on octave. I am not able to do so. I want to know what the right command for plotting the 'ffd' equation in the code is.

`f = @(x) x.^2 + 3*x - 1 + 5*x.*sin(x);
   pkg load symbolic
   syms x;
   ff = f(x);
   ffd = diff(ff, x)  `

What I have tried so far: I have tried adding these lines of code to the end and it didn't work. The graph was empty and I got an error.

 real

ffd = (sym) 5⋅x⋅cos(x) + 2⋅x + 5⋅sin(x) + 3
error: __go_line__: invalid value for array property "ydata", unable to create graphics handle
error: called from
__plt__\>__plt2vs__ at line 466 column 15
__plt__\>__plt2__ at line 245 column 14
__plt__ at line 112 column 18
plot at line 229 column 10
real at line 10 column 1\`

I was expecting it to plot the graph of (sym) 5⋅x⋅cos(x) + 2⋅x + 5⋅sin(x) + 3 i.e., ffd, but it didn't work


Solution

  • In order to draw graphs of the differentiated functions we need to have code similar to this and in this case I am using pkg symbolic

      pkg load symbolic
      syms x;
    
      x = sym('x');
      y = @(x) x.^3;
      yy = y(x);
      ffd = diff(diff(yy,x));
      ffe = diff(yy,x);
      ez1=ezplot(y,[-10,10])
      hold on
      ez2=ezplot(ffe,[-10,10])
      hold on 
      ez3=ezplot(ffd,[-10,10])
      
    

    note: hold on function is used to draw more than one graphs on the same screen. However, if you modify the program and run it again it doesn't clear the screen of the previous graphs, if anyone knows how to do this, please leave a comment.