Can I use integral with symbolic/variable interval values?

7 vues (au cours des 30 derniers jours)
Brede Løvik Lillehammer
Brede Løvik Lillehammer le 20 Jan 2014
Commenté : giorgio vanni le 24 Jan 2019
Hi. I'm wondering if it is possible to use, in some way, variable or symbolic interval values for the integral function. I need to solve a similar kind of problem shown below, can't think of a way to do it (my functions are quite huge, so it's not easy to somehow simplify it).
  • Function 1: f(s)=...
  • Function 2: g(x)=...
  • f_new = integral(@(s) f, 0, x)
Now, both f_new and g is a function of x.
  • Final function = integral(@(x) f_new*g, 0, 2)
Hope the question is somewhat clear. If not, just ask. Any help is appreciated! :)

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Jan 2014
Assuming that f is a function handle already, such as
f = @(s) tan(s^2 + exp(-s));
then
f_new = @(x) integral(f, 0, x);
final_function = @(b) integral( @(x) f_new(x) .* g(x), 0, b);
and
final_function(2)
  2 commentaires
Mike Hosea
Mike Hosea le 20 Jan 2014
You will need to vectorize f_new with arrayfun, e.g.
f_new = @(v)arrayfun(@(x)integral(f,0,x),v)
or, alternatively, prevent the outer integral from passing in non-scalars with the 'ArrayValued' option:
final_function = @(b)integral(@(x)f_new(x).*g(x), 0, b,'ArrayValued',true);
giorgio vanni
giorgio vanni le 24 Jan 2019
I've copied the answer from Walter in an easier version, as follows:
fun=@(y)integral(@(x)x,0,y)
integral(fun,0,1)
But what I've obtained is the following:
Error using integral (line 85)
A and B must be floating-point scalars.
Error in @(y)integral(@(x)x,0,y)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
I can't understand where is the problem, can you help me?

Connectez-vous pour commenter.

Plus de réponses (1)

Brede Løvik Lillehammer
Brede Løvik Lillehammer le 21 Jan 2014
Thanks for your help guys! This works. Also found the function int(), which seems to do the same thing if I'm not mistaken.
  1 commentaire
Walter Roberson
Walter Roberson le 21 Jan 2014
int() is for symbolic integration. integral() is for numeric integration.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by