Problem with number of intervals chosen by quadgk
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
I am running the following code being called in nested loops that vary n and k:
g = @(x) alpha(x, n, fun);
I = @(x) x.*g(R.*x).*besselj(n,j(n+1,k).*x);
[int, err] = quadgk(I,0,1);
with:
function res = alpha(r, n, fun)
func = @(theta) feval(fun,r,theta).*cos(n.*theta);
res = (1/pi) .* quadgk(func,-pi,pi);
end
and the function passed as fun is:
function y = f(r,th)
y = (4-r.^2).*sin(th).^2;
end
Now the problem I have is that the first call of quadgk chooses a differen number of points than the call in alpha. This causes me to get a matrix dimension error if f since r and th are different sizes. Is there any way to work around this problem?
p.s. I know I can give them a max number of points, but that doesn't help since they could still choose different numbers under that max.
Antworten (1)
Titus Edelhofer
am 12 Dez. 2011
Hi Nicolas,
since the "r" in the function alpha is the variable, it looks to me, as if you have to rewrite alpha to loop on r, something like
function res = alpha(r, n, fun)
res = zeros(size(r));
for i=1:length(r)
func = @(theta) fun(r(i), theta).*cos(n.*theta);
res(i) = 1/pi * quadgk(func, -pi, pi);
end
end
Titus
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!