필터 지우기
필터 지우기

vectorized fzero function for Monte Carlo simulation

조회 수: 3 (최근 30일)
wangm
wangm 2021년 10월 6일
답변: wangm 2021년 10월 8일
I am run a Monte Carlo simulation with e.g. 1 million realizations and there is a zero searching using the fzero function in each loop. The code becomes very slow for 1 million loops. Is there a vectorized way for fzero? The code likes:
for i = 1:1e6
x(i) = fzero(fun, x0)
end
Is there a quick way like: x = vectorized_fzero(fun, x0) to improve the efficiency?
Thanks

답변 (2개)

Walter Roberson
Walter Roberson 2021년 10월 6일
No.
However if you happen to know the derivative of the function or can construct it symbolically, then you can create a vectorized version of the Newton Raphson method.
Selection of which entries to process further can end up being more expensive than just processing all of the entries in some cases, depending on how expensive the function is.
The number of digits gain per iteration is known in theory so you can often put in a fixed upper limit on the number of iterations.

wangm
wangm 2021년 10월 8일
not familar with your solution. does it work with multiple random variabes? the x in equation is a vector of x1, x2,... and x1, x2,... are sampled from their respective distribution. I just wonder if someone has made fzero applicable to this situation.

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by