fsolve for 2 equation with 2 variables

Here is my function, in order to shorten the expression here I add A and B, but in my original function they are inside F(1) and F(2) (i.e. that is not the problem), this is the error I get: Objective function is returning undefined values at initial point.
function F = myfun(x)
N=32;
K=5;
s=1;
b=0.1;
P=5;
A=-2*s^4*x(1)*N+2*s^4*x(1)*K+3*s^2*x(2)*log(2);
B=sqrt(8)*x(2)*s^2*log(2);
g=exprnd(1,1,N-K);
F(1) = sum((g.*(1-b*x(1))/(x(2)*log(2)))-1./g)+(N-K)*((A+sqrt(A^2-B^2))/((4*s^2/sqrt(8))*B))-N*P;
F(2) = b*(sum(log2((g*(1-b*x(1)/x(2)*log(2))))))-(N-K)*log2(1+(2*A^2+2*A*sqrt(A^2-B^2)-B^2)/((4/sqrt(8))*B*(A+(4/sqrt(8))*B+sqrt(A^2-B^2))));
end

 採用された回答

Star Strider
Star Strider 2017 年 12 月 13 日

0 投票

What is the initial point you chose? Your function returns finite values for random non-zero arguments. It returns [NaN NaN] for [0 0] as an input.
The solution is most likely to use an initial point other than [0 0]. I would use rand(2,1).

7 件のコメント

Miroslav Mitev
Miroslav Mitev 2017 年 12 月 13 日
Thank you, you are right. Just one last thing, do you know how can I add constraints on x1 and x2 and how can I get all the iterations?
Star Strider
Star Strider 2017 年 12 月 13 日
My pleasure.
See the documentation for the Optimization Toolbox fmincon (link) function. It will allow you to specify many types of constraints.
Miroslav Mitev
Miroslav Mitev 2017 年 12 月 13 日
Actually when I set
x0=rand(2,1);
example (0.3211 0.5321)
and when I enter
fsolve(@myfun,x0)
it returns me the same values
(0.3211 0.5321)
as a solution, which can not be true.
Star Strider
Star Strider 2017 年 12 月 13 日
Your function may not have a solution either using the root-finding function fsolve or the minimisation functions like fmincon. I got equivocal or inconsistent results for both.
Miroslav Mitev
Miroslav Mitev 2017 年 12 月 13 日
There is a solution for sure it is just a bit complicated expression. I am still not sure how to get the result, but anyway, your answer is helpful, thank you
Matt J
Matt J 2017 年 12 月 13 日
Since it is only a function of 2 variables, you could do a coarse surf() plot of norm(F) and find visually where the roots approximately lie. This would give you a better initial guess than simply randomizing.
Star Strider
Star Strider 2017 年 12 月 13 日
My pleasure.
It might be useful for you to post the symbolic expression you are coding as well as your code for it as a new Question, since that seems to be the problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by