zufryy
zufryy

Reputation: 187

How to get first derivation of equation in matlab

if i have function f(x,y,z), how to get first derivation of my function in matlab.

f'=df(x,y,z)/d(x,y)

Is it true if I use this method f' = diff(f,x) + diff(f,y) ?

Upvotes: 0

Views: 2608

Answers (2)

Jonas
Jonas

Reputation: 74940

If f(x,y,z) allows you to create a 2D array such that an element i,j of the array is the value of z corresponding to a coordinate pair xi,yj, then yes, you can use diff for the numeric difference.

Note that in your case, you need to specify three inputs to DIFF, as the second input is the order of the difference, not the dimension. Also, diff gives you the difference. To get the correct value of the derivative, you need to divide by the step size in your x and y value as well (unless the coordinates increment by 1).

Upvotes: 1

eykanal
eykanal

Reputation: 27047

You answered your own question; so long as the f(x,y,z) function outputs an M x N vector/matrix, you can use the diff function to obtain the numerical solution to derivative (as opposed to the analytical solution). The number of variables used to create the matrix isn't important.

Do note that if you're working on a matrix, you will have to consider the direction of the derivative.

Upvotes: 1

Related Questions