MATLAB Answers

integrating function from -inf to +inf

조회 수: 1(최근 30일)
Randy Chen
Randy Chen 4 Nov 2020
댓글: Randy Chen 4 Nov 2020
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:
>> 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

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 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

표시 이전 댓글 수: 1
Randy Chen
Randy Chen 4 Nov 2020
i guess there's something wrong with my function in the first place?
Steven Lord
Steven Lord 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)
Randy Chen
Randy Chen 4 Nov 2020
thank you!

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Community Treasure Hunt

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

Start Hunting!

Translated by