integrating function from -inf to +inf

2 views (last 30 days)
I'm trying to integrate the following function from -inf to +inf with repsect to x.
fun = @(x) -3.*v.^2 -4.*v.*a./((x.^2+a.^2)*pi) - a.^2./((x.^2+a.^2)^2*pi^2)
fun =
function_handle with value:
@(x)-3.*v.^2-4.*v.*a./((x.^2+a.^2)*pi)-a.^2./((x.^2+a.^2)^2*pi^2)
>> integral(fun,-inf,inf)
Error using symengine
Not a square matrix.
Error in sym/privBinaryOp (line 1030)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in ^ (line 330)
B = privBinaryOp(A, p, 'symobj::mpower');
Error in @(x)-3.*v.^2-4.*v.*a./((x.^2+a.^2)*pi)-a.^2./((x.^2+a.^2)^2*pi^2)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 103)
[q,errbnd] = vadapt(@minusInfToInfInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
I don't know why i'm getting this error?
by the way v and a are both constants

Accepted Answer

Ameer Hamza
Ameer Hamza on 4 Nov 2020
You need use element-wise operator:
fun = @(x) -3.*v.^2 -4.*v.*a./((x.^2+a.^2)*pi) - a.^2./((x.^2+a.^2).^2*pi^2)
%^ put a dot here
  4 Comments
Steven Lord
Steven Lord on 4 Nov 2020
The integral function is for numeric integration. If you have fixed values for a and v, define variables with those values before creating your fun function. If you want to perform the integration symbolically use the int function on a symbolic expression (not a function handle.)
syms a x
f = a*x^2;
int(f, x, 0, 5)
a = 3;
f = @(x) a*x.^2;
integral(f, 0, 5)

Sign in to comment.

More Answers (0)

Categories

Find more on Matrix Computations in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!