I want to create a function "f" which calculates the product of two polynomials
a0 +a1X + ···+anX^n and b0+b1X+···+bmX^m
For example, since (1 + x)(3 + 2x^2) = 3 + 3x + 2x^2 + 2x^3,we expect the following resuslt:
f(c(1,1),c(3,0,2))
[1] 3 3 2 2
I have some idea here:
X^0: a0b0
X^1: a0b1+a1b0
X^2: a0b2+a1b1+a2b0
.
.
So, I have the function like this
A =(a0,a1,....,an),B=(b0,b1,...,bn)
f= function(A,B){
n=length(A)
m=length(B)
for(k in 0:(n+m-2))
for(j in 0:k)
{
C[k+1]=sum(A[j+1]*B[k-j+1])
}
}
But it doesn't work when I type f(A,B) Did anyone has better idea?