# How to evaluate vector function defined in 2D with meshgrid?

2 visualizaciones (últimos 30 días)
Yonghyeon Jeon el 19 de Sept. de 2021
Respondida: darova el 19 de Sept. de 2021
Hi, guys.
I would like to evaluate and get the function values of vector function defined in 2D.
For example, we assume that we have the function defined in 2D and discretized domain.
These are coded in matlab as follows:
fun = @(x, y) [sin(x) .* sin(x) ; cos(x) .* cos(y)];
xgrid = linspace(0, pi, 3);
ygrid = linspace(0, pi, 4);
[xmesh, ymesh] = meshgrid(xgrid, ygrid);
So, the result that I want is the 3-dimensional matrix such as
result(:,:,1) = [0, 1, 0 ; 0, 1, 0 ; 0, 1, 0 ; 0, 1, 0];
result(:,:,2) = [1, 0, -1 ; .5, 0, -.5 ; -.5, 0, .5 ; -1, 0, 1];
I tried
fun(xmesh, ymesh)
but it didn't give me the wanted result.
Plese give me a novel advises.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

darova el 19 de Sept. de 2021
Try cat
fun = @(x, y) cat(3, sin(x).*sin(x), cos(x).*cos(y));
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre MATLAB en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by