Root() in answer of solve function
36 views (last 30 days)
Show older comments
Linh Dang
on 6 May 2016
Commented: Walter Roberson
on 1 Mar 2021
Hello, I am solving a partial derivative equation using symbolic expression. After using f1= diff(f,Qs) and solve(f1,Qs), I got the following answer that have root(....). Anybody can explain to me how can I get rid of root()? Note: z is not defined initially
Thanks for your help
Example:ans= root(3*a^2*k^2*z^6 - 2*Qn*a^2*k^2*z^5 + 4*a*k*z^5 - 3*Qn^2*a^2*k^2*z^4 + 8*Qn*a*k*z^4,z,1)
2 Comments
pepe
on 23 Dec 2019
I have had a similar version dependent exprience. My code is:
syms x
solve(x^3+x-1==0)
In Matlab 2019 it produces the useless root() output that you also mentioned. But in MATLAB 2014 it produces a nicer result comprised of fractions and sums of numbers;...so I recommend you also give it a try using a old version of MATLAB.
good luck
پویا پاکاریان
پویاپاکاریان
Walter Roberson
on 23 Dec 2019
syms x
>> simplify(solve(x^3+x-1==0, 'maxdegree', 3),'steps',50)
ans =
-(12^(1/3)*((93^(1/2) - 9)^(1/3) - (93^(1/2) + 9)^(1/3)))/6
(2^(2/3)*3^(1/3)*((93^(1/2) - 9)^(1/3) - (93^(1/2) + 9)^(1/3)))/12 - (2^(2/3)*(3^(5/6)*(93^(1/2) - 9)^(1/3) + 3^(5/6)*(93^(1/2) + 9)^(1/3))*1i)/12
(2^(2/3)*(3^(5/6)*(93^(1/2) - 9)^(1/3) + 3^(5/6)*(93^(1/2) + 9)^(1/3))*1i)/12 + (2^(2/3)*3^(1/3)*((93^(1/2) - 9)^(1/3) - (93^(1/2) + 9)^(1/3)))/12
Accepted Answer
Walter Roberson
on 6 May 2016
RootOf(f(z), z) represents the set of values, z, that satisfy f(z) == 0 -- the roots of the expression.
You have a polynomial of degree 6. There are not generally exact solutions to such polynomials, but if the polynomial is what is shown, that particular one can be factored to create four 0's and two exact roots.
You could try applying simple() to the output.
5 Comments
Ariel Chazan
on 5 Mar 2020
Walter, I have a question on the nature of an expression of the form root(...). Is the expression an integer?
For example, if I apply the solve function a polynomial and get an array x with three elements all in the form of root(...), i.e. x = [root(...), root(...), root(...)], can I now assign a variable to one of these elements, i.e a = x(1), and use a later in a piece of code just like any other variable? Many thanks for your help
Walter Roberson
on 5 Mar 2020
The expression would seldom be an integer. It would also not necessarily be real-valued.
However, yes you can assign it to a variable and use it in symbolic expressions.
If the root() expression contains only constants and the variable z then MATLAB will understand the represented value as being a constant.
More Answers (1)
Victor Prohorov
on 1 Mar 2021
Read Matlab help:
Try to get an explicit solution for such equations by calling the solver with 'MaxDegree'. The option specifies the maximum degree of polynomials for which the solver tries to return explicit solutions. The default value is 2. Increasing this value, you can get explicit solutions for higher order polynomials.Solve the same equations for explicit solutions by increasing the value of 'MaxDegree' to 3.
1 Comment
Walter Roberson
on 1 Mar 2021
Already discussed https://www.mathworks.com/matlabcentral/answers/282911-root-in-answer-of-solve-function#comment_365402
Also, when you are working with partial derivatives then when matlab sees the diff() then if you called solve() then matlab will call dsolve() in order to work out the solution. However, dsolve does not support the MaxDegree option and will return RootOf (though the presentation interface will rewrite them as root() to show to the user.) There is no method provided by matlab to reduce a RootOf that has already been returned.
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!