Root() in answer of solve function
조회 수: 35 (최근 30일)
이전 댓글 표시
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
pepe
2019년 12월 23일
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
2019년 12월 23일
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
채택된 답변
Walter Roberson
2016년 5월 6일
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
Ariel Chazan
2020년 3월 5일
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
2020년 3월 5일
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.
추가 답변 (1개)
Victor Prohorov
2021년 3월 1일
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
Walter Roberson
2021년 3월 1일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!