How do i solve a cubic function giving the answer in a matrix
Show older comments
Im trying to solve this cubic equation to give me the intersection points at Pr and give me the anser in a matrix format. Doing this only gives me one answer not three
Pr=input('Pr=');
solve(0==((8*0.9)/((8*Z)-1))-(27/(64*(Z^2)))-Pr,Z);
Z=subs(Z,Pr)
2 Comments
madhan ravi
on 24 Nov 2018
what’s Pr?
callum roberts
on 24 Nov 2018
Edited: callum roberts
on 24 Nov 2018
Accepted Answer
More Answers (1)
John D'Errico
on 24 Nov 2018
This is not a cubic polynomial. Fact. A cubic polynomial is of the form:
a + b*x + c*x^2 + d*x^3
What you have is a rational polynomial. Hint: a cubic polynomial does not have any points where the function goes to infinity for a real finite input. What happens in your function?
syms Z Pr
pretty(((8*0.9)/((8*Z)-1))-(27/(64*(Z^2)))-Pr)
36 27
----------- - Pr - -----
(8 Z - 1) 5 2
64 Z
So when Z==1/8 or Z==0, thig function is undefined, with a singularitiy at those locations. Again, is it a cubic pollynomial? No.
Now, as long as you are willing to assume that Z is NEVER going to be exactly 0 or 1/8, you can multiply by Z^2*(8*Z-1), converting the relation into one that is cubic polynomial in nature. It looks like solve does this for you.
Prvals = 1:5;
vpa(subs(solve(36/(5*(8*Z - 1)) - Pr - 27/(64*Z^2),Z),Pr,Prvals),5)
ans =
[ 0.21067, 0.19186, 0.18239, 0.17615, 0.17155]
[ 0.40717 - 0.29075i, 0.19157 - 0.31738i, 0.1213 - 0.28576i, 0.086927 - 0.2594i, 0.066727 - 0.23881i]
[ 0.40717 + 0.29075i, 0.19157 + 0.31738i, 0.1213 + 0.28576i, 0.086927 + 0.2594i, 0.066727 + 0.23881i]
And since you can the do a subs into the result for a set of values for Pr, that works. Be careful though, because for any value of Pr that would have yielded a solution of 1/8 for Z, that solution is actually spurious.
Categories
Find more on Number Theory 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!