A possible bug in solver?

조회 수: 4 (최근 30일)
Daniel
Daniel 2012년 12월 6일
댓글: Daniel 2014년 2월 24일
Either this is a bug in 'solver' or I'm missing something.
This script should generate two identical figures, however the second part ignores an entire set of solutions.
clear all;
%%System parameters
D = 0.072;
phi = 20;
B = 8;
Beta = 0.3;
static = [];
syms x2 u
for x1=0.1:0.01:0.82
res = solve(0== -x1 + D*(1 - x1)*exp(x2/(1+x2/phi)), 0== -x2 + B*D*(1 - x1)*exp(x2/(1+x2/phi)) + Beta*(u - x2));
static = [static; vpa(res.u)];
end
plot(static,0.1:0.01:0.82)
hold all;
clear all;
%%System parameters
D = 0.072;
phi = 20;
B = 8;
Beta = 0.3;
static = [];
syms x2 x1
for u=-1:0.01:1
res = solve(0== -x1 + D*(1 - x1)*exp(x2/(1+x2/phi)), 0== -x2 + B*D*(1 - x1)*exp(x2/(1+x2/phi)) + Beta*(u - x2));
static = [static; vpa(res.x1)];
end
plot(-1:0.01:1,static)
xlabel('u')
ylabel('x1')
  댓글 수: 4
Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
But x1 and u are different in your expression
Daniel
Daniel 2012년 12월 6일
They are different variables in the same equation system.
If you have:
x1 + x2 = 0
And you fix x1=1, solving the system you'll obtain a solution {x1,x2} = {1,-1}. Now, if you fix x2 to -1, you'll obtain the same solution {x1,x2} = {1,-1}.
That is to say, in my problem, that if you obtain 3 different values of "u" solving for "x1" (the first curve, shaped like an S), you should obtain 3 different values of "x1" when solving for "u" (the weird second curve, quasi-sigmoidal, which is wrong).
I hope that clarifies as to why the first and second figures should be similar, almost identical.

댓글을 달려면 로그인하십시오.

채택된 답변

Aubrey
Aubrey 2012년 12월 6일
Would you understand it if the equation was:
x1 + x2^2 = 0
Now x1 and x2 have different effects on the equation, is that better?
If you fix x1 to 1, the solution set is S1 = {x1,x2} = {1,i}.
Now if you fix x2 to i, the solution set is S2 = {x1,x2} = {1,i}.
Actually, if you fix x1 to 1, the solutions are {1,i} and {1,-i}, while if you fix x2 to i, the only solution is {1,i}.
This is exactly the same issue that you are encountering in your plots. Looking at the plot, there are three different solutions for x1 when u=0. Solve finds one of them.
If we had a perfect solver that was guaranteed to find all solutions, then you are correct and we would find the same set of solutions either way. However, numerical solvers cannot guarantee finding all solutions.
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
static = [static; vpa(res.u)]; correspond to first plot
static = [static; vpa(res.x1)] correspond to the second plot
Why the plot of u and x1 are expected to be the same?
Daniel
Daniel 2014년 2월 24일
Giving this thread some closure after a long time, Aubrey's answer is correct.
MATLAB's solver will fail to find some solutions. I ended up using the global optimization toolbox.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
In your above comment, x1 and x2 have the same effect in the equation. In your equations u appears once while x1 appears three times, then they have'nt the same effect, why are you expecting to find the same result?
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 6일
Why do you fix x1 to i? and not 4 or ....
It's not what you did in your program, what you did is
for x1=0.1:0.01:0.82
and
for u=-1:0.01:1
Daniel
Daniel 2012년 12월 6일
편집: Daniel 2012년 12월 6일
Run the script, see how the inferior and superior lines overlap and you'll understand.
I came here in search of answers and I ended up answering, lol.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by