How to draw double integral functions

Click For Summary
SUMMARY

This discussion focuses on correcting a MATLAB M-File for drawing double integral functions involving parameters R and h. The original code had issues with symbolic variables and the integrand definition. The corrected version defines the function f as a function of R and h, and properly uses element-wise division in the integrand. The final implementation successfully draws the desired functions using the ezsurf function.

PREREQUISITES
  • Familiarity with MATLAB programming
  • Understanding of double integrals and numerical integration
  • Knowledge of symbolic mathematics in MATLAB
  • Experience with function handles and element-wise operations in MATLAB
NEXT STEPS
  • Explore MATLAB's quad2d function for numerical integration techniques
  • Learn about symbolic computation in MATLAB using syms and related functions
  • Investigate the use of function handles in MATLAB for dynamic function definitions
  • Study the ezsurf function for visualizing mathematical functions in MATLAB
USEFUL FOR

Mathematics students, MATLAB programmers, and engineers interested in numerical methods and visualizing complex functions.

matinking
Messages
15
Reaction score
0
Hi every one!

I would like to draw a double integral function in related to R and h parameters by below M-File but It does goes wrong!
Is there anyone to correct it for me?
thank you

syms R h;

a1 = 0;

a2 = atan(R./(R+h));

r1 = h;
r2 = sqrt(R.^2+(R+h).^2);

integrand = @(r,a)(h.*sin(a)/((r.^2).*(r.^2+h.^2-2.*r.*h.*cos(a))));
f = quad2d(integrand,r1,r2,a1,a2);

ezsurf(f,[0.001,5]);
 
Physics news on Phys.org
There's two problems that I can see right away (and perhaps more that I don't see). For one I'm guessing you're trying to make f a function of R and h? But you just leave them as symbolic objects. The second problem is that where you define the integrand, you need an extra "."

Code:
integrand = @(r,a)(h.*sin(a)./((r.^2).*(r.^2+h.^2-2.*r.*h.*cos(a))));


If I understand what you're trying to do correctly then this should do it:
Code:
f = @(h,R) quad2d(@(r,a)(h.*sin(a)./((r.^2).*(r.^2+h.^2-2.*r.*h.*cos(a)))),h,sqrt(R.^2+(R+h).^2),0,atan(R./(R+h)));
ezsurf(f,[0.001,5]);

When I ran it, there were a bunch of warnings but I think that may be due to a singularity in the integral you're evaluating.
 
Thank you very much.

your correctness let's the functions be drawn!
 

Similar threads

Replies
5
Views
4K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K