Solve takes forever without error message for certain input values

1 次查看(过去 30 天)
Hello, I try to solve following equation using matlab (R2016a+Symbolic Toolbox):
syms R2
eta=(2*R2 + 499999999999999999999999974/5)/(2*(99999999999999999999999999*R2 - 1549999999999999999999999987/5)) - 28670157817202169/38280596832649216
u =- (500000000000000000000000000*R2)/(31*(99999999999999999999999999*R2 - 1549999999999999999999999987/5)) - 3511406642924695/36028797018963968
v =3511406642924695/36028797018963968 - (500000000000000000000000000*R2)/(31*(99999999999999999999999999*R2 - 1549999999999999999999999987/5))
R2a=solve(eta==sqrt(abs(u*v)),R2);
R2a=double(R2a)
R2b=solve(eta==-sqrt(abs(u*v)),R2);
R2b=double(R2b)
R2ges=transpose([transpose(R2a) transpose(R2b)])
This works fine and will deliver two solutions for R2 in seconds. However the same code with different input parameters eta u and v will not give a solution in reasonable time without bringing any kind of error message.
syms R2
eta =(2*R2 + 4499999999999999999999999801/45)/(2*(99999999999999999999999999*R2 - 2711111111111111111111111089/10)) - 4465535319756041/38280596832649216
u =- (1125000000000000000000000000*R2)/(61*(99999999999999999999999999*R2 - 2711111111111111111111111089/10)) - 7022813285849393/72057594037927936
v =7022813285849393/72057594037927936 - (1125000000000000000000000000*R2)/(61*(99999999999999999999999999*R2 - 2711111111111111111111111089/10))
R2a=solve(eta==sqrt(abs(u*v)),R2);
R2a=double(R2a)
R2b=solve(eta==-sqrt(abs(u*v)),R2);
R2b=double(R2b)
R2ges=transpose([transpose(R2a) transpose(R2b)])
If I stop the code, I get the following message:
Operation terminated by user during mupadengine/evalin (line 102)
In mupadengine/feval (line 158)
[S,err] = evalin(engine,stmt,'message');
In solve (line 292)
sol = eng.feval('solve', eqns, vars, solveOptions);
In forum_test (line 29)
R2a=solve(eta==sqrt(abs(u*v)),R2);
Do you have any ideas how to resolve the problem? I want to solve this equation a lot of times in order to find certain cases that fulfill other conditions. However, if in a loop iteration, one of the "solve" lines takes forever, this does obviously not work and will make it very impractical for example to have a lot of iterations run over night.
Thanks and best regards, Tina
  2 个评论
Torsten
Torsten 2017-8-21
What you have after multiplication with the denominators is a polynomial equation of 4th degree in R2. There is an analytic solution formula for such polynomials. Why don't you use it directly ?
Best wishes
Torsten.
Tina Gottwald
Tina Gottwald 2017-8-21
Hello, I did not use a direct analytical solution for a polynomial because the "type" of polynomial you get can vary depending on other input parameters (the code shown here is a very small part of a more complex calculation). It may be difficult to code all the possible cases with an "own" analytical formula.
I know that there will not always be a real solution for R2. If there is none, then the code should simply continue with the next iteration. I just tried to use the Return Parameters to keep the code from taking forever to try to find a solution, but so far without much success. It takes about 15 Minutes before the code continues in some cases... I

请先登录,再进行评论。

回答(1 个)

Tina Gottwald
Tina Gottwald 2017-8-21
The problem could be solved the following way:
syms R2
assume (R2, 'real')
eta =(2*R2 + 4499999999999999999999999906/45)/(2*(99999999999999999999999999*R2 - 772222222222222222222222217/5)) + 37229654178979847/76561193665298432
u =7022813285849389/72057594037927936 - (4500000000000000000000000000*R2)/(139*(99999999999999999999999999*R2 - 772222222222222222222222217/5))
v =- (4500000000000000000000000000*R2)/(139*(99999999999999999999999999*R2 - 772222222222222222222222217/5)) - 7022813285849389/72057594037927936
[R2a]=solve(eta==sqrt(abs(u*v)),R2)
R2a=double(R2a)
R2b=solve(eta==-sqrt(abs(u*v)),R2);
R2b=double(R2b)
R2ges=transpose([transpose(R2a) transpose(R2b)])
The line assume( R2, 'real') did the trick for me as I'm only looking for real solutions. The code is now fast and runs without problems.

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by