How can I use MATLAB to solve double integrals?

In summary, the conversation is about a person seeking help with integrating a function using Matlab. They are struggling with setting up nested for loops for the integral within the integral, but they have managed to solve a simpler version of the problem using the trapezoidal rule. They are unsure if this is considered cheating and are looking for feedback on their approach.
  • #1
Moly
21
0
Hi Everyone.

I would like to integrate the following using matlab:
[tex] \int_0^1 ~\int_0^x e^{-x^2} ~dy ~dx [/tex]
looks pretty simple but don't know how to set up the embedded for loops for the integral with in the integral especially that the upper limit of the inner integral is x and not a number.
My actual assignment is much more complicated than this but i thought trying to work it out for a simpler function might help me with the more complex one.
Thanks for your help
 
Physics news on Phys.org
  • #2
the program that i put together is giving me the integral=24.8427 and the answer is actually 0.316... my program is copied below, what am i doing wrong:

x0=0; xt=1; xstep=11; dx=1/(xstep-1);
y0=0; yt=1; ystep=11; dy=1/(ystep-1);

sum2=0;
for i1=1:xstep
sum1=0;
y=(i1-1)*dy;
x2step=floor(y*xstep);
for i=1:xstep
if i>=x2step
sum1=sum1+dx*exp(-y^2)/2
%pause
end
x=(i-1)*dx;
end
sum2=sum2+sum1
end
sum3=sum2*dx
 
Last edited:
  • #3
oh... forgot to say that I am using trapazoidal rule for the integration
 
  • #4
Now, this is giving me the corrrect answer but not sure if i cheated in a way or not... what do you think:
close all
clear all

x0=0; xt=1; xstep=110; dx=1/(xstep-1);
y0=0; yt=1; ystep=110; dy=1/(ystep-1);

sum2=0;
for i1=1:ystep+1
sum1=0;
y=(i1-1)*dy;
x2step=floor(y/dx);
for i=1:xstep+1
if i<=x2step
sum1=sum1+dx*exp(-y^2);
end
x=(i-1)*dx;
end
sum2=sum2+sum1;
end
sum3=sum2*dy
 

1. What is a double integral in Matlab?

A double integral in Matlab is a mathematical concept that involves finding the area under a 3D surface and above a 2D region. It is represented by using two integral symbols and is commonly used in engineering, physics, and other scientific fields.

2. How do I calculate a double integral in Matlab?

To calculate a double integral in Matlab, you can use the "integral2" function. This function takes in the function to be integrated, the limits of integration, and any other necessary parameters. It then returns the value of the double integral.

3. Can I visualize a double integral in Matlab?

Yes, you can visualize a double integral in Matlab by using the "surf" or "mesh" functions. These functions create 3D plots of the surface and the area under it, allowing you to better understand the concept of a double integral.

4. How accurate are double integrals in Matlab?

The accuracy of double integrals in Matlab depends on the function being integrated and the limits of integration. Matlab uses numerical methods to calculate integrals, so the accuracy may vary. It is always recommended to check the results and adjust the parameters if necessary.

5. Can I use symbolic variables in double integrals with Matlab?

Yes, you can use symbolic variables in double integrals with Matlab by using the "syms" function to declare the variables. This allows you to perform symbolic calculations and get exact solutions for your double integrals.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
951
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
449
  • Calculus
Replies
11
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
955
  • General Math
Replies
13
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top