How to plot a surface of vector z in a 2D grid made of vectors x and y?

조회 수: 12 (최근 30일)
Ivan Verstraeten
Ivan Verstraeten 2019년 11월 30일
편집: Ivan Verstraeten 2019년 12월 1일
I have a vector z which consists of function values defined on a 2D plane. I do not know the function though. I have tried interpolation with griddata and reshape to get z into a matrix but nothing seems to work. Perhaps I'm doing something fundamentally wrong so that's it's impossible to get the result I want? Help is much appreciated!
N = 100; % Amount of grid points
L = 1; % System extends from -L/2 to L/2
h = L/(N-1); % Grid step size
x = h*(0:N-1) - L/2; % Coordinates of grid points
y=x;
coeff = -1/((pi)^2*h^2) ;
coeff = ones(100,1)*coeff;
B=[coeff coeff -4*coeff coeff coeff];
H=spdiags(B,[-3 -1 0 1 3],N,N);
[V,D]=eigs(H,N);
z=V(:,100);
[X,Y] = meshgrid(x,y) ;
Z = reshape(z,size(X)) ;
figure
surf(X,Y,Z)
EDIT: As far as I know my problem lied in the construction of the matrix 'H'. It does not yield eigenvectors that are a lengthy enough to define a surface over the entire grid. For this you need a rank 3 tensor I think. Though I use the kronecker tensor product 'kron' to get all the same spacial information into a second order tensor. This way the eigenvectors are of correct size to 'reshape' them over the grid.
%---Set up the Hamiltonian operator matrix
coeff = -h_bar^2/(2*mass*h^2) ;
I=speye(N,N);
o=ones(N,1);
t=-2*ones(N,1);
D=spdiags([o t o] ,[-1 0 1],N,N);
H=kron(D,I).*coeff+kron(I,D).*coeff;
  댓글 수: 5
Star Strider
Star Strider 2019년 11월 30일
My pleasure!
It does contain information in 3D, however the ‘z’ vector is not randomly distributed with respect to the ‘x’ and ‘y’ coordinates, as griddata requires.
I am not certain what you are doing. I am not certain you can create a surface from ‘z’.
Ivan Verstraeten
Ivan Verstraeten 2019년 11월 30일
I'm trying to plot the eigenvectors of a particle in a 2D potential well; the eigenvectors of the hamiltonian 'H'.

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

답변 (1개)

Star Strider
Star Strider 2019년 11월 30일
I am not certain what you want the plots to look like, since I am not at all familiar with what you are doing.
Try this:
figure
mesh(X,Y,D)
figure
mesh(X,Y,V)
See if one of those does what you want.
  댓글 수: 3
Star Strider
Star Strider 2019년 12월 1일
The problem is that ‘V(:,99)’ would only plot one column vector (as you noted), not a surface. You are doing something that iis vary far from my areas of expertise, so if you have an paper or online reference explaning (in very basic terms) what you are doing, I might be able to help. (Otherwise, I will eventualy delete my Answer as not actually being one, and hope that someone who understands what you are doing sees this and responds.)
Ivan Verstraeten
Ivan Verstraeten 2019년 12월 1일
편집: Ivan Verstraeten 2019년 12월 1일
Here is some background:
But only read it if you have the time for it and/or really want to :) , because I think my problem can be narrowed down to 'plotting a surface of a column vector' (if it's possible with what I have). I was actually following the answer to basically the same question:https://nl.mathworks.com/matlabcentral/answers/412639-creating-surface-plot-from-a-matrix-with-3-columns
But the 'reshape' command gives the error: 'To RESHAPE the number of elements must not change'.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by