Can MATLAB solve 3 order equation including square root of the variable?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Huan Zhao
am 9 Okt. 2017
Beantwortet: David Goodmanson
am 19 Okt. 2017
Hi there,
I am using MATLAB to solve the below equation to obtain x. All the other variables are known.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168033/image.png)
The code used is shown below.
if true
% code
syms a b c d e f g R x
eqn = a*x^3 + b*sqrt(R^2-x^2)*x^2 + c*x^2 + d*sqrt(R^2-x^2)*x...
+ e*x + f*sqrt(R^2-x^2) + g == 0;
sol = solve(eqn, x, 'ReturnConditions', true)
end
Then I have the results:
>> sol.conditions
=
(d^2 - 4*b*f)^(1/2) ~= d + 2*b*z1 & d + 2*b*z1 + (d^2 - 4*b*f)^(1/2) ~= 0 & a^2 + b^2 ~= 0 & R^2*b^2*z1^4 + 2*R^2*b*d*z1^3 + 2*R^2*b*f*z1^2 + R^2*d^2*z1^2 + 2*R^2*d*f*z1 + R^2*f^2 == a^2*z1^6 + 2*a*c*z1^5 + 2*a*e*z1^4 + 2*a*g*z1^3 + b^2*z1^6 + 2*b*d*z1^5 + 2*b*f*z1^4 + c^2*z1^4 + 2*c*e*z1^3 + 2*c*g*z1^2 + d^2*z1^4 + 2*d*f*z1^3 + e^2*z1^2 + 2*e*g*z1 + f^2*z1^2 + g^2 & (signIm(((a*z1^3 + c*z1^2 + e*z1 + g)*1i)/(b*z1^2 + d*z1 + f)) == -1 | a*z1^3 + c*z1^2 + e*z1 + g == 0) & b ~= 0
>> sol.parameters
=
z1
>> sol.x
ans =
z1
Does this mean there is no solution for the equation, please?
Thanks.
0 Kommentare
Akzeptierte Antwort
David Goodmanson
am 19 Okt. 2017
Hello Huan,
I don't believe a symbolic solution is possible but if you can live with a numerical solution, then you can take all the terms involving sqrt(R^2-x^2) over to the right hand side, square both sides, bring the right hand side back and obtain a sixth degree polynomial
(a*x^3 + c*x^2 + e*x + g)^2 - (b*x^2 + d*x + f)^2*(R^2-x^2) = 0.
One can square this out and find the coefficients by hand but it helps to have the symbolic results
syms a b c d e f g R x
z = (a*x^3 + c*x^2 + e*x + g)^2 - (b*x^2 + d*x + f)^2*(R^2-x^2)
z = collect(expand(z))
which gives
z = (a^2 + b^2)*x^6 + (2*a*c + 2*b*d)*x^5 etc. etc. (results below)
The coefficients are denoted by q below and the solutions are the roots of that polynomial. Leaving syms at this point and putting in arbitrary values for the constants, then in regular variables the solution is
a = 1; b = 2; c = 3; d = 4; e = 5; f = 6; g = 7; R = 8;
q6 = a^2 + b^2;
q5 = 2*a*c + 2*b*d;
q4 = - R^2*b^2 + 2*f*b + c^2 + d^2 + 2*a*e;
q3 = - 2*b*d*R^2 + 2*a*g + 2*c*e + 2*d*f;
q2 = - R^2*d^2 - 2*b*R^2*f + e^2 + f^2 + 2*c*g;
q1 = - 2*d*f*R^2 + 2*e*g;
q0 = - R^2*f^2 + g^2;
x = roots([q6 q5 q4 q3 q2 q1 q0])
x =
6.9305 + 0.0000i
-7.3609 + 0.0000i
-0.9906 + 1.4981i
-0.9906 - 1.4981i
-0.9942 + 1.3238i
-0.9942 - 1.3238i
In this case two solutions are real, four are complex. Since the original equation was squared, the solutions can involve either positive sqrt(R^2-x^2) (three solutions) or negative sqrt(R^2-x^2) (three solutions). If you check the original equation
(a*x.^3 + c*x.^2 + e*x + g) - (b*x.^2 + d*x + f).*sqrt(R^2-x.^2) % should be 0 for pos. sqrt
(a*x.^3 + c*x.^2 + e*x + g) + (b*x.^2 + d*x + f).*sqrt(R^2-x.^2) % should be 0 for neg. sqrt
the results show that in this example solutions 1,5,6 use positive sqrt and solutions 2,3,4 use negative sqrt. If you want a solution with positive square root and x real, then the first root x = 6.9305 gets the job done. In general there is no guarantee that there is a solution with x real.
0 Kommentare
Weitere Antworten (1)
Duncan Lilley
am 18 Okt. 2017
Hello,
If a symbolic equation has no solution, then "solve" would return empty. The return value you have received indicates that there is a solution, but because there are so many variables and terms within square roots, the symbolic solution is subject to conditions. Whatever values satisfy the conditions on parameter "z1" are valid solutions to "x".
If you want a numeric solution, since the other variables are known, you can substitute for those values and get a numeric solution by using "vpasolve". You can find the documentation page for "vpasolve" here.
If, however, you wish to have a symbolic solution, this page may help you with troubleshooting equation solutions from the "solve" function.
More information regarding the differences between symbolic and numeric can be found on this documentation page.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!