Error using integral function
조회 수: 2 (최근 30일)
이전 댓글 표시
Dear MATLAB users,
I am using integral function in which I am getting error. I read the questions others asked. The answers says we should add .* instead of * where two terms are getting multiplied. Kindly help to solve it as the function I am solving in "integral function" is autogenerated by some other function.
My code is as follows:
syms x y
alpha = 45*pi/180;
b = cos(alpha);
l = 0;
N = 10;
phi = 0;
X = (sqrt(1-x*x)/sin(alpha))*cos(phi);
Y = (sqrt(1-x*x)/sin(alpha))*sin(phi);
Z = (x-cos(alpha))/sin(alpha);
r = sqrt(X*X+Y*Y+Z*Z);
y1 = x;
y2 = (x/2)*log((1+x)/(1-x)) - 1;
for i=1:N
for j=1:N
fun = y1.*int(subs(y2.*r^j,x,y).*ALP(j,l,y),y,x,1)
G0j = integral(@(x)fun,b,1)
end
end
function y = ALP(j,l,x)
y = ((-1)^l)*(1-x*x)^(l/2)*diff(legendreP(j,x),l);
end
Error is as follows:
Error using integralCalc/finalInputChecks (line 522)
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 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in rough (line 66)
G0j = integral(@(x)fun,b,1)
One more question:
I was initially using symbolic integration. But as I increase number of terms in expansion MATLAB didn't solve it but return expression as int(fun,Xmin,Xmax). Is there any way to resolve this. Can matlab solve complecated symbolic algebra?
Thank You.
Yashika
댓글 수: 0
채택된 답변
Star Strider
2020년 1월 14일
Try this instead:
ALP = @(j,l,x) ((-1)^l)*(1-x*x)^(l/2)*diff(legendreP(j,x),l);
syms x y
alpha = 45*pi/180;
b = cos(alpha);
l = 0;
N = 10;
phi = 0;
X = (sqrt(1-x*x)/sin(alpha))*cos(phi);
Y = (sqrt(1-x*x)/sin(alpha))*sin(phi);
Z = (x-cos(alpha))/sin(alpha);
r = sqrt(X*X+Y*Y+Z*Z);
y1 = x;
y2 = (x/2)*log((1+x)/(1-x)) - 1;
for i=1:N
for j=1:N
fun = y1.*int(subs(y2.*r^j,x,y).*ALP(j,l,y),y,x,1);
G0(i,j) = vpaintegral(fun,x,b,1)
end
end
The integral function will not work with symbolic variables or symbolic functions. The vpaintegral function (R2016b and later releases) will. Use the double function with ‘G0’ to convert it to a double array (with some loss of precision) if you want to use it in non-symbolic calculations.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!