How can I use "vpasolve" to get the smallest solution of an equation in an intervial?

27 views (last 30 days)
I have an equation with two symbolic functions, "fun1" and "fun2". I can solve fun1 == fun2 with "vpasolve":
>> x = vpasolve(fun1 == fun2);
If the equation is a polynomial, then "vpasolve" returns all of the solutions. Is there a way to make "vpasolve" return all the solutions for non-polynomial equations, or to set it so it returns the smallest solution in a given interval?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Mar 2021
Edited: MathWorks Support Team on 8 Mar 2021
There is no way to ask for more than one solution when the input to "vpasolve" is not a polynomial equation. This is because the approach to solving equations is numerical, and there is no way to know how many solutions actually exist.
However, you can call "vpasolve" iteratively, each time narrowing down the search range: If you are interested in the smallest solution, the new upper limit will be slightly smaller than the one of the previous iteration. The inverse is true in the case you are interested in the largest solution.
In the attached short demo you can see how you can use "vpasolve" iteratively to find the smallest solution. In the example, the function "eps" is used to decrease the search range by a very small amount.
Please be aware that "vpasolve" uses symbolic math and variable precision arithmetic, both of which are computationally expensive. If the input to "vpasolve" is a complicated equation, it can take a very long time to produce a result.
If you want to reduce the computation time, you can set a smaller number of significant decimal digits used for variable precision arithmetic using the "digits" function of MATLAB. This, however, will reduce the precision of your solution.

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!