{"action":"created","issue":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/1630","labels_url":"https://api.github.com/repos/chebfun/chebfun/issues/1630/labels{/name}","comments_url":"https://api.github.com/repos/chebfun/chebfun/issues/1630/comments","events_url":"https://api.github.com/repos/chebfun/chebfun/issues/1630/events","html_url":"https://github.com/chebfun/chebfun/issues/1630","id":113566940,"number":1630,"title":"chebop.numVars","user":{"login":"nickhale","id":2035010,"avatar_url":"https://avatars.githubusercontent.com/u/2035010?v=3","gravatar_id":"","url":"https://api.github.com/users/nickhale","html_url":"https://github.com/nickhale","followers_url":"https://api.github.com/users/nickhale/followers","following_url":"https://api.github.com/users/nickhale/following{/other_user}","gists_url":"https://api.github.com/users/nickhale/gists{/gist_id}","starred_url":"https://api.github.com/users/nickhale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickhale/subscriptions","organizations_url":"https://api.github.com/users/nickhale/orgs","repos_url":"https://api.github.com/users/nickhale/repos","events_url":"https://api.github.com/users/nickhale/events{/privacy}","received_events_url":"https://api.github.com/users/nickhale/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chebfun/chebfun/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-27T11:59:22Z","updated_at":"2015-10-27T13:52:55Z","closed_at":null,"body":"Why is `.numVars` required in the second case, but not the first?\r\n\r\n```matlab\r\n>> odeFun1 = @(x,u) [ diff(u{1}) + u{1} + 2*u{2} ; ...\r\n                   diff(u{1}) - u{1} + diff(u{2}) ];\r\n>> A = chebop(odeFun1);\r\n>> A.lbc = @(u) u{1} + diff(u{1});\r\n>> A.rbc = @(u) diff(u{2});\r\n>> x = chebfun('x');\r\n>> f = [ exp(x) ; chebfun(1) ];\r\n>> u = A\\f\r\nu = \r\n   2 x 1 chebmatrix of block types:\r\n    'chebfun'    \r\n    'chebfun'    \r\n```\r\n\r\n```matlab\r\n>> A = chebop(@(x,u) odeFun1(x,u));\r\n>> A.lbc = @(u) u{1} + diff(u{1});\r\n>> A.rbc = @(u) diff(u{2});\r\n>> % A.numVars = 2 % <-- uncomment to make this work.\r\n>> x = chebfun('x');\r\n>> f = [ exp(x) ; chebfun(1) ];\r\n>> u = A\\f\r\n\r\nIndex exceeds matrix dimensions.\r\nError in adchebfun/subsref (line 1311)\r\n                    out = f(index.subs{1});\r\nError in @(x,u)[diff(u{1})+u{1}+2*u{2};diff(u{1})-u{1}+diff(u{2})]\r\n\r\nError in @(x,u)odeFun1(x,u)\r\n\r\nError in chebop/feval (line 190)\r\n    out = N.op(x, u);\r\nError in chebop/linearize (line 150)\r\n        Nu = feval(N, x, u{:});\r\nError in chebop/solvebvp (line 105)\r\n[L, residual, isLinear] = linearize(N, u0, x);\r\nError in  \\  (line 56)\r\n    [varargout{1:nargout}] = solvebvp(N, rhs, varargin{:}); \r\n```"},"comment":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/comments/151502926","html_url":"https://github.com/chebfun/chebfun/issues/1630#issuecomment-151502926","issue_url":"https://api.github.com/repos/chebfun/chebfun/issues/1630","id":151502926,"user":{"login":"asgeirbirkis","id":3543429,"avatar_url":"https://avatars.githubusercontent.com/u/3543429?v=3","gravatar_id":"","url":"https://api.github.com/users/asgeirbirkis","html_url":"https://github.com/asgeirbirkis","followers_url":"https://api.github.com/users/asgeirbirkis/followers","following_url":"https://api.github.com/users/asgeirbirkis/following{/other_user}","gists_url":"https://api.github.com/users/asgeirbirkis/gists{/gist_id}","starred_url":"https://api.github.com/users/asgeirbirkis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asgeirbirkis/subscriptions","organizations_url":"https://api.github.com/users/asgeirbirkis/orgs","repos_url":"https://api.github.com/users/asgeirbirkis/repos","events_url":"https://api.github.com/users/asgeirbirkis/events{/privacy}","received_events_url":"https://api.github.com/users/asgeirbirkis/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T13:52:55Z","updated_at":"2015-10-27T13:52:55Z","body":"(Hit the comment button too early above)\r\n\r\nTo summarize: \r\n\r\n* In the first case, we can actually inspect the anonymous function to conclude how many unknown variables are involved.\r\n\r\n* To do the second case automatically would require a try-catch statement until we hit the correct number of variables, which for nonlinear problems can lead to difficulties if the arguments we try lead to errors when evaluating the operator (e.g. division by zero). This is the approach we did in v4, but we didn't go for it with v5."}}