Is any way in Matlab to perform definite integral with conditions in the integration domain?
7 次查看(过去 30 天)
显示 更早的评论
Basic example;
f(x)= x^2+3*x for x<100 f(x)=x^3 for x>100; a=10; b=200;
d=integral(f(x), a, b)
Note: this is a basic example, I know for something like the equation above with the int function in symbolic tool box can be resolve easily doing two independent indefinite integrals and then transforms its results in functions and then evaluate those functions (one function in the interval a the other function in the interval b) to obtain the result. However the equation I’m working is very complex, and when I try to find its indefinite integral with the int function, I'm receiving the following warning error " the explicit integral can't been found". For that reason I’m trying to figure out if the integral function could work having some limitation in the integration domain.
I will appreciate whatever help that can point me out to resolve this issue. Thanks
0 个评论
采纳的回答
Mike Hosea
2014-1-27
编辑:Mike Hosea
2014-1-27
I'm not sure I understand your clarification correctly. Here is my best guess
>> f = @(x)(x.^2+3*x).*(x <= 100) + x.^3.*(x > 100);
>> Q1 = @(c)integral(f,10,c,'Waypoints',100);
>> Q2 = @(c)integral(f,c,200,'Waypoints',100);
Then you can calculate the whole integral using Q = Q1(200) = Q2(10), and you can also calculate the two pieces Q1(c) + Q2(c) = Q for any c. The use of Waypoints is for efficiency. If any of the pieces become nonfinite while the other interval is active and finite, you may need to write a MATLAB function instead of using the logical masking technique above, say fun.m:
function y = fun(x)
y = zeros(size(x),'like',x);
for k = 1:numel(x)
if x(k) <= 100
y(k) = x(k)^2 + 3*x(k);
else
y(k) = x(k)^3;
end
end
Then Q1 and Q2 would be written
>> Q1 = @(c)integral(@fun,10,c,'Waypoints',100);
>> Q2 = @(c)integral(@fun,c,200,'Waypoints',100);
It occurs to me that you may mean to integrate the pieces as "basis functions" with finite support, in which case you would define two different functions to integrate in Q1 and Q2, respectively, each defined to be zero outside of their support, either using logical masking or using the same MATLAB function approach with if/else/end.
更多回答(1 个)
Wayne King
2014-1-27
编辑:Wayne King
2014-1-27
Using integral()
integral(@(x) x.^2+3*x,10,100)
integral(@(x) x.^3,100,200)
You just integrate your first function from 10 to 100 since it is defined for x<100. x^2+3*x
Integrate the second function from 100 to 200 because it is defined for x>100, x^3
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!