integrate with the upper limit is a function

Hello!
How to integrate a function on Matlab with the upper limit is a function, for exemple the following integral:
i tried this code:
U= vpa(int(f,s,0,t^2))
but it returns int(f,s,0,t^2)!!
is there any method to do it?

9 Comments

The Symbolic Math Toolbox appropriately considers an otherwise undefined function.
Define it and you get an actual result —
syms s t
f(s) = 1 / (s^2 + 2*s + 1)
f(s) = 
U = vpa(int(f,s,0,t^2))
U = 
.
there is the code i used:
syms s t
f=sin(0.008414709848078965066525023216303*exp(-2*s^(1/2)) + 0.00008414709848078965066525023216303*cos(s)^2 + 0.008414709848078965066525023216303) + 1
U= vpa(int(f,s,0,t^2))
the code returns
numeric::int(sin((4850749969438627*exp(-2*s^(1/2)))/576460752303423488 + (3104479980440721*cos(s)^2)/36893488147419103232 + 4850749969438627/576460752303423488) + 1, s == 0..t^2)
Why i dont have the result of the integral?
Why i dont have the result of the integral?
MATLAB cannot compute an analytical antiderivative of f. And such an antiderivative would be necessary because the result is not a numerical value, but a function of the symbolic variable t.
Is there any other alternative to do it on Matlab? or to obtain the result of the integral as a function of the symbolic variable t?
Is there any other alternative to do it on Matlab?
If you want to keep t symbolic: no.
If you give t numerical values, you can use "integral" for evaluation.
f = @(s) sin(0.008414709848078965066525023216303*exp(-2*s.^(1/2)) + 0.00008414709848078965066525023216303*cos(s).^2 + 0.008414709848078965066525023216303) + 1;
F = @(t)integral(f,0,t^2);
tnum = 0:0.1:5;
Fnum = arrayfun(@(t)F(t),tnum);
plot(tnum,Fnum)
grid on
The int function is not doing the integration (or the subsequent substitution). Not all functions have analytic integrals, and yours is apparently one of them.
syms s t
f(s) = sin(0.008414709848078965066525023216303*exp(-2*s^(1/2)) + 0.00008414709848078965066525023216303*cos(s)^2 + 0.008414709848078965066525023216303) + 1
f(s) = 
U1 = int(f,s)
U1(s) = 
% U = vpa(int(f,s,0,t^2))
% U = simplify(U, 100)
Consider instead integrating this numerically if you want a numeric result, using the integral function.
.
The inconvient of the intergal function is that we need to use '.^ 'and/or './'
and I obtaint the function f after several calculus on Matlab the result I obtient is without '.^ 'and/or './'
If you have working with a mix of scalar constants and scalar symbolic variables, then you can use ^ and / instead of .^ and ./ . You only need .^ and ./ if you are working with non-scalar values.
syms s t
f1 = sin(0.008414709848078965066525023216303*exp(-2*s^(1/2)) + 0.00008414709848078965066525023216303*cos(s)^2 + 0.008414709848078965066525023216303) + 1
f1 = 
f2 = sin(0.008414709848078965066525023216303*exp(-2*s.^(1/2)) + 0.00008414709848078965066525023216303*cos(s).^2 + 0.008414709848078965066525023216303) + 1
f2 = 
isAlways(f1 == f2)
ans = logical
1
The inconvient of the intergal function is that we need to use '.^ 'and/or './'
If you have a symbolic function and want to convert it to a function that can be used together with "integral", use "matlabFunction". Here, you will also get .^, ./ and .* operators.
Another way is to use the 'ArrayValues',true option for "integral" that passes one value for s to the function at a time. The disadvantage is that this option might slow down the integration:
f = @(s) sin(0.008414709848078965066525023216303*exp(-2*s^(1/2)) + 0.00008414709848078965066525023216303*cos(s)^2 + 0.008414709848078965066525023216303) + 1;
F = @(t) integral(f,0,t^2,'ArrayValued',1);
tnum = 0:0.1:5;
Fnum = arrayfun(@(t)F(t),tnum);
plot(tnum,Fnum)
grid on

Sign in to comment.

Answers (0)

Products

Release

R2015a

Asked:

on 31 Jul 2024

Moved:

on 4 Aug 2024

Community Treasure Hunt

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

Start Hunting!