Getting errors for numerical integration

5 views (last 30 days)
Jay
Jay on 5 Sep 2017
Answered: Cam Salzberger on 5 Sep 2017
So I'm solving this integral -
fun = @(x)(((((besselj(0,(2*pi*1)/(3*(10.^8))*x*ro)-besselj(0,(2*pi*x)/(3*(10.^8)))*x*ri)).^2)/x)*freopen(x));
q = integral(fun,0,Inf);
where freopen is -
function f =freopen(x) epso = 2.5; f = 1/sqrt(epso-(x.^2)); end
I dont understand why I would get a matrix dimension error as the same function and integrand was working for symbolic integration. Also I'm unable to understand rest of the errors.
Errors -
Error using * Inner matrix dimensions must agree.
Error in numint>@(x)(((((besselj(0,(2*pi*1)/(3*(10.^8))*x*ro)-besselj(0,(2*pi*x)/(3*(10.^8)))*x*ri)).^2)/x).*(1/sqrt(epso-(x.^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 83) [q,errbnd] = vadapt(@AToInfInvTransform,interval);
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct);
Error in numint (line 5) q = integral(fun,0,Inf);
Any help would be greatly appreciated.

Answers (1)

Cam Salzberger
Cam Salzberger on 5 Sep 2017
I would have thought the issue would be with one of the divides, not one of the multiplications. Either way, it's likely that you are multiplying or dividing two matrices together that are not the proper size for matrix multiplication or division. I'd suggest doing:
dbstop if error
to catch the error when it occurs. Then, while in debug mode, run pieces of the equation until you figure out what appears to be messing up the dimensions.
Also, I'd suggest cleaning up the extraneous parentheses. They really serve to confuse the equation further. I believe you have an instance where "x*ro" is inside the bessel call, and another where "x*ri) is outside of it, and I can't tell if that's intentional.
Remember to check if you mean to be using * and /, or .* and ./, if you're expecting an operand to be an array.
-Cam

Community Treasure Hunt

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

Start Hunting!