A possible bug in solver?

1 次查看(过去 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 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by