Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Muhammad Adil
Muhammad Adil am 15 Mär. 2020
Kommentiert: Walter Roberson am 22 Mär. 2020
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

Antworten (1)

Walter Roberson
Walter Roberson am 15 Mär. 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 Kommentare
Walter Roberson
Walter Roberson am 22 Mär. 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
Walter Roberson am 22 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by