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

7 次查看(过去 30 天)
亦扬
亦扬 2024-4-12
以下是二元函数:
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 个)

类别

Help CenterFile Exchange 中查找有关 循环及条件语句 的更多信息

Community Treasure Hunt

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

Start Hunting!