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
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...
1. Write a Matlab function to convolve two sequences objects: function y = conv(x, h) % CONV Convolve two finite-length Matlab sequence objects, x and h % returning sequence object, y. When you convolve x[n] and h[n] , you may not use MATLAB's numerical conv routine. 2. write a second convolution function, conv_rt, in Matlab that basically implements a real-time convolu- tion strategy: function y = conv_rt(x, h) % Convolve two finite-length arrays, x and h % returning array, y...
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...
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)...