画二元函数图,用到了三重积分,用meshgrid报错,用循环效率太低,求大佬改进。
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
以下是二元函数:
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 Kommentar
Piyush Kumar
am 26 Apr. 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
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!