Fsolve Error while solving a system of non-linear equations.

1 次查看(过去 30 天)
I am trying to solve this system of non linear equations using fsolve:
function F = root2d(q)
M = 2;
z_alice = 1;
gammabar = 1;
F(1) = gamma(M) - gammainc(M*q(1)/gammabar, M ...
,'upper') - gammainc(M*(q(3)+z_alice)/gammabar, M,'upper');
F(2) = gamma(M) - gammainc(M*q(1)/gammabar, M,'upper') - (M/gammabar)^M...
(-q(2)^M*vpa(expint(1-M,sym(M)*q(2)/gammabar)) + (q(1) + z_alice)^M * ...
vpa(expint(1-M,sym(M)*q(1)+z_alice)/gammabar));
F(3) = q(2)^M * vpa(expint(1-M, sym(M)*q(2)/gammabar))...
-((q(1)+z_zlice)^M)*vpa(expint(1-M, sym(M)*(q(1)+z_alice)/gammabar))...
-q(3)^M * vpa(expint(1-M, sym(M)*q(3)/gammabar))+...
((q(2)+z_zlice)^M)*vpa(expint(1-M, sym(M)*(q(2)+z_alice)/gammabar));
when I run this:
close all;
clear all;
clc;
fun = @root2d;
q0 = [0,0 0];
q = fsolve(fun,q0)
I get the following error:
Failure in initial objective function evaluation. FSOLVE cannot continue.
Any help will be apprecated.
Thanks

回答(1 个)

Walter Roberson
Walter Roberson 2020-3-15
F(2) = gamma(M) - gammainc(M*q(1)/gammabar, M,'upper') - (M/gammabar)^M...
(-q(2)^M*vpa(expint(1-M,sym(M)*q(2)/gammabar)) + (q(1) + z_alice)^M * ...
vpa(expint(1-M,sym(M)*q(1)+z_alice)/gammabar));
Notice that at the end of the first line, you have ^M... with no operation after the ^M . Notice that the next line starts with ( with no operation there.
When you use ... then the current line ends immediately and the next line is effectively put into position, with no implied whitespace or operation. Your code is thus equivalent to
F(2) = gamma(M) - gammainc(M*q(1)/gammabar, M,'upper') - (M/gammabar)^M (-q(2)^M*vpa(expint(1-M,sym(M)*q(2)/gammabar)) + (q(1) + z_alice)^M * vpa(expint(1-M,sym(M)*q(1)+z_alice)/gammabar));
At the end of the second line you have the * before the ... so that is a plain multiplication between the two sides, but at the end of the first line you have the M and then ( on the next line, so what you have is M(-q(2)etc) which is an indexing request into M.
Be sure to put the appropriate mathematical operation before the ... on that first line.
  3 个评论
Walter Roberson
Walter Roberson 2020-3-22
Your code defines z_alice and uses that variable, but it also uses z_zlice twice. Is that a different variable, or is that a typing mistake?
Walter Roberson
Walter Roberson 2020-3-22
Your initial values, q0, are [0 0 0] . However, the second and third inputs must be non-zero and not the negative of z_alice (so, not -1) or else the expint() returns inf and you end up getting NaN created.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by