MATLAB Answers

0

Fzero, Function value at starting guess must be finite and real

James_111 さんによって質問されました 2019 年 1 月 24 日
最新アクティビティ Alan Weiss
さんによって 回答されました 2019 年 1 月 24 日
My code is:
format long;
b=50;a=3;e=50;
spdf = @(x) a.*(b.^a)./(x+b).^(a+1)./(1-(b./(e+b)).^a);
fun21 = @(x,u,m) min(x,max(0,fzero(@(y) 0.5.*(100-10-x+y).^(-0.5)-m-2.*u.*y,0))).*spdf(x);
fun31 = @(u,m) integral(@(x) fun21(x,u,m),0,e,'arrayvalued', true); % first moment of optimal insurance contract
[us,ms]=solve([fun31(u,m)-12==0, fun3(u,m)-178.57145==0], [u m]);
The error is:
Function value at starting guess must be finite and real.
I think my fzero function can give a finite value. Maybe the error is coming from u and m? Any one could help me fix the code? Thanks a lot!

  0 件のコメント

サインイン to comment.

1 件の回答

Alan Weiss
回答者: Alan Weiss
2019 年 1 月 24 日
 採用された回答

According to the documentation, the fun argument of integral "must accept a vector argument, x, and return a vector result, y." However, the fzero function is not vectorized, and accepts only scalar arguments. I believe that you need to write a full function file (not anonymous function handle) for fun21 and loop through the passed points one at a time as you send them to fzero.
Alan Weiss
MATLAB mathematical toolbox documentation

  0 件のコメント

サインイン to comment.



Translated by