How to minimize a function without using a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an equation with 3 constant (Nug & Sill, Lag) and 2 variable (R[ranges from 1 to 4000], alpha[ranges from 1 to 2, step of 0.1]). I need to find the value R and alpha that minimizes the function. Is there any Matlab function or any way i can do it without having to do a doublé for loop.
%q = 4000
for i=1:q
Theoritical(i,1) = Nug+Sill*(1-exp(-(Lag(i,1)/R)^alpha));
end
Thank you. Darl.
댓글 수: 0
답변 (1개)
Guillaume
2016년 7월 26일
It doesn't look like your Lag is much of a constant if there's 4000 values for it. Does Lag changes with R (since there's also 4000 R values)?
You can use fminsearch or fminbnd but if there's only 4000 values for R and 11 for alpha, you could simply calculate the result for all of them at once and get the minimum :
[R, alpha] = ndgrid(1:4000, 1:0.1:2); %get all combinations of R and alpha
result = Nug + Sill * (1 - exp(-bsxfun(@rdivide, Lag, R) .^ alpha)); %assumes Lag is a column vector with 4000 elements
[minvalue, location] = min(result(:));
minR = R(location)
minalpha = alpha(location)
댓글 수: 5
Guillaume
2016년 7월 26일
So, for a given R and alpha, you've 11 different theoritical (theoretical?) values. What is it you want to minimise?
참고 항목
카테고리
Help Center 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!