Is any way in Matlab to perform definite integral with conditions in the integration domain?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Mike Hosea
il 27 Gen 2014
Modificato: Mike Hosea
il 27 Gen 2014
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.
Più risposte (1)
Wayne King
il 27 Gen 2014
Modificato: Wayne King
il 27 Gen 2014
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
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!