integrating function from -inf to +inf

2 次查看(过去 30 天)
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

采纳的回答

Ameer Hamza
Ameer Hamza 2020-11-4
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 个评论
Steven Lord
Steven Lord 2020-11-4
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Computations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by