Numerical Integration with variable limits MATLAB

In summary, the conversation revolved around computing an integral involving two functions that are numerically defined as vectors in MATLAB. The first function, f(x), is defined for x values from 0 to 4 with corresponding f(x) values of 0, 1, 8, 27, and 64. The second function, g(y), is defined for y values from 0 to 4 with corresponding g(y) values of 0, 1, 4, 9, and 16. The question was how to compute the integral ##\int_0^1 f(x) \int_x^1 g(y)\, dydx## in MATLAB. It was suggested to use the cumsum() function
  • #1
member 428835
Hi PF!

Suppose I have two functions ##f(x),\,g(y)## that are numerically defined as vectors (i.e. ##g(y) = [0,1,4,9,16]:y = [0,1,2,3,4]## and say ##f(x) = [0,1,8,27,64]:x = [0,1,2,3,4]##) and am trying to compute $$\int_0^1 f(x) \int_x^1 g(y)\, dydx.$$

How would I do this in MATLAB? I could be in the wrong thread here, in which case I'm sorry!
 
Physics news on Phys.org
  • #2
f and g are defined only for discrete points. Without further definition, there is nothing to integrate.
 
  • #3
mathman said:
f and g are defined only for discrete points. Without further definition, there is nothing to integrate.
Let's say ##g(x) = x^3## and ##f(y) = y^2##. Now can you help?
 
  • #4
Rereading my post, that came off a little rude. I'm not trying to be. Just wanting to make sure I have addressed the issue you pointed out. :)
 
  • #5
It might be better to ask questions about Matlab in the computers and programming section of the forum.

Ask how ##\sum_{k=1}^5 ( \ f(k) \sum_{j=k}^5 g(j)\ )## would be done.
 
  • Like
Likes member 428835
  • #6
To properly answer this question we need to know how familiar you are with numerical integration and how familiar you are with matlab.

Think about what numerical integration is... you are basically summing up the f(x) values as you sweep the x axis. If you have discrete points this becomes easy, as you are already ready. With some MATLAB knowledge this is fairly easy.
 
  • #7
The function cumsum() may help you to do this, but only if the x value increases by the same amount every time
Alternatively you may need to write your own function, if you have varying x values.
 
  • #8
donpacino said:
To properly answer this question we need to know how familiar you are with numerical integration and how familiar you are with matlab.
I'd say I'm pretty familiar with both, but I know some people on here are way more advanced than me, so I'm unsure. I think I'm going to write my own double sum from Stephan Tashi's post. Thanks for your input!
 

1. What is Numerical Integration with variable limits in MATLAB?

Numerical Integration with variable limits in MATLAB is a mathematical method used to approximate the definite integral of a function with varying limits. It involves using numerical algorithms to calculate the area under a curve, which represents the integral of the function over a specified interval.

2. How do I use the quad function in MATLAB for numerical integration with variable limits?

The quad function in MATLAB is used for numerical integration with variable limits. It takes in the function, lower limit, and upper limit as inputs and returns the approximate value of the integral. Example: quad(@(x) x^2, 0, 2) returns the approximate value of the integral of x^2 from 0 to 2.

3. Is there a difference between numerical integration with fixed limits and variable limits?

Yes, there is a difference between numerical integration with fixed limits and variable limits. In numerical integration with fixed limits, the limits of integration are known and remain constant. In contrast, with variable limits, the limits of integration can change, making the integral more complex to solve analytically and requiring the use of numerical methods.

4. How do I choose the appropriate numerical integration method for my function?

Choosing the appropriate numerical integration method for a function depends on various factors such as the nature of the function, the accuracy required, and the computational resources available. Some commonly used methods in MATLAB include the trapezoidal rule, Simpson's rule, and Gaussian quadrature. It is recommended to try different methods and compare the results to determine the most suitable one for your function.

5. Can I use MATLAB's symbolic toolbox for numerical integration with variable limits?

Yes, the symbolic toolbox in MATLAB can be used for numerical integration with variable limits. It allows for the integration of symbolic expressions, making it useful for more complex functions. However, the symbolic toolbox may be computationally slower compared to using numerical methods directly, so it is essential to consider the trade-off between accuracy and speed when using this toolbox.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
940
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top