Solving for area under graph in matlab

In summary: Well the idea is that if you have the values for a function at regular intervals you use a numerical technique to get an approximation of the area under the curve of the function (which is just the integral using the right limits).The easiest way to get an approximation is to use the midpoint method which goes something like this:Lets say you have two function values f(a) and f(a+h), then the approximated area for f(a) to f(a+h) is h x [f(a+h)+f(a)]/2. Using this formula you apply it to all your data points and you get an approximation for the integral.This is not the best method
  • #1
kthejohnster
23
0
how could i use MATLAB to find area under graph using numerical methods that the integral of flow vs time graph is 1/T*sum(Qti)dt or at least i think that's what the formula is, if not please help
 
Physics news on Phys.org
  • #2
kthejohnster said:
how could i use MATLAB to find area under graph using numerical methods that the integral of flow vs time graph is 1/T*sum(Qti)dt or at least i think that's what the formula is, if not please help

Hey kthejohnster and welcome to the forums.

For this problem (even in MATLAB) you just a standard numerical integration routine if you have an array of values (in any dimension).

Are you familiar with numerical integration schemes? Here is something to get you started:

http://en.wikipedia.org/wiki/Numerical_integration
 
  • #3
chiro said:
Hey kthejohnster and welcome to the forums.

For this problem (even in MATLAB) you just a standard numerical integration routine if you have an array of values (in any dimension).

Are you familiar with numerical integration schemes? Here is something to get you started:

http://en.wikipedia.org/wiki/Numerical_integration

Thanks, I know that the integral is equal to the sum of value * dt for the time but don't know how to write it in matlab. I have my plot x_plot and its a periodic function with period T how would I calculate the area under 1 period?
 
  • #4
kthejohnster said:
Thanks, I know that the integral is equal to the sum of value * dt for the time but don't know how to write it in matlab. I have my plot x_plot and its a periodic function with period T how would I calculate the area under 1 period?

Well the idea is that if you have the values for a function at regular intervals you use a numerical technique to get an approximation of the area under the curve of the function (which is just the integral using the right limits).

The easiest way to get an approximation is to use the midpoint method which goes something like this:

Lets say you have two function values f(a) and f(a+h), then the approximated area for f(a) to f(a+h) is h x [f(a+h)+f(a)]/2. Using this formula you apply it to all your data points and you get an approximation for the integral.

This is not the best method to use, but its a good way to demonstrate what I am referring to in terms of numerical integration.

If you want some kind of numeric answer I strongly suggest you look at the wikipedia page and then look at the various schemes that are available.
 
  • #5
Can you use MATLAB built-ins like trapz or quad?
 

1. How can I calculate the area under a graph in Matlab?

To calculate the area under a graph in Matlab, you can use the trapz function, which calculates the approximate area under a curve using the trapezoidal rule. This function takes in two arguments: the vector containing the x values and the vector containing the y values. It then returns the approximate area under the curve.

2. Can I calculate the area under a graph for multiple curves in Matlab?

Yes, you can calculate the area under multiple curves in Matlab by using the trapz function for each curve separately and then summing up the results. You can also use the integral function to calculate the exact area under a curve, which allows for multiple curves to be inputted at once.

3. What if my graph has negative values? Will the area under the curve still be calculated correctly?

Yes, the trapz function in Matlab takes into account both positive and negative values when calculating the area under a curve. As long as the x and y vectors are correctly inputted, the area under the entire curve will be calculated accurately, regardless of the presence of negative values.

4. Is there a way to plot the area under a graph in Matlab?

Yes, you can plot the area under a graph in Matlab by using the fill function. This function takes in the x and y vectors and fills in the area between the curve and the x-axis. You can also use the area function, which plots the area and adds it to the existing plot.

5. Can I calculate the area under a graph for a specific section or interval?

Yes, you can calculate the area under a graph for a specific section or interval by specifying the indices of the x and y vectors that correspond to that section. You can then use the trapz function on these selected indices to calculate the area under the curve for that specific interval.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
Replies
10
Views
832
  • MATLAB, Maple, Mathematica, LaTeX
Replies
22
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
49
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top