2013-10-22 133 views
0

我想解決一個雙積分,我正在解決內部以及與quadgk函數外部積分。如何在matlab中使用quadgk函數作爲函數句柄?

% The integrand is of course a function of both x and y 
integrand = @(x,y) (phi(j,y,X) - phi(j,x,X))*(phi(i,y,X) - phi(i,x,X))/abs(y-x)^(2*s+1) 

% The inner integral is a function of x, and integrates over y 
inner = @(x) quadgk(@(y)integrand(x,y), x-lambda, x+lambda) 

% The inner integral is integrated over x to yield the value of the double integral 
dblIntegral = quadgk(inner, -(1+lambda), 1+lambda) 

和我得到這個以下錯誤:

integrand = @(x,y)(phi(j,y,X)-phi(j,x,X))*(phi(i,y,X)-phi(i,x,X))/abs(y-x)^(2*s+1) 
inner = @(x)quadgk(@(y)integrand(x,y),x-lambda,x+lambda) 

??? Error using ==> quadgk at 108 
A and B must be scalar floats. 

Error in ==> @(x)quadgk(@(y)integrand(x,y),x-lambda,x+lambda) 
Error in ==> quadgk>evalFun at 344 
     fx = FUN(x); 

Error in ==> quadgk>f1 at 362 
    [y,too_close] = evalFun(tt); 

Error in ==> quadgk>vadapt at 258 
     [fx,too_close] = f(x); 

Error in ==> quadgk at 197 
[q,errbnd] = vadapt(@f1,interval); 

Error in ==> frational_laplacian at 29 
dblIntegral = quadgk(inner, -(1+lambda), 1+lambda) 

回答

0

你得到的問題,因爲內部quadgk使用評估值的矢量傳遞的功能。這意味着,在該線

dblIntegral = quadgk(inner, -(1+lambda), 1+lambda) 

功能inner被稱爲其中x是一個矢量。 quadgk要求a和b(在這種情況下x±lambda)是標量,所以你會看到你所看到的錯誤。如果你想確保inner總是得到一個標量作爲輸入,你可以使用

dblIntegral = quadgk(@(x)arrayfun(inner,x), -(1+lambda), 1+lambda)