Integration of real variable function on arbitrary interval.

2 views (last 30 days)
Mehdi on 1 Dec 2023
Commented: Walter Roberson on 2 Dec 2023
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)
ans =
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).

Paul on 1 Dec 2023
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)
ans =
0
Witht the original integrand
int(x^(1/3),-1,1)
ans =
ans =
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
Sam Chak on 2 Dec 2023
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 on 2 Dec 2023
You have to be clearer about what it means to be undefined.
syms x real
fun = x^(1/3) + x^2
fun =
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
fun2 =
fun3 = RealizeIt(fun)
fun3 =
int(fun, x, -1, 1)
ans =
int(fun, x, 0, 1)
ans =
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)
ans =
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)
ans =
int(fun3, x, -1, 1)
ans =
int(fun3, x, 0, 1)
ans =
function y = RealizeIt(y)
y = piecewise(isfinite(y) & imag(y) == 0, y, 0);
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2022b

Community Treasure Hunt

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

Start Hunting!