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 日
Why would you find the same result with different codes?
Daniel
Daniel 2012 年 12 月 6 日
In the first part of the code, the system of equations is solved using 'x1' as the free variable. In the second part, 'u' is used as the free variable.
Either way, the solution set of both approaches should be the same, resulting in similar figures.
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 日

1 投票

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 件のコメント

Daniel
Daniel 2012 年 12 月 6 日
Hi Aubrey, thank you for your reply.
Yes, this is the exact problem I'm having. Solving for 'x1' provides the three solutions in the nonlinear region while solving for 'u' provides a single (incomplete) solution.
Actually it's not the first time I've reported 'solver' finding incomplete sets.
I understand that from a computational point of view solving for 'x1' is easier for 'solver' since the function mapping f(u) -> x1 is 1-to-N while f(x1) -> u is N-to-1.
However, from a didactic point of view, the right way to go about this is solving for "u".
I'm interested in finding out if there's anything that can be done in this case.
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 日

0 投票

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 件のコメント

Daniel
Daniel 2012 年 12 月 6 日
編集済み: Daniel 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}.
The solution set is independent of the variable being solved, as long as the variables are properly fixed.
This is an important concept because in my code what I'm doing is finding the static curve (static output vs static input) of the nonlinear equation system.
The static curve should be the same, independently of the variable being solved (in this case, 'x1' or 'u').
However, as one can see, the two curves obtained by solving either for 'x1' or 'u' are different.
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.

サインインしてコメントする。

カテゴリ

質問済み:

2012 年 12 月 6 日

コメント済み:

2014 年 2 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by