Tuesday, 2 February 2016

Using the gradient function

Let's say you have some data in a range, vector array or matrix. This can be plotted really easily in Octave. Let's plot y = x^2:


>> x = 0:10
x =

    0    1    2    3    4    5    6    7    8    9   10

>> y = x.^2
y =

     0     1     4     9    16    25    36    49    64    81   100

>> plot(x,y)


Now you'd like to plot the slope of this graph of y=x^2

>> z = gradient(y)
z =

    1    2    4    6    8   10   12   14   16   18   19

>> plot(x,y,z)

No comments:

Post a Comment