MATLAB: A and B must be floating-point scalars.

integralnumerical integration

I have some problem to solve, i can integral my function with the error "A and B must be floating-point scalars." and alpha,R and lambda are known number
  • sorry, i have refresh my code because it is not clear
——————————————————————
syms r
syms pr
lambda = 1 / (pi*500^2);
alpha = 4;
R = int(2*pi*lambda_B*r^2*exp(-lambda_B*pi*r^2), r, 0, Inf);
w =((1-(1+1i*t*pr^alpha*r^(-alpha))^(-1))*r);
f = int(w, r, R,Inf);
g = exp(-2 * pi * lambda * f)*2*pi*lambda*pr*exp(-lambda*pi*pr^2);
ACC = integral(@(pr)g, 0, Inf);
----------------------------------------------------------------
*[error]
Error using integralCalc/finalInputChecks (line 511)
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
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 more_fading (line 59) charfun_I_CC = integral(@(pr)g, 0, Inf);*
thank you so much!

Best Answer

You have

ACC = integral(@(pr)g, 0, Inf);

This passes a function to integral that ignores its input value and just executes g. g is a symbolic expression involving the symbolic variables pr and t. Using pr as an argument name in @(pr)g does not cause the argument pr to be substituted

You should use something like

G = matlabFunction(g, 'vars', pr);
integral(G, 0, Inf)

This will still have problems because of t.

I say "symbolic t" because you did not define t so I have to assume you wanted it symbolic.