{"action":"created","issue":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/1710","labels_url":"https://api.github.com/repos/chebfun/chebfun/issues/1710/labels{/name}","comments_url":"https://api.github.com/repos/chebfun/chebfun/issues/1710/comments","events_url":"https://api.github.com/repos/chebfun/chebfun/issues/1710/events","html_url":"https://github.com/chebfun/chebfun/issues/1710","id":126707094,"number":1710,"title":"MESHGRID vs NDGRID for CHEBFUN2 and CHEBFUN3","user":{"login":"Hadrien-Montanelli","id":5701816,"avatar_url":"https://avatars.githubusercontent.com/u/5701816?v=3","gravatar_id":"","url":"https://api.github.com/users/Hadrien-Montanelli","html_url":"https://github.com/Hadrien-Montanelli","followers_url":"https://api.github.com/users/Hadrien-Montanelli/followers","following_url":"https://api.github.com/users/Hadrien-Montanelli/following{/other_user}","gists_url":"https://api.github.com/users/Hadrien-Montanelli/gists{/gist_id}","starred_url":"https://api.github.com/users/Hadrien-Montanelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hadrien-Montanelli/subscriptions","organizations_url":"https://api.github.com/users/Hadrien-Montanelli/orgs","repos_url":"https://api.github.com/users/Hadrien-Montanelli/repos","events_url":"https://api.github.com/users/Hadrien-Montanelli/events{/privacy}","received_events_url":"https://api.github.com/users/Hadrien-Montanelli/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-01-14T17:34:54Z","updated_at":"2016-01-15T17:41:17Z","closed_at":null,"body":"Two- and three-dimensional grids can be generated by the `meshgrid` and `ndgrid` commands. For example:\r\n```\r\n>> tt = chebpts(3);\r\n>> [xx, yy] = meshgrid(tt)\r\n\r\nxx =\r\n    -1     0     1\r\n    -1     0     1\r\n    -1     0     1\r\n\r\n\r\nyy =\r\n    -1    -1    -1\r\n     0     0     0\r\n     1     1     1\r\n\r\n>> [xx1, yy1] = ndgrid(tt)\r\n\r\nxx1 =\r\n    -1    -1    -1\r\n     0     0     0\r\n     1     1     1\r\n\r\n\r\nyy1 =\r\n    -1     0     1\r\n    -1     0     1\r\n    -1     0     1\r\n```\r\nNote that `xx1 = yy = permute(xx, [2 1])` and `yy1 = xx = permute(yy, [2 1])`. Similarly in 3D,\r\n```\r\n>> [xx, yy, zz] = meshgrid(tt);\r\n>> [xx1, yy1, zz1] = ndgrid(tt);\r\n```\r\ngenerate grids such that `xx1 = yy = permute(xx, [2 1 3])`, `yy1 = xx = permute(yy, [2 1 3])` and `zz1 = zz`. \r\n\r\nIn 2D, one can evaluate a `chebfun2` at a grid generated by either `meshgrid` or `ndgrid`. However, to construct a `chebfun2` from discrete data, these data have to come from a grid generated by `meshgrid`.\r\nIn 3D, the current behaviour is that one can also evaluate a `chebfun3` at a grid generated by either `meshgrid` or `ndgrid`, but the construction process from discrete data assumes that the grid was generated by `ndgrid`. I don't like this inconstancy. \r\n\r\nBecause we're using `meshgrid` for `chebfun2` objects, when`f` is a `chebfun2` then `diff(f,1,1)` is (the partial derivative) df/dy, while `diff(f,1,2)` corresponds to df/dx. This seems unnatural to me but I can live with it.\r\n\r\nBehnam chose `ndgrid` for two reasons: A, if we were using `meshgrid` for `chebfun3`, then, for example, `diff(f,1,1)` would be df/dy, `diff(f,1,2)` would be df/dx and `diff(f,1,3)` would be df/dz, and B, `meshgrid` doesn't generalise to dimensions > 3 while `ndgrid` does.\r\n\r\nIt's clear that changing the behaviour of Chebfun2 is a lot of work and we probably don't want to do that (the papers/guide assume this behaviour), but I still wanted to raise this issue. "},"comment":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/comments/172028498","html_url":"https://github.com/chebfun/chebfun/issues/1710#issuecomment-172028498","issue_url":"https://api.github.com/repos/chebfun/chebfun/issues/1710","id":172028498,"user":{"login":"heatherw3521","id":15003640,"avatar_url":"https://avatars.githubusercontent.com/u/15003640?v=3","gravatar_id":"","url":"https://api.github.com/users/heatherw3521","html_url":"https://github.com/heatherw3521","followers_url":"https://api.github.com/users/heatherw3521/followers","following_url":"https://api.github.com/users/heatherw3521/following{/other_user}","gists_url":"https://api.github.com/users/heatherw3521/gists{/gist_id}","starred_url":"https://api.github.com/users/heatherw3521/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heatherw3521/subscriptions","organizations_url":"https://api.github.com/users/heatherw3521/orgs","repos_url":"https://api.github.com/users/heatherw3521/repos","events_url":"https://api.github.com/users/heatherw3521/events{/privacy}","received_events_url":"https://api.github.com/users/heatherw3521/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T17:41:17Z","updated_at":"2016-01-15T17:41:17Z","body":"Overall from the perspective of someone really new to numerical computing (but obviously very influenced by Grady), I definitely think meshgrid is the more intuitive one and matches up with how I think about discretizations. I assume other student users would have a similar intuition. For people still learning, this is important because they don't have the experience to always recognize quickly that something is amok in the results, or figure out exactly what that something could be. "}}