I am trying to solve a cubic function from which I would like to get one numeric result as my variable. I've been able to do this by other means, but not with MATLAB and that's what I would need to do. I am not very good with Matlab for Im new with it so any help would be much appreciated!
My equation is; Solve for, V: V^3 - x * V^2 + y * V - z = 0.
In reality x = b+ ((R*T)/p), y = a/p and z = (a*b)/p. I know all these variables/results of the calculations so I only need to find out what V is.
So in one case the equation can be expressed as: V^3 - 0.10933127 * V^2 + 0.00082152 * V - 0.00002193 = 0
I have tried the following means and failed:
eqn = V^3 - 0.30993828*V^2 + 0.002598122*V - 0.0000693698 == 0;
S = solve(eqn,V,'Real',true)
With the first one I get symbolic results and cant open them by doubleclicking, I dont know if this is normal?
a = 1;
b = 0.30993828;
c = 0.002598122;
d = 0.0000693698;
function sols = solve_cubic(a, b, c, d)
sols = solve(a*x^3 - b*x^2 + c*x - d, x)
For some reason this does not give me anything for x in workspace, only values a,b,c,d that I already list.
p = [1 -0.10933127 0.00082152 -0.00002198];
r = roots(p)
With this I get a column vector with each row being "0.XXX + 0.XXXi".
If there is someone with extra knowledge thank you in advance!