Question

Problem Six: Given two polynomials: g(x) = anx + an-iz-1 +--+ aix + ao Write a MATLAB function (name it polyadd) to add the
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB CODE :

function x = polyadd(g,h)
length_g = length(g) ; % length of vector g
length_h = length(h) ; % length of vector h
if length_g > length_h % if length of g is grater than h
x = g; % initialize x with g
i = length_g ; % i is last index of g
j = length_h ; % j is last index of h
for k = 1 : length_h % loop from 1 to length_h
x(i) = x(i)+ h(j) ;% add h to x starting from last index
i = i - 1 ; % decrease i
j = j - 1 ; % decrease j
end

else % if length of h is greater than equal to length of g
x = h ; % initialize x with h
i = length_h ; % i is last index of h
j = length_g ; % j is last index of g
for k = 1 : length_g % loop from 1 to length_g
x(i) = x(i) + g(j);% add g to x starting from last index
i = i - 1 ; % decrease i
j = j - 1 ; % decrease j
end
end
end

OUTPUT :

(a)

g[l 2 3 4] h[o 20 30 41 >>h-[10 20 30 41] >>polyadd (g, h) ans - 11 22 33 45

(b)

>>g [11 12 13 14] h[101 102] >>polyadd (g,h) ans - 11 12 114 116

(c)

>>g [43 54 55] h(77 66 88 44 331 >>polyadd (g,h) ans - 77 66 131 98 88

Add a comment
Know the answer?
Add Answer to:
Problem Six: Given two polynomials: g(x) = anx" + an-iz"-1 +--+ aix + ao Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Six: Given two polynomials: g(x) = anx" + an-iz"-1 +--+ aix + ao Write a MATLAB function (name it polyadd) to add the two polynomials and returns a polynomial t(x) = g(x) + h(x),...

    Problem Six: Given two polynomials: g(x) = anx" + an-iz"-1 +--+ aix + ao Write a MATLAB function (name it polyadd) to add the two polynomials and returns a polynomial t(x) = g(x) + h(x), whether m = n, m < n or m > n. Polynomials are added by adding the coefficients of the terms with same power. Represent the polynomials as vectors of coefficients. Hence, the input to the function are the vectors: g=[an an-1 ao] and h=[am...

  • Problem 1. Given a polynorial p(x) anz" + an-lz"-ı + + aix + ao, where the...

    Problem 1. Given a polynorial p(x) anz" + an-lz"-ı + + aix + ao, where the coefficients are a,'s, Horner's method is an efficient algorithm for evaluating the polynomial at a number c that works as follows: Multiply an by c, then add an-1. Then multiply the result by c and add an-2. Then multiply the result by c and add an-3 and so on until you reach a0. This over all gives an O(n) algorithm for evaluation of p(c)...

  • MATLAB The z-transform of LTI systems can be expressed as a ratio of two polynomials in z-1 Also,...

    MATLAB The z-transform of LTI systems can be expressed as a ratio of two polynomials in z-1 Also, the rational z-transform can be written in factored form N-M) for z → H(G) = 0, the values of z are the zeros of the system for z = p2 → H(p) = oo, the values of z are the poles of the system Use MATLAB to graph Y() 1-242+2882 x(2) 1-0.8 -2 H(z) = 0,82-1 +0 642 Hints: e z: is...

  • 4. Consider the following partial information about a function f(x): S.x2, 0<x<I, (2-x), 1<x<2. Given that...

    4. Consider the following partial information about a function f(x): S.x2, 0<x<I, (2-x), 1<x<2. Given that the function can be extended and modelled as a Fourier cosine-series: (a) Sketch this extended function in the interval that satisfies: x <4 (b) State the minimum period of this extended function. (C) The general Fourier series is defined as follows: [1 marks] [1 marks] F(x) = 4 + ] Ancos ("E") + ] B, sin("E") [1 marks] State the value of L. (d)...

  • The polynomial addition C function of Program 2.6 padd is the code when the polynomial is used to...

    The polynomial addition C function of Program 2.6 padd is the code when the polynomial is used to arrange the polynomial in the two arrangement methods of the polynomial described in the text 2.4.2. For the remaining method, when the expression polynomial is arranged by a coefficient, create a polynomial addition C function padd() corresponding to Program 2.6. 66 Arrays And Structures are zero are not displayed. The term with exponent equal to zero does not shouw able since x...

  • okay so here is my c++ code and the errors im really stuck on fixing what...

    okay so here is my c++ code and the errors im really stuck on fixing what i did wrong it seems to be the same repeated error our job is to write a menu driven program that can convert to display Morse Code ere is the menu the program should display Menu Alphabet Initials N-Numbers - Punctuations S = User Sentence Q- Quit Enter command the user chooses A your program should use a loop and your morse code printing...

  • All of the following questions are in relation to the following journal article which is available...

    All of the following questions are in relation to the following journal article which is available on Moodle: Parr CL, Magnus MC, Karlstad O, Holvik K, Lund-Blix NA, Jaugen M, et al. Vitamin A and D intake in pregnancy, infant supplementation and asthma development: the Norwegian Mother and Child Cohort. Am J Clin Nutr 2018:107:789-798 QUESTIONS: 1. State one hypothesis the author's proposed in the manuscript. 2. There is previous research that shows that adequate Vitamin A intake is required...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT