To find the n-th order derivative of a function f(x) in MATLAB, you can use the diff function n times.
For example, if we have the function f(x) = x^3 + 2x^2 + 3x + 4, and we want to find its second derivative, we can do the following:
main.m170 chars5 lines
The diff function takes two arguments: the function you want to differentiate, and the variable of differentiation (in our case, x). The output is the derivative of the function with respect to x.
We can also find the n-th order derivative using a loop, like this:
main.m249 chars8 lines
Here, we initialize the derivative as the original function f, and then use a loop to differentiate it n times.
Note that we first need to declare x as a symbolic variable using the syms function, so that MATLAB knows we are working with a mathematical expression, not just a set of numbers.
gistlibby LogSnag