How do i solve a cubic function giving the answer in a matrix
7 views (last 30 days)
Show older comments
callum roberts
on 24 Nov 2018
Commented: Star Strider
on 25 Nov 2018
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
Accepted Answer
Star Strider
on 24 Nov 2018
Try this:
syms Z
Pr = 42; % Choose A Number ...
Zs = solve(0==((8*0.9)/((8*Z)-1))-(27/(64*(Z^2)))-Pr,Z)
Zroots = vpa(Zs)
Zrootsd = double(Zroots)
produces:
Zs =
root(z^3 - (41*z^2)/280 + (9*z)/896 - 9/7168, z, 1)
root(z^3 - (41*z^2)/280 + (9*z)/896 - 9/7168, z, 2)
root(z^3 - (41*z^2)/280 + (9*z)/896 - 9/7168, z, 3)
Zroots =
0.0036611845692819380187451079457217 - 0.094934986290941940021998513244942i
0.0036611845692819380187451079457217 + 0.094934986290941940021998513244942i
0.13910620229000755253393835553713
Zrootsd =
0.00366118456928194 - 0.0949349862909419i
0.00366118456928194 + 0.0949349862909419i
0.139106202290008 + 0i
4 Comments
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.
0 Comments
See Also
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!