Integrating a Function of Two Variables in MATLAB

In summary, the speaker is seeking help with integrating a function with variable limits using MATLAB. They have defined the functions g(r,z) and f(r,z) and are planning to use the built-in function "integral" and a loop to solve the problem. They are open to any further suggestions or assistance.
  • #1
bewertow
3
0
Hey guys,

I have this function:

f(r,z) = r*(1 + g(r,z))

The function g(r,z) is a modification of the student t-distribution in z, where the degrees of freedom depend continuously on r.

I would like to integrate this function f(r,z) from 0 to R with respect to r.

Unfortunately Maple could not find the integral, so I would like to do this numerically in MATLAB.

I have no clue where to start though. I've integrated a function of one variable in MATLAB before, but only with constant limits.

Any help would be greatly appreciated!
 
Physics news on Phys.org
  • #2




Hi there,

Thank you for sharing your function and problem with us. It sounds like an interesting and challenging task. Here are some steps you can take to solve this problem using MATLAB:

1. Define the function g(r,z) in MATLAB: You can do this by writing a separate function file or by using the "inline" function in MATLAB. Make sure the function takes in two inputs, r and z, and outputs a single value.

2. Define the function f(r,z) in MATLAB: Similar to step 1, you can define the function f(r,z) using the "inline" function or by creating a separate function file. The function should take in r and z as inputs and output a single value, which is the result of the multiplication between r and (1 + g(r,z)).

3. Use the "integral" function: MATLAB has a built-in function called "integral" that can numerically evaluate integrals. You can use this function to integrate your function f(r,z) with respect to r. The syntax for this function is: integral(@(r)f(r,z),0,R), where R is the upper limit of integration and f(r,z) is the function you defined in step 2. This will give you the numerical value of the integral.

4. Use a loop to vary R: Since R is a variable in your function, you can use a loop to vary its value and integrate the function for different values of R. This will give you a range of numerical values for the integral, which you can then use to analyze the behavior of the function.

I hope this helps you get started with solving your problem. If you encounter any difficulties or have any further questions, please don't hesitate to reach out for help. Good luck!
 

1. What is the syntax for integrating a function of two variables in MATLAB?

The syntax for integrating a function of two variables in MATLAB is integral2(f, xmin, xmax, ymin, ymax), where f is the function to be integrated and xmin, xmax, ymin, and ymax are the limits of integration.

2. How do I define a function of two variables in MATLAB?

To define a function of two variables in MATLAB, you can use the @ symbol to create an anonymous function or use the function keyword to create a named function. For example, f = @(x,y) x^2 + y^2 defines an anonymous function of two variables, while function z = my_function(x,y) defines a named function with two input variables, x and y.

3. Can I integrate over a non-rectangular region in MATLAB?

Yes, you can integrate over a non-rectangular region in MATLAB using the integral2 function. You can specify the limits of integration as functions of x and y, allowing you to integrate over any shape or region.

4. How do I handle singularities or discontinuities in the function being integrated?

If your function has singularities or discontinuities within the integration limits, you can use the 'AbsTol' and 'RelTol' options in the integral2 function to control the accuracy of the integration. You can also split the integration into smaller regions where the function is well-behaved, and then sum the integral values over these regions.

5. Is there a way to visualize the integrated function in MATLAB?

Yes, you can use the surf or mesh functions in MATLAB to create a surface or mesh plot of the integrated function. You can also use the contour function to create a contour plot of the integrated function. These visualization tools can help you to better understand the behavior of the integrated function and check the accuracy of your integration.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
983
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
798
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
Back
Top