Calculating Integral using Array Input

조회 수: 3 (최근 30일)
J_P
J_P 2021년 6월 9일
댓글: J_P 2021년 6월 9일
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)
%...

채택된 답변

Jan
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.
  댓글 수: 1
J_P
J_P 2021년 6월 9일
Ah fair enough, I did not think of the grid itself. Well, worth a try, thanks a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by