Need Help with Numerical Integration in MATLAB

In summary: This will result in a simpler integral that can be evaluated using the trapezoidal rule. In summary, the correct approach would be to use the method of substitution to evaluate the inner integral first and then use the trapezoidal rule to evaluate the outer integral.
  • #1
n0_3sc
243
1
Here is an integral (similar in form to the one) I want to evaluate:
$$ \int_{r_1}^{r_2} R \left\{ \int_{x_1}^{x_2} Y(x,R)\, dx \right\}^2\,dR $$
This is my approach - please correct me because I don't think it's right:
I treat R as a constant and evaluate the inner integral over some vector of x (using the function "trapz" in MATLAB)
I do the same thing again for another value of R (until the range of R values are done). Ending up with an array of values for the inner integral. (Where each element corresponds to the integral of a particular value of R).
Lastly, I evaluate the outer integral (with "trapz") over the same vector of R but for each value of the inner integral.

What do you think?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Is this the correct approach?No, this is not the correct approach. The correct approach would be to use the method of substitution to first evaluate the inner integral for all values of R, and then to evaluate the outer integral with the results of the inner integral. This can be done by setting the inner integral equal to a new variable, say U, and then substituting U back into the outer integral.
 
  • #3


Your approach seems correct. Since the integral is in the form of nested integrals, it would be best to use the "trapz" function in MATLAB to evaluate each integral separately. First, you can create a vector of evenly spaced values for R, and then use a loop to evaluate the inner integral for each value of R. This will give you an array of values for the inner integral. Then, you can use the "trapz" function again to evaluate the outer integral over the same vector of R, using the array of values for the inner integral as the function to be integrated. This will give you the final result of the integral. Just make sure to use appropriate limits for the inner and outer integrals and to check your results with other methods to ensure accuracy.
 

1. What is numerical integration in MATLAB?

Numerical integration in MATLAB is a method used to calculate the definite integral of a function over a given interval. It involves dividing the interval into smaller subintervals and approximating the area under the curve using a numerical method.

2. How do I perform numerical integration in MATLAB?

To perform numerical integration in MATLAB, you can use the built-in function "integral" or "quad". These functions take in the desired function, interval, and other parameters and return the approximate value of the integral.

3. What are the common methods used for numerical integration in MATLAB?

Some common methods used for numerical integration in MATLAB include the trapezoidal rule, Simpson's rule, and Gaussian quadrature. These methods differ in their accuracy and computational complexity.

4. How can I improve the accuracy of numerical integration in MATLAB?

You can improve the accuracy of numerical integration in MATLAB by using a smaller step size or by increasing the number of subintervals. You can also try using a more accurate method, such as Gaussian quadrature, instead of the default trapezoidal rule.

5. Can I integrate a function with multiple variables in MATLAB?

Yes, you can integrate a function with multiple variables in MATLAB by using the "integral2" or "quad2d" functions. These functions take in a function with two variables and integrate it over a specified region.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
3K
Replies
3
Views
417
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
Replies
5
Views
664
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top