Why MATLAB gives me this warning?

조회 수: 53 (최근 30일)
Volkan Yangin
Volkan Yangin 2017년 3월 22일
댓글: Walter Roberson 2023년 3월 18일
Check function or try again with a different starting value. Exiting fzero: aborting search for an interval containing a sign change because NaN or Inf function value encountered during search. (Function value at 2.96273e+152 is -Inf.)
MATLAB gives me this warning on command window, but it still does calculations corretly after this warning. Is this an error? I have seen this warning for first time.
Thanks
  댓글 수: 1
Volkan Yangin
Volkan Yangin 2017년 3월 22일
OK, i obtained the problem. First value of the function runs with 0 starting value and it gives me the warning.

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

채택된 답변

Rik
Rik 2017년 3월 22일
You are trying to find a zero of a function. This means Matlab will look for an x-value where the sign changes. During this proces it encountered a -inf value, after which it broke off its search.
What you need to do is written in the warning message: either check if your function is indeed the function you ment (i.e. check for typos), or adjust the starting value. If you have the function y=x and you start looking a x=100 and only increasing x, you'll never find the crossing. Apparently something equivalent has happened here.
Your Matlab is not broken, it just did not find the result it was looking for.
  댓글 수: 3
Ryland
Ryland 2023년 3월 17일
Is there a way to have tell matlab to automatically adjust the starting value with an if statement?
Walter Roberson
Walter Roberson 2023년 3월 18일
You can use try/catch but then you would need a search algorithm better than the one built in to fzero.
If you already have information about where a root might be, use that point the first time.
If not...
well imagine an upside-down Gaussian.... nearly flat except that in a narrow range it dips slightly below zero. Place that one dip somewhere between -realmax and +realmax. What search strategy are you going to use to find it?

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

추가 답변 (1개)

Ju DING
Ju DING 2018년 5월 3일
well,I also encounter the same problem as you.Please check your function input, maybe there is an illegal input.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by