# Plotting an integral-defined function in MATLAB

1. Aug 5, 2015

### jack476

At this exact moment, the proper name of functions defined by:

f(x) = ∫0xf(t)dt escapes me, so I apologize for the title maybe not being as clear as possible.

What I'd like to know is how to go about defining such a function so that I can plot it. Do I just put the variable x into the upper bound of integration, then define the function to be whatever comes from that? Thank you.

2. Aug 5, 2015

### RUber

To plot this, you might want to use some sort of iterative scheme.
The most simple is the trapezoid rule.
x= linspace(0, 1) ;
dx= t(2) - t(1);
y = zeros(length(x));
y(1) = 0;
for i = 2:length(x)
y(i) = y(i-1) + dx/2*(f((x(i))+f(x(i-1)))
end
plot(x,y)

---

Are the functions f referring to the same thing?
If so, notice that you have
$f(x) = \int_0^x f(t) dt$
so
$\frac{d}{dx}f(x) = \frac{d}{dx}\int_0^x f(t) dt = f(x)$
This implies that $f(x) = e^x$.

3. Aug 6, 2015

### kreil

You can do this using a function handle. Consider this code for the function $f(x) = \int _0^x \sin(t) e^t dt$.

Code (Text):

f = @(x) integral(@(t) sin(t).*exp(t), 0, x);

To evaluate, you can just call the function with a value for the limit of integration:
Code (Text):

f(10)

To plot, you can use ezplot. It returns a warning since f isn't vectorized (needs to loop over values of x to pass to integral one at a time), but it still works and generates a plot.

Code (Text):

ezplot(f)

4. Aug 6, 2015

### jack476

Excellent. Thanks guys, that did it.