how can i find x value from given y (6th degree polynomial)

y = [7 12 18 27 35 39];
p1 = 3.7739e-21
p2 = -6.5969e-17
p3 = 2.2715e-13
p4 = 1.1034e-09
p5 = -4.8986e-06
p6 = 0.010416
p7 = -0.70896
y = p1*x^6 + p2*x^5+p3*x^4+p4*x^3+p5*x^2+p6*x+p7;

 Accepted Answer

x=roots([p1,p2,p3,p4,p5,p6,p7-y])

9 Comments

Get rid of line 9. You don't need it.
i'm not sure about those answers
Please do not post screenshots of pure text. If you just copy/paste the text, it will consume much less disk space in the forum.
I don't know why you would doubt the output of roots, but you can plug it back into the original polynomial to verify that it is satisfied.
x=roots([p1,p2,p3,p4,p5,p6,p7-y])
polyval([p1,p2,p3,p4,p5,p6,p7],x)
You will need to call roots once per element of y. You cannot find the root for a vector of y vectors all at once.
p1 = 3.7739e-21;
p2 = -6.5969e-17;
p3 = 2.2715e-13;
p4 = 1.1034e-09;
p5 = -4.8986e-06;
p6 = 0.010416;
p7 = -0.70896;
y = [7 12 18 27 35 39];
x=nan(numel(y),6);
for i=numel(y):-1:1
x(i,:)=roots([p1,p2,p3,p4,p5,p6,p7-y(i)]);
end
x
x =
1.0e+03 * 9.3101 + 1.8774i 9.3101 - 1.8774i -4.5565 + 0.0000i 1.1038 + 1.7008i 1.1038 - 1.7008i 1.2089 + 0.0000i 9.2800 + 1.8478i 9.2800 - 1.8478i -4.5894 + 0.0000i 2.1232 + 0.0000i 0.6932 + 1.8383i 0.6932 - 1.8383i 9.2421 + 1.8102i 9.2421 - 1.8102i -4.6272 + 0.0000i 2.7430 + 0.0000i 0.4401 + 2.0518i 0.4401 - 2.0518i 9.1810 + 1.7489i 9.1810 - 1.7489i -4.6807 + 0.0000i 3.3617 + 0.0000i 0.2187 + 2.3009i 0.2187 - 2.3009i 9.1215 + 1.6884i 9.1215 - 1.6884i -4.7256 + 0.0000i 3.7931 + 0.0000i 0.0849 + 2.4753i 0.0849 - 2.4753i 9.0896 + 1.6555i 9.0896 - 1.6555i -4.7472 + 0.0000i 3.9881 + 0.0000i 0.0301 + 2.5515i 0.0301 - 2.5515i
i'm sorry can i just ask you another time what is this unswer, i don't understand it
x =
1.0e+03 *
9.3101 + 1.8774i 9.3101 - 1.8774i -4.5565 + 0.0000i 1.1038 + 1.7008i 1.1038 - 1.7008i 1.2089 + 0.0000i
9.2800 + 1.8478i 9.2800 - 1.8478i -4.5894 + 0.0000i 2.1232 + 0.0000i 0.6932 + 1.8383i 0.6932 - 1.8383i
9.2421 + 1.8102i 9.2421 - 1.8102i -4.6272 + 0.0000i 2.7430 + 0.0000i 0.4401 + 2.0518i 0.4401 - 2.0518i
9.1810 + 1.7489i 9.1810 - 1.7489i -4.6807 + 0.0000i 3.3617 + 0.0000i 0.2187 + 2.3009i 0.2187 - 2.3009i
9.1215 + 1.6884i 9.1215 - 1.6884i -4.7256 + 0.0000i 3.7931 + 0.0000i 0.0849 + 2.4753i 0.0849 - 2.4753i
9.0896 + 1.6555i 9.0896 - 1.6555i -4.7472 + 0.0000i 3.9881 + 0.0000i 0.0301 + 2.5515i 0.0301 - 2.5515i
because my answer should be just a one number like 2.49e+03
i'm sorry that i have to use another screenshot to explain it whit new y values
these are the y values [16.27 27.9 41.86 62.79 81.39 90.69]
format long g
p = [3.7769e-21, -6.6055e-17, 2.2806e-13, 1.0989e-09, -4.8887e-06, 0.010408, -0.71229];
R = roots(p)
R =
9350.21416809902 + 1915.74457506144i 9350.21416809902 - 1915.74457506144i -4499.3555970064 + 0i 1608.69399831728 + 1978.77107818079i 1608.69399831728 - 1978.77107818079i 70.7499925489447 + 0i
realroots = R(imag(R)==0)
realroots = 2×1
1.0e+00 * -4499.3555970064 70.7499925489447
syms x
poly = poly2sym(p)
poly = 
fplot([poly,0], [-4750 250])
It is a degree 6 polynomial in real coefficients. There are always going to be an even number of real roots: in this case there are two real roots. You can never get just one real root for a polynomial of even order that has real coefficients.
i see thank you and i just realized i can use polyval
h = polyval(p,[16.27 27.9 41.86 62.79 81.39 90.69])

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2012a

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!