where do i went wrong,(Polynomials)?
Show older comments
%Create a code that will perform the following operations
syms x;
% 1. Convert the symbolic function f(x) as a polynomial vector g.
%Define the symbolic function f(x)
syms f(x);
f(x)=3*x^3-5*x^9+2*x-10+x^25
g=sym2poly(f(x));
%Convert the function to polynomial vector F
F=sym2poly(f(x))
% 2. Convert the polynomial vector a as a symbolic polynomial.
%Encode the polynomial vector A
A=[1 2 3 0 0 7]
%Convert the vector a symbolic expression with the variable 'x' and save as a(x);
a(x)=poly2sym(A, x)
% 3. Find the product of b and c.
% Encode the polynomials b(x) and c(x).
b(x)=1+2*x-3*x^3+18*x^95;
c(x)=2*x-3*x^85;
%Convert the polynomials to vectors B and C, respectively.
B1=sym2poly(b(x))
B=poly2sym(B1)
C1=sym2poly(c(x))
C=poly2sym(C1)
%Multiply the vectors B and C and save it as D.
D=expand(B*C)
%Bring your answer as a symbolic expression with the variable 'x', save answer as d(x).
D1=sym2poly(D);
d(x)=poly2sym(D1, x)
%4. Divide b by a
%Save answer as Quotient and Remainder
[Quotient, Remainder]=deconv(B1, A)
%Convert Quotient to symbolic Expression. Save as q(x).
q(x)=poly2sym(Quotient, x)
%Convert Remainder to symbolic Expression. Save as r(x).
r(x)=poly2sym(Remainder, x)
%5. Create a polynomial in symbolic form with the Roots=(1,4,5,6,7)
%Encode the Roots as a vector
Roots=[1 4 5 6 7];
%Convert the Roots into a polynomial vector. Save the Answer as H;
H=poly(Roots)
%Convert H to symbolic Expression. Save as h(x).
h(x)=poly2sym(H, x)
%6. Resolve a/h the as Partial Fractions.
%Let Residue, Poles and Quotient be Res, Pol and Quo, respectively. Solving the coefficients:
[Res, Pol, Quo]=residue(AP, H)
%7. Evaluate (c+b)/h when x=3. Answer must be numeric. Save answer as m.
M1=((c(x)+b(x))/h(x));
m=double(subs(M1, x, 3))
%8. Find the roots of the polynomial vector k= [1 -15 88 -258 397 -303 90]
%Encode k
K1=[1 -15 88 -258 397 -303 90];
k=poly(K1)
%Solve the roots of polynomial vector k. Save as RootK.
RootK=roots(k)

9 Comments
Stephen Ken Lantapon
on 23 Jun 2021
Walter Roberson
on 23 Jun 2021
What is the difference between this and https://www.mathworks.com/matlabcentral/answers/862940-m-quite-frustrated-about-where-i-went-wrong-can-you-please-lend-some-help-i-promise-i-tried?s_tid=srchtitle which already has an Answer? (You should edit that one to make it readable instead of posting a new question)
Ivan Kervi Bagsao
on 3 Mar 2023
Edited: Ivan Kervi Bagsao
on 3 Mar 2023
How do you fix this

Walter Roberson
on 3 Mar 2023
double(C)
Ivan Kervi Bagsao
on 7 Mar 2023
% Encode the polynomials b(x) and c(x).
b(x)=1+2*x-3*x^3+18*x^95;
c(x)=2*x-3*x^85;
%Convert the polynomials to vectors B and C, respectively.
B1=sym2poly(b(x))
B=poly2sym(B1)
C=poly2sym(c(x),x)
%Multiply the vectors B and C and save it as D.
D=expand(B*C)
%Bring your answer as a symbolic expression with the variable 'x', save answer as d(x).
d(x)=poly2sym(sym2poly(D), x)

Walter Roberson
on 7 Mar 2023
%Convert the polynomials to vectors B and C, respectively.
B1=sym2poly(b(x))
B=poly2sym(B1)
You converted symbolic polynomial b into vector B1 and then you convert vector B1 back into a symbolic polynomial B. That B is going to be exactly the same as b except possibly with different order of terms. Your instructions are that B and C must be the vectors, not the polynomials.
In the context of sym2poly and poly2sym, "poly" is vector form and sym is symbolic expression form.
Ivan Kervi Bagsao
on 7 Mar 2023
still not right for C
Walter Roberson
on 7 Mar 2023
C=poly2sym(c(x),x)
as explained earlier, poly2sym expects to be passed the vector form and to return the expression form. Your assignment requires that C be in the vector form.
Ivan Kervi Bagsao
on 8 Mar 2023
Convert the polynomials to vectors B and C, respectively.
B=poly2sym(b(x),x)
C=poly2sym(c(x),x)
%Multiply the vectors B and C and save it as D.
D=expand(B*C)
%Bring your answer as a symbolic expression with the variable 'x', save answer as d(x).
D1=sym2poly(D)
d(x)=poly2sym(D1, x)
Still doesnt work

Answers (1)
Tanmay Das
on 28 Jul 2021
I am assuming that the correct logic is used to write the code and hence directly jumping into the error. The error is ocurring in this part of the code:
%6. Resolve a/h the as Partial Fractions.
%Let Residue, Poles and Quotient be Res, Pol and Quo, respectively. Solving the coefficients:
[Res, Pol, Quo]=residue(AP, H)
Variable ‘AP’ has not been declared anywhere in the code. It should be ‘A’ instead of ‘AP’ and the modified code for the 6th part should look like this:
%6. Resolve a/h the as Partial Fractions.
%Let Residue, Poles and Quotient be Res, Pol and Quo, respectively. Solving the coefficients:
[Res, Pol, Quo]=residue(A, H)
Categories
Find more on Polynomials in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!