Function value at starting guess must be finite and real.

조회 수: 2 (최근 30일)
Volkan Yangin
Volkan Yangin 2017년 3월 10일
편집: Volkan Yangin 2017년 3월 10일
Hi everybody. I created a code as under the this text.
hiz(1)=18.54;
ra=36:1:71
for g=2:1:numel(ra)+1
WR=C*cos(egim(ra(g-1)))
WS=C*sin(egim(ra(g-1)))
WL=@(hiz1) C*((hiz1+hiz(ra(g-1)))/2).^2
WB=@(hiz1) C*( hiz1-hiz(ra(g-1))).^2/(mes(ra(g))-mes(ra(g-1)))
P=C*((yuk(ra (g)))- (yuk(ra(g-1))))
T=C*mes((ra(g))-mes(ra(g-1)))
TOTAL= @(hiz1) WR+WL(hiz1)+WS+WB(hiz1)
TOTAL_LOSS= @(hiz1) TOTAL(hiz1)*(mes(ra(g))-mes(ra(g-1)))
hiz1_function=@(hiz1) C*hiz(ra(g-1))^2-TOTAL_LOSS(hiz1)+T-C*hiz1.^2-P
x1 = [-100 100];
for k1 = 1:length(x1);
hiz_rts(g-1,k1) = fzero(hiz1_function, x1(k1))
end
end
C is the constant value of the algorithm. When this code starts to run, MATLAB gives me Function value at starting guess must be finite and real. error. How can i achieve this problem? Yesterday, i used this code without for loop and it didn't give me an error message.
Thanks..

답변 (1개)

Guillaume
Guillaume 2017년 3월 10일
Well, the error message is clear, the function you're passing to fzero must return a finite and real value at the starting point. It's not the case for one of your starting x1 value, hence the error.
We can't tell you which value nor the cause since we don't know the values of mes, hiz, egim. Possibly mes(ra(g))-mes(ra(g-1)) is 0 in some case, and WB ends up being Inf. You should be able to test it yourself by looking at the actual values.
In any case, your g loop will fail at the last iteration since ra(g) is not valid when g = numel(ra)+1
  댓글 수: 5
Volkan Yangin
Volkan Yangin 2017년 3월 10일
Yes, they go to NaN with -100 and 100. Thank you Guillaume. I am working on parameters now.
Volkan Yangin
Volkan Yangin 2017년 3월 10일
편집: Volkan Yangin 2017년 3월 10일
Guillaume, the problem on the WB, as you think. Algorithm don't know hiz(ra(g-1)) values. hiz(1) has been known only. I think, if i will be able to add the new value of hiz, algoritm runs correctly.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by