Calculating Integral using Array Input
13 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
I'm trying to calculate the following, and was wondering whether anyone could suggest a quicker way of doing it, other than introducing a loop. Ideally, I want something that is similar to integral but can work with an array input also (an "elementwise" integral?).
Thanks a lot!
R = [5e-07,1e-06,1.75e-06,2.5e-06,3.5e-06]
phi = 40.2594
b = R/cosd(phi)
n = [1,3,10,17,35]
R_1 = R(1)
b_1 = b(1)
n_1 = n(1)
fun = @(x) (1-(R_1-x).*(b_1-x)/(R_1*b_1)).^(n_1-1).*(((R_1-x)+(b_1-x))/(R_1*b_1)).*n_1.*x
lambda_max = integral(fun,0,R_1)
R_2 = R(2)
b_2 = b(2)
n_2 = n(2)
fun = @(x) (1-(R_2-x).*(b_2-x)/(R_2*b_2)).^(n_2-1).*(((R_2-x)+(b_2-x))/(R_2*b_2)).*n_2.*x
lambda_max = integral(fun,0,R_2)
%...
0 件のコメント
採用された回答
Jan
2021 年 6 月 9 日
編集済み: Jan
2021 年 6 月 9 日
You do need a loop to get the best solution. Remember that integral is an adaptive method, which creates finer grids until a certain accuracy is reached. Using a set of different parameters does not allow to use the optimal grid for all values, such that it is expected, that you need more function evaluations and get a less accurate solution due to the accumulated rounding errors.
Use a loop and provide the parameters one after the other.
You can use parfor to accelerate the computations.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!