Plotting an integral-defined function in MATLAB

Click For Summary

Discussion Overview

The discussion revolves around how to define and plot an integral-defined function in MATLAB, specifically functions of the form f(x) = ∫0^x f(t) dt. Participants explore methods for implementing this in MATLAB, including iterative schemes and function handles.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Exploratory

Main Points Raised

  • One participant seeks clarification on defining a function based on an integral and how to plot it in MATLAB.
  • Another participant suggests using an iterative scheme, specifically the trapezoid rule, to approximate the integral for plotting.
  • A third participant discusses the relationship between the function and its derivative, proposing that if f(x) = ∫0^x f(t) dt, then f(x) could be e^x.
  • Another participant provides a method using a function handle in MATLAB to define the integral of sin(t) * e^t, demonstrating how to evaluate and plot it using ezplot.

Areas of Agreement / Disagreement

Participants present multiple approaches to defining and plotting the function, with some uncertainty about the nature of the function f. There is no consensus on the specific form of f, as one participant proposes it could be e^x while others focus on practical implementation in MATLAB.

Contextual Notes

Participants do not fully resolve the assumptions regarding the nature of the function f or the implications of the derivative relationship discussed. There are also limitations in the vectorization of the function handle mentioned.

Who May Find This Useful

This discussion may be useful for MATLAB users interested in numerical integration and plotting functions defined by integrals, particularly in the context of mathematical modeling or computational physics.

jack476
Messages
327
Reaction score
124
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.
 
Physics news on Phys.org
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##.
 
You can do this using a function handle. Consider this code for the function [itex]f(x) = \int _0^x \sin(t) e^t dt[/itex].

Code:
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:
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:
ezplot(f)
 
Excellent. Thanks guys, that did it.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 13 ·
Replies
13
Views
2K