We know that the usual way to make a contour plot in Matlab for a function Z(x,y) is
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2); (for example)
contour(X,Y,Z);
However, this way does not work for the following function f(x,y):
Suppose h_{ij}(x,y) is a large (e.g., 100×100) matrix, in which each component is a (self-defined) function of x and y. We define another function
f(x,y)=det(h_{ij}(x,y))
and want to make a contour plot of the function f(x,y).
The determinant in f=det(h) requires each component of the matrix h be a number. So f(x,y) can be calculated by Matlab only if x and y are numbers, not vectors. If we use [X,Y]=meshgrid(…), it means that each component of the matrix h is a vector, and f(X,Y) cannot be calculated.
Is there a way to make a contour plot for the above function f(x,y), in which x and y cannot take vector values?
Assuming that
his pre-defined to be a matrix of functions each of which takes two scalar arguments and outputs a matrix (or any valid input to thedetfunction), and the subscriptsiandjrefer to the indices in X and Y of the arguments to that function, something like the following code should work (X and Y should be the same size as h):I think you’re misunderstanding what
meshgriddoes – the output of meshgrid can be easily fed to a function as above. They are not vectors in each element (just a 2-D matrix). You can then plotZas usual.