画二元函数图,用到了​三重积分,用mesh​grid报错,用循环​效率太低,求大佬改进​。

以下是二元函数:
function fun1 = fun1(a,b)
rou = 1e-3;
R = 22.5;
D1 = 50;
x1 = 50;
xmin = x1-R;
xmax = x1+R;
ymin = -inf;
ymax = inf;
k = 6.67e-11;
fun_jifen = @(x,y,z,a,b) k.*rou.*z./((x-a).^2+(y-b).^2+z.^2).^1.5;
fun1 = integral3(@(x,y,z) fun_jifen(x,y,z,a,b),xmin,xmax,ymin,ymax,@(x,y) D1-sqrt(R^2-(x-x1).^2),@(x,y) D1+sqrt(R^2-(x-x1).^2));
end

댓글 수: 1

Piyush Kumar
Piyush Kumar 2024년 4월 26일
Hi,
If you are calling fun1, i.e. evaluating integral3 at many points using a loop, it can be slow especially for large datasets or complex calculations.
You can leverage MATLAB's Parallel Computing Toolbox to distribute the computation of the integral across multiple cores. This doesn't reduce the computational complexity but can significantly reduce the wall-clock time by performing multiple computations simultaneously. The effectiveness of parallel computing depends on the hardware capabilities of your computer, especially the number of cores available.
To distribute the computation of fun1 for different values of a and b across available CPU cores, you may use "parfor" loop: https://www.mathworks.com/help/matlab/ref/parfor.html

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 循环及条件语句에 대해 자세히 알아보기

질문:

2024년 4월 12일

편집:

2024년 4월 26일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!