MATLAB: Roots of the equation

differential equat...differential equationsrootsSymbolic Math Toolbox

I have the code below which solves for the roots of the polynomial (its a 3rd degree polynomial, specified in the 'inline' function).
However, I'm getting 8 roots instead of 3 and I am not sure where I am making the mistake.
Can someone please correct/point out the fault in my code?
I believe the error is in the last 2 lines of the code v=v=(g1/g2)*Ta; x=vpasolve(v);.
clc
clear all
close all
syms v
syms T
Tc=96.15+273 %K
Pc=4990; %KPa
R=(8.314/86.47)
Ta=1400
a=(0.42748*R*R*Tc^2.5)/(Pc)
b=(0.08664*R*Tc)/(Pc)
P=inline('((0.0961*T)/(v-6.1626e-04))- (2.0735/((T^0.5*v*(v+6.1626e-04))))','T','v')
f1=diff(P(T,v),T)
g1=vpa(subs(f1,T,Ta))
f2=diff(P(T,v),v)
g2=vpa(subs(f2,T,Ta))
v=(g1/g2)*Ta
x=vpasolve(v)
myoutput comes out to be
x =
-0.040991209604397432084120108739213
-0.00061855000000000004596600877704304
-0.00061855000000000004596600877704304
0
0
0.0006001598864238780912163945225872
0.00061855000000000004596600877704304
0.00061855000000000004596600877704304
I should only have 3 roots.

Best Answer

Are you claiming that v is a cubic polynomial?
pretty(vpa(v,5))
/ 0.0961 0.000019792 \
| -------------- + ------------------ | 1400.0
\ v - 0.00061626 v (v + 0.00061626) /
-------------------------------------------------------------
0.055417 134.54 0.055417
------------------- - ----------------- + -------------------
2 2 2
v (v + 0.00061626) (v - 0.00061626) v (v + 0.00061626)
It does not look like a cubic polynomial to me.
Really a bad idea to use the unknown variable v inside an expression v. Is your goal to write unreadable, un-debuggable code? That is a good start.
Anyway, if I use solve on v, as you do, solve finds only two roots. That is logical, since the numerator reduces to a quadratic polynomial.
x = solve(v)
x =
-0.00095509368407154541097786474853663
0.00013288519845187396718265228931994
So I have no idea what you did to find 8 roots, since I copied your code and pasted it into MATLAB.