Differentiation in 2D for Non Uniformly Distributed Data

19 views (last 30 days)
Hello, My problem is quite simple, I think, but I cannot find a solution.
I have a 2d scatter plot of an electric field. So basically I have a nx3 matrix, let's call it M, where the 2 first columns are the x and y coordinates, and the 3rd column is a value between 0 and 1 Volts.
So I basically plot this as: scatter(M(:,1),M(:,2),5,M(:,3));
I would like to calculate the second order spatial derivative of this electric field in 2 Dimensions. But I don't know how to do that. I tried using the gradient function, but this doesn't work. I think this is due to the fact that my 2D space is not uniformly distributed (it was exported by a FEA in COMSOL).
Thank you in advance for your help.
Julia
  2 Comments
Alberto
Alberto on 10 Apr 2014
Edited: Alberto on 10 Apr 2014
Hi Julia:
in a function like that, second order derivatives is the Hessian matrix. There are formulas for obtain the second order partial derivatives, I`m afraid you will have to implement them by yourself.
For example, for the first derivative, and you have the nodes x_0, x_1 and x_2:
f'(x_1)= [f(x_2) - f(x_0)]/(x_2 - x_0)
This first derivative aproximation doesn't need the spaces between the nodes. Once you have the functions derived, you can derived again in the same variable or the other one.
Julia
Julia on 10 Apr 2014
Hello,
Thank you for your quick response!
Indeed, I should compute the Hessian matrix. However, I will get a 2x2 Matrix. How do I plot this? Do I plot the norm of the matrix?
Thank you for your help!

Sign in to comment.

Answers (2)

Andrew Newell
Andrew Newell on 10 Apr 2014
Edited: Andrew Newell on 10 Apr 2014
Before using finite difference formulae, you should use TriScatteredInterp to create a gridded data set. You can't use the gradient function because it applies to functions, not fixed data points. Once you have obtained the Hessian, how you plot it depends on what you want to learn. For example, you might want to look at each component separately, or you might be interested in the norm.

Gypaets
Gypaets on 18 Dec 2015
I've written a function which calculates first and second order spatial derivatives: trigradient2
You can get the second order derivatives approximation with
[~, ~, Uxx, Uyy, Uxy]=trigradient2(M(:,1),M(:,2),M(:,3));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!