How to implement a timeout on simplify() ?

4 views (last 30 days)
Imran Khan
Imran Khan on 2 Sep 2024
Edited: Imran Khan on 5 Sep 2024
I want to use a timeout on the simplify() function. I think this functionality exists using the 'seconds' option. From MATLAB help: "Time limit for the simplification process, specified as the comma-separated pair consisting of 'Seconds' and a positive value that denotes the maximal time in seconds."
But for some reason this doesn't seem to be working. For example, when I have a rather long symbolic expression as given in the attached file (exceeded character limit for the question form), and try to run:
simplify(blah,'Seconds',5)
This just keeps running without timing out.
Am I doing something wrong? Is there some way to specify a timeout for the simplify() function?
  7 Comments
Walter Roberson
Walter Roberson on 3 Sep 2024
Seconds is meant for timeout.
In practice, it is impractical to check the timer at each low-level step. In practice, the code recurses through expressions. Potentially it might check the timer each time it recurses, or after each significant step. But the problem is your expressions are complicated, and even digging into the children a fair ways gets you expressions that are hard to simplify. You have sums of sines and cosines, and pattern matching needs to be done on each potential grouping of sine and cosine in each expression, because of possible trig reductions.
sin(A) + sin(B) + cos(C) + cos(D)
has to check {sin(A), sin(B)}, {sin(A), cos(C )}, {sin(A), cos(D)}, {cos(C }, cos(D)} for potential reductions. But you have whole series of them in each expression... Probably the program is trying to reduce the entire sum, taking a long time at it, and not checking the timer until after it is done.
Imran Khan
Imran Khan on 4 Sep 2024
@Walter Roberson, thanks for your detailed explanation of how the timer is likely working internally - it makes me think that this is an issue to escalate to support. That is, if something can be done about it.

Sign in to comment.

Answers (1)

Imran Khan
Imran Khan on 5 Sep 2024
Edited: Imran Khan on 5 Sep 2024
Contacted MATHWORKS support. This is a known issue under Windows 10. Fixed in MATLAB 2023Rb Release 6.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!