Can I integrate using nested functions using quad?

5 Ansichten (letzte 30 Tage)
Francisco Hernandez
Francisco Hernandez am 10 Jun. 2015
Kommentiert: Star Strider am 10 Jun. 2015
Hello,
What I'm trying to do is the following. Using a function
f (x) = x + alpha
where alpha=x^2, I'm trying to use the function quad to integrate f(x). The obvious way to do it is
quad(@(x)(x+x.^2),a,b).
Is there a way to integrate only writting alpha, instead of x^2, namely
quad(@(x)(x+alpha),a,b)
Apparently I can't do that, is there any other function that would allow me to do this, or how can I do this? It would be useful for me to do this, because the function I want to integrate is way more complicated than the one described above.
Thank you for your response.

Akzeptierte Antwort

Star Strider
Star Strider am 10 Jun. 2015
You can do that!
You need to define ‘alpha’ as an anonymous function and refer to it as such in your code for ‘f’:
alpha = @(x) x.^2;
f = @(x) x + alpha(x);
a = 0;
b = 2;
int_f = quad(f, a, b);

Weitere Antworten (1)

Francisco Hernandez
Francisco Hernandez am 10 Jun. 2015
Thank you! This was very useful :)

Kategorien

Mehr zu Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by