where do i went wrong,(Polynomials)?

조회 수: 2 (최근 30일)
Stephen Ken Lantapon
Stephen Ken Lantapon 2021년 6월 23일
댓글: Ivan Kervi Bagsao 2023년 3월 8일
%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
Walter Roberson
Walter Roberson 2023년 3월 7일
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 2023년 3월 8일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Tanmay Das
Tanmay Das 2021년 7월 28일
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)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by