0

I have a huge function to integrate:

syms x y

f=(228155022448185.*(cos((2.*pi).*y)./exp(131738205584307./(35184372088832*x)) - 1)*(cos((8.*pi).*y)/exp(131738205584307./(8796093022208*x)) - 1)*(cos((8.*pi).*y)/exp(131738205584307./(8796093022208.*x)) + cos((18.*pi).*y)/exp(1185643850258763./(35184372088832.*x)) - 2))/((18014398509481984. *(x.^2)).*exp(x. * ((1981232555272083.*(y.^2))/2251799813685248 - y./16 + 1./16)))

I need to integrate it (x:[0,inf) and y:[0,1]), but I receive an error for quad2d and dblquad.

quad2d(quadfun,0,100,0,1)

??? Error using ==> quad2d>tensor at 350
Integrand output size does not match the input size.
Error in ==> quad2d at 164
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
and

dblquad(quadfun,0,100,0,1)     

     ??? Error using ==> dblquad>innerintegral at 74
      Inputs must be floats, namely single or double.
    Error in ==> quad at 76
    y = f(x, varargin{:});

Error in ==> dblquad at 53
Q = quadf(@innerintegral, ymin, ymax, tol, trace, intfcn, ...

Could you explain why these errors appear? And how can I fix it?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
frwmetric
  • 41
  • 1
  • 1
  • 6

1 Answers1

4

The quad function family doesn't work with symbolic math. Instead, you can either:

  1. Use symbolic integration with int. To compute a double integral, invoke int twice consecutively, each time with a different integration variable.

  2. Define an equivalent regular function that accepts non-symbolic parameters and pass its handle to quad. I'd do it with an anonymous function -- just start your definition with f = @(x, y) instead of f =, and that's it (also remember that f is a function handle now, so you don't need to write the ampersat (@) when passing it around).

Eitan T
  • 32,660
  • 14
  • 72
  • 109
  • firstly when I use int, I have received Warning: Explicit integral could not be found. secondly without the symbolic variables how can I define my function... I wrote syms x y then I wrote my function as f=@(x,y)... actually there quadfun=@(x,y)f which is not mention above sorry about that... – frwmetric May 28 '13 at 13:36
  • @frwmetric If MATLAB has problems with finding the explicit integral, this means that you must resort to the second approach. Don't define `x` and `y` symbolic as symbolic arguments, keep everything non-symbolic for `quad`. – Eitan T May 28 '13 at 13:50
  • sorry I am not expert at matlab.. what do you mean non-symbolic?... how can I define my function with non-symbolic variables... – frwmetric May 28 '13 at 15:21
  • Do you know how to define anonymous functions? And remove the syms line. – Eitan T May 28 '13 at 15:26
  • Yes. And without the syms, the x and y will be non-symbolic. If you are not familiar with the Symbolic Math toolbox, I suggest that you read tutorials about it first. – Eitan T May 28 '13 at 20:03