Skip to content

Commit

Permalink
Ensure chebfun3/plus works fine with objects of different tech
Browse files Browse the repository at this point in the history
also added a test which did not work previously
  • Loading branch information
bhashemi committed Mar 25, 2023
1 parent a69d966 commit 84c7573
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion @chebfun3/plus.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@
% number of the plus operation f + g, i.e., ||f|| + ||g|| / ||f+g||
% We first compute a rough approximate vscale for f+g:
m = 51; % size of sampling grid
hVals = sample(f, m, m, m) + sample(g, m, m, m);

% trigtech and chebtech sample at different points. The else-part of the following
% statement ensures that f and g are sampled at the same points even if they have different techs.
if (~isPeriodicTech(f) && ~isPeriodicTech(g) ) || (isPeriodicTech(f) && isPeriodicTech(g) )
hVals = sample(f, m, m, m) + sample(g, m, m, m);
else
[xxf, yyf, zzf] = chebpts3(m, m, m, f.domain);
[xxg, yyg, zzg] = chebpts3(m, m, m, g.domain);
hVals = feval(f, xxf, yyf, zzf) + feval(g, xxg, yyg, zzg);
end
hVscale = max(abs(hVals(:)));
vscaleFG = [vscale(f), vscale(g)];
kappa = sum(vscaleFG)/hVscale;
Expand Down
7 changes: 7 additions & 0 deletions tests/chebfun3/test_plus.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@
pass(8) = rank(g) == rank(f);
pass(9) = abs(vscale(g) - 2e100)/2e100 < 2e-2;

% Does plus works fine with objects of different tech?
ff = @(x,y,z) sin(pi*x).*cos(pi*(x+y));
f = chebfun3(ff);
g = chebfun3(ff,'trig');
fmg = f - g;
pass(10) = norm(fmg) < tol;

end

0 comments on commit 84c7573

Please sign in to comment.