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

7 ビュー (過去 30 日間)
亦扬
亦扬 2024 年 4 月 12 日
編集済み: Dyuman Joshi 2024 年 4 月 26 日
以下是二元函数:
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 Center および File Exchange循环及条件语句 についてさらに検索

Community Treasure Hunt

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

Start Hunting!