How to integrate a vector over a surface of x,y-coordinate vectors

조회 수: 3 (최근 30일)
Jakob Aberhan
Jakob Aberhan 2023년 7월 18일
댓글: Jakob Aberhan 2023년 7월 21일
Hello,
I have 3 vectors. One x vector with x-coordinates, one y vector with y-coordinates and a vector z with values to this x,y-coordinates. Now I need to integrate the values of the z vecotor over the x,y-surface.
I tried to first make a 2D-Mesh with
[X,Y] = meshgrid(x,y)
and then resape the vector z on to this mesh with
Z = griddata(x, y, z, X(:,1), Y(1,:));
this didnt work.
Can anyone tell me what I am doing wrong or can tell me how I can integrate one verctor over the x,y-coordinates of vector x and y ?
I am using matlab R2022b
Thank you in advance :)
  댓글 수: 3
Jakob Aberhan
Jakob Aberhan 2023년 7월 18일
Hey,
thank you for your reply.
My Data is quiet big so I cant attach the original. I have a velocity field. The Data is stored in 3 vectors with same length.
x giving the x-coordinates, y the y-coordinates and z is the magnitude of the velocity at the point (x,y). The spacing bewteen the coordinates is irregular. So now I want to integrate the velocity over x and y. To do so my idea was to create a mesh with [X,Y]=meshgrid(x,y). Then interpolate z on that mesh with Z = griddata(x,y,z,X,Y) . And then integrate over x and y.
Jakob Aberhan
Jakob Aberhan 2023년 7월 18일
My problem is I dont know how to interpolate correctly and how to integrate then over the x,y-Mesh with Data in it.

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

채택된 답변

KSSV
KSSV 2023년 7월 19일
편집: KSSV 2023년 7월 19일
You need to find out whether your data is structured is unstructured. Depedning on that, you need to proceed.
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
surf(X,Y,Z)
%%unstructured
m = 100 ; n = 100 ;
xi = linspace(min(x),max(x),m) ;
yi = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
figure
surf(X,Y,Z)
To integrate have have look on trapz
  댓글 수: 4
KSSV
KSSV 2023년 7월 19일
Need not to use that line. You may remove it. Edited the code.
Jakob Aberhan
Jakob Aberhan 2023년 7월 21일
Ok so I could solve my problem. Thanks a lot, you really helped me with your answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by