Differentiation in 2D for Non Uniformly Distributed Data

조회 수: 22 (최근 30일)
Julia
Julia 2014년 4월 10일
답변: Gypaets 2015년 12월 18일
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
Alberto
Alberto 2014년 4월 10일
편집: Alberto 2014년 4월 10일
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 2014년 4월 10일
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!

댓글을 달려면 로그인하십시오.

답변 (2개)

Andrew Newell
Andrew Newell 2014년 4월 10일
편집: Andrew Newell 2014년 4월 10일
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 2015년 12월 18일
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));

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by