Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
function minimization with different parameters
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a function defined by intervals, it is k/x for x>c and -|x|+q with x independent variable. I want to minimize the difference between this function and some data (it is a fit MLH). the function to minimize is CHI2=sum((yi-f(x)).^2./stdi). I am not able to give a function divided by steps to fminsearch. The function f(x) is continous but not derivable.
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 9월 13일
fminsearch does not require derivatives. You can use standard logical indexing techniques in calculating your objective function
f = @(x) (x>c) .* k ./ (x + (x==0)) + (x<=c) .* (q - abs(x));
Note: your formula has a singularity at the point x = 0 in the case where c is negative, so unless you can constrain c to be positive, it is not continuous. I work around the division by 0 by adding 1 in the case where x == 0, which gives the "wrong" answer at 0, but as long as you know that c > 0 then when x == 0, x > c cannot be true so the (x > c) .* (expression) would multiply out to 0, making the exception irrelevant. This would not be the case if the division by 0 was left in, as k/0 for non-zero k would give either +inf or -inf and either of those multiplied by the 0 from (x > c) would give NaN. So the (x + (x==0)) in the denominator is there so NaN does not get introduced for positive c and x == 0. But if your c < 0 and your x == 0 then You Have A Problem.
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!