Calculating Integral using Array Input
조회 수: 3 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!