I have an array $A$ having the next 145 values

I would like to calculate the $\frac{dA}{dX}$, having a 1D grid, $x$: 1:286:41468

I use the function gradient:

DA_DX = gradient(A, 41468/145)

I am trying to understand why the $\frac{dA}{dX}$ output graph has peaks which cause problems to my code. Please, do you see something wrong in my steps? Is any other way to calculate the $\frac{dA}{dX}$ without gradient function?


You can calculate the derivative using the diff function and then dividing by the time interval between the "samples" in your vector like this:

dA = diff(A) / 286

The diff() function calculates the difference between an element and the previous one in the vector. With this you'll be calculating the derivative for each element in the vector as the increment in A divided by the increment in x. Check out the help for the diff() for more info.

  • $\begingroup$ the problems is in the region that I have local min and max, so the dA/dx becomes almost zero $\endgroup$ – user1640255 Nov 18 '13 at 0:41
  • $\begingroup$ I don't understand what the problem is. When you have a maximum, minimum or an inflection point the derivative should be zero, or close to zero. What do you mean when you say (in your question) that you have peaks that cause problems to your code? You are calculating the derivative the correct way. $\endgroup$ – Pedro G. Nov 18 '13 at 11:31
  • $\begingroup$ can I sent you the output pictures? Look I calculate the velocity u of a 2nd order nonlinear equation. In two regions u is almost flat. A is the derivative f of the u derivative. The first derivative takes in these regions two small values, and the second derivative have not logical values in these regions, is like noise. $\endgroup$ – user1640255 Nov 19 '13 at 2:31
  • $\begingroup$ Yes, some pictures would help because it is hard to understand your problem without looking at the actual data. You can edit your question and add links to the output pictures. Upload them to an image hosting service like tinypic.com and just paste the link in your question. $\endgroup$ – Pedro G. Nov 19 '13 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.