Integration of real variable function on arbitrary interval.
조회 수: 3 (최근 30일)
이전 댓글 표시
My symbolic variable is defined to be real, but when I integrate my function over a predefined rbitrary interval the integrate take it as complex variable.
x = sym("x","real");
int((x)^(1/3),-1,1)
I expected to receive 3/4 but received complex number.
Is there any way to get 3/4?
Note the integration must be done analytically and can not be changed to numerical and also the integral interval can not be changed to [-1,0]&[0,1], since in my original problem it is not easy to find this seperation point (0 here).
댓글 수: 0
채택된 답변
Paul
2023년 12월 1일
Why would you expect the result to be 3/4?
Plotting the function, assuming we want the real cube root
plot(-1:.01:1,nthroot(-1:.01:1,3))
It looks like the integral should be 0, which is the obtained result when changing the integrand to use nthroot.
syms x real
int(nthroot(x,3),-1,1)
Witht the original integrand
int(x^(1/3),-1,1)
the result isn't necessarily complex. I've run into this before and I'm pretty sure there's a way to subsitute nthroot for the cube root using mapSymType. See this Question
댓글 수: 11
Sam Chak
2023년 12월 2일
Hi @Mehdi
I believe @Walter Roberson's workaround may be effective if you can identify a mathematical property in the function that allows for complex-valued solutions. Even better, if you could share the actual mathematical function with us, we could test its functionality more accurately.
for loop
if property == true
fun = piecewise();
out = int(fun, x, interval)
else
out = int(fun, x, interval)
end
end
Walter Roberson
2023년 12월 2일
You have to be clearer about what it means to be undefined.
syms x real
fun = x^(1/3) + x^2
If that is to be "undefined" for negative x, then is it only the x^(1/3) part that should be undefined, or is it the entire expression that should be undefined ? Like if you had int(sin(fun(x)), x, -1, 1) then is it the entire fun that is undefined for negative ?
fun2 = RealizeIt(x^(1/3)) + x^2
fun3 = RealizeIt(fun)
int(fun, x, -1, 1)
int(fun, x, 0, 1)
The original conception took 0 for the range below 0 as the x^(1/3) was considered undefined there -- so in the original, the integral was considered to be clipped below 0, with only the part above 0 to be evaluated.
But this slightly modified function has components that can be meaningfully evaluated below 0. Should those components be considered, or should the fact that one of the components is undefined mean that the whole expression should be considered undefined?
int(fun2, x, -1, 1)
The above is when you let the x^2 be considered valid below 0 and only zero out the x^(1/3)
int(fun2, x, 0, 1)
int(fun3, x, -1, 1)
int(fun3, x, 0, 1)
function y = RealizeIt(y)
y = piecewise(isfinite(y) & imag(y) == 0, y, 0);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!