{"action":"created","issue":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/1505","labels_url":"https://api.github.com/repos/chebfun/chebfun/issues/1505/labels{/name}","comments_url":"https://api.github.com/repos/chebfun/chebfun/issues/1505/comments","events_url":"https://api.github.com/repos/chebfun/chebfun/issues/1505/events","html_url":"https://github.com/chebfun/chebfun/issues/1505","id":78971638,"number":1505,"title":"Chebfun2v roots fails on linear example","user":{"login":"ajt60gaibb","id":1814063,"avatar_url":"https://avatars.githubusercontent.com/u/1814063?v=3","gravatar_id":"","url":"https://api.github.com/users/ajt60gaibb","html_url":"https://github.com/ajt60gaibb","followers_url":"https://api.github.com/users/ajt60gaibb/followers","following_url":"https://api.github.com/users/ajt60gaibb/following{/other_user}","gists_url":"https://api.github.com/users/ajt60gaibb/gists{/gist_id}","starred_url":"https://api.github.com/users/ajt60gaibb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajt60gaibb/subscriptions","organizations_url":"https://api.github.com/users/ajt60gaibb/orgs","repos_url":"https://api.github.com/users/ajt60gaibb/repos","events_url":"https://api.github.com/users/ajt60gaibb/events{/privacy}","received_events_url":"https://api.github.com/users/ajt60gaibb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chebfun/chebfun/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/chebfun/chebfun/labels/chebfun2/chebop2","name":"chebfun2/chebop2","color":"009800"},{"url":"https://api.github.com/repos/chebfun/chebfun/labels/high-priority","name":"high-priority","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-21T12:21:15Z","updated_at":"2015-05-26T09:12:21Z","closed_at":null,"body":"I have been playing a lot with `chebfun2v/roots` recently and there is an example where it misses a well-conditioned root: \r\n\r\n```\r\np = @(x,y) y + x/2 + 1/10; \r\nq = @(x,y) y - 2.1*x + 2; \r\nr = roots( chebfun2v( p, q ) )\r\nr =\r\n     []\r\n```\r\n\r\nIt actually has a solution inside `[-1,1]x[-1,1]`:\r\n\r\n```\r\n[ .5 1 ; -2.1 1] \\ [.1 ; -2]\r\nans =\r\n   0.807692307692308\r\n  -0.303846153846154\r\n```\r\n\r\nSee also: \r\n```\r\nplot(roots(chebfun2(p))), hold on, plot(roots(chebfun2(q)))\r\n```\r\n![intersection](https://cloud.githubusercontent.com/assets/1814063/7748454/c6bb51cc-ff92-11e4-90a9-4a5db9419084.png)"},"comment":{"url":"https://api.github.com/repos/chebfun/chebfun/issues/comments/105458626","html_url":"https://github.com/chebfun/chebfun/issues/1505#issuecomment-105458626","issue_url":"https://api.github.com/repos/chebfun/chebfun/issues/1505","id":105458626,"user":{"login":"aaustin141","id":3380006,"avatar_url":"https://avatars.githubusercontent.com/u/3380006?v=3","gravatar_id":"","url":"https://api.github.com/users/aaustin141","html_url":"https://github.com/aaustin141","followers_url":"https://api.github.com/users/aaustin141/followers","following_url":"https://api.github.com/users/aaustin141/following{/other_user}","gists_url":"https://api.github.com/users/aaustin141/gists{/gist_id}","starred_url":"https://api.github.com/users/aaustin141/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaustin141/subscriptions","organizations_url":"https://api.github.com/users/aaustin141/orgs","repos_url":"https://api.github.com/users/aaustin141/repos","events_url":"https://api.github.com/users/aaustin141/events{/privacy}","received_events_url":"https://api.github.com/users/aaustin141/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T09:12:21Z","updated_at":"2015-05-26T09:12:21Z","body":"I think I've finally figured this out.  It has nothing to do with getting rid of negligible components of the `B` array.  Instead, it's a bug in the part of the `chebT1rtsmatgep` subroutine that handles the linear case, namely [this line](https://github.com/chebfun/chebfun/blob/9e28b8fa7a2f90f0299acc7f1b61cf5730fe7ed6/%40chebfun2v/roots.m#L639).  I think the arguments to `eig` here have been reversed; the line should really be `r = eig(c(:,:,2),-c(:,:,1));`.\r\n\r\nThe reason that commenting out the lines that eliminate small leading entries in `B` appears to fix things is that for many bivariate linear problems, prior to executing those lines, `size(B, 3)` will be 3, and `B(:, :, 1)` will be very small.  Executing those lines causes this small component to get stripped, so that when `B` is  passed into `chebT1rtsmatgep` later, it has `size(B, 3)` equal to 2, which triggers the handler for the linear case.  If, on the other hand, those lines are skipped, the small coefficient doesn't get stripped, so the argument to `chebT1rtsmatgep` has size 3 in the third dimension, and the general handler, which does things correctly, gets called instead.\r\n\r\nNote that this explanation is consistent with the results I observed in my previous post, where `B(:, :, 1)` is exactly zero on my machine for this example.  That this happened was very fortunate, as it strongly hinted that the real problem was elsewhere.  I was eventually able to discover what was wrong by trying a whole bunch of randomly selected bivariate linear examples and finding that `chebfun2v` missing the solutions was the rule rather than the exception.  With the changes in I just made to address this in #1508, I now find that it nails these problems every time.\r\n\r\nSorry for leading everyone on a wild goose chase regarding this.  If I'd been more attentive when looking at #1232, we probably would have found this sooner.\r\n\r\nNote that this bug also exists in Chebfun v4.\r\n\r\n@ajt60gaibb, would you be willing to take a look at the fixes I've made in #1508 and let me know if I'm missing anything else here?  I've gone ahead and returned the cutoff tolerance for small components of `B` to its former value of `10*eps` since that was, in fact, never the problem to begin with.  I've also added a test for the exact example used here so we don't mess this up again in the future."}}