where do i went wrong,(Polynomials)?

3 views (last 30 days)
Stephen Ken Lantapon
Stephen Ken Lantapon on 23 Jun 2021
%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
Walter Roberson
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
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

Sign in to comment.

Answers (1)

Tanmay Das
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)

Products

Community Treasure Hunt

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

Start Hunting!