Fsolve Error while solving a system of non-linear equations.
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 15 Mar 2020
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 Comments
Walter Roberson
on 22 Mar 2020
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
on 22 Mar 2020
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.
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!