Plotting Free Surface Using MATLAB | Get Results Quickly

In summary, the programmer wants to plot a free surface defined by a double integral and has written a routine to do so but needs to get it working for the integrand above. The integrand is chosen such that the denominator has no zeros, and a piece of Matlab code was used to compute the 2D Fourier transform of a Gaussian.
  • #1
hunt_mat
Homework Helper
1,796
33
Hi,

I like to think that I can generally get MATLAB to do what I want and when I want but this has got me stumped. I want to plot a free surface defined by a double integral:
[tex]
\eta =\frac{1}{4\pi^{2}}\int_{\mathbb{R}^{2}}\frac{\mu e^{-\mu^{2}/4}e^{i(kx+ly)}\tanh\mu}{U^{2}k^{2}-\mu (B-E_{b}\mu+\mu^{2})\tanh\mu}dkdl
[/tex]
Where [itex]\mu=\sqrt{k^{2}+l^{2}}[/itex]. I wrote a routine that does a double integral trapezium rule reasonably well but I need to get it working for the integrand above. Is there a quick method I can use to do this?

I should add that U is chosen such that the denominator has no zeros.
 
Physics news on Phys.org
  • #2
I should add, the algorithm I used to compute the 2D trapezium rule is
[tex]
\begin{array}{rcl}
\int_{a}^{b}\int_{c}^{d}f(x,y)dxdy & = & \left(\sum_{i=1}^{N}\sum_{j=1}^{M}f(x_{i},y_{j})-\frac{1}{2}\sum_{i=1}^{N}f(x_{i},c)-\frac{1}{2}\sum_{i=1}^{N}f(x_{i},d)\right)\delta x\delta y \\
& - & \left(\frac{1}{2}\sum_{j=1}^{M}f(a,y_{j})+\frac{1}{2}\sum_{j=1}^{M}f(b,y_{j})\right)\delta x\delta y -{} \\
& - & \frac{1}{4}(f(a,c)+f(a,d)+f(b,c)+f(b,d))\delta x\delta y
\end{array}
[/tex]
The piece of Matlab code I used to compute the integral is given in here. I tested it out by computing the inverve 2D Fourier transform of a Gaussian and that seemed to work fine.
function y=trap_2d(A,dx,dy)
N=length(A(:,1));
M=length(A(1,:));

a=A(1,1)+A(1,M)+A(N,1)+A(N,M);
b=sum(A(1,:))+sum(A(N,:));
c=sum(A(:,1))+sum(A(:,M));
u=zeros(1,N);
for i=1:N
u(i)=sum(A(i,:));
end

d=sum(u);

y=(d-0.5*c-0.5*b-0.25*a)*dx*dy;
 

Related to Plotting Free Surface Using MATLAB | Get Results Quickly

1. How can I plot a free surface using MATLAB?

To plot a free surface using MATLAB, you can use the "surf" function. This function creates a three-dimensional surface plot with a color scale based on the data values. You will need to provide the x, y, and z coordinates of the points to be plotted, as well as the corresponding data values.

2. Can I customize the appearance of the free surface plot?

Yes, you can customize the appearance of the free surface plot by using various input arguments in the "surf" function. For example, you can change the color scheme, add labels and titles, and adjust the axes limits and scale.

3. How do I get results quickly when plotting a free surface?

To get results quickly when plotting a free surface using MATLAB, you can use the "shading" option in the "surf" function. This option allows you to choose between different shading algorithms, with the "flat" option being the fastest. You can also reduce the number of data points used in the plot to increase speed, but this may affect the accuracy of the results.

4. Can I save my free surface plot as an image or figure?

Yes, you can save your free surface plot as an image or figure using the "saveas" function in MATLAB. This function allows you to save the plot in various formats, such as JPEG, PNG, or PDF. You can also use the "print" function to save the plot as a high-resolution image.

5. Are there any other tools or techniques I can use to plot a free surface?

Yes, there are other tools and techniques you can use to plot a free surface, such as the "pcolor" function, which creates a pseudocolor plot. You can also use the "mesh" or "meshgrid" functions to create a wireframe or surface plot, respectively. Additionally, there are other software programs and packages available that specialize in plotting free surfaces and offer more advanced features and options.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
916
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Atomic and Condensed Matter
Replies
7
Views
506
Back
Top