Function value at starting guess must be finite and real.

30 views (last 30 days)
Volkan Yangin
Volkan Yangin on 10 Mar 2017
Edited: Volkan Yangin on 10 Mar 2017
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..

Answers (1)

Guillaume
Guillaume on 10 Mar 2017
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 Comments
Volkan Yangin
Volkan Yangin on 10 Mar 2017
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by