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

7 visualizaciones (últimos 30 días)
亦扬
亦扬 el 12 de Abr. de 2024
Editada: Dyuman Joshi el 26 de Abr. de 2024
以下是二元函数:
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 comentario
Piyush Kumar
Piyush Kumar el 26 de Abr. de 2024
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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 循环及条件语句 en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!