adding 2 polynomials having lots of trouble
Afficher commentaires plus anciens
y(x) = p_1*(x^n)+p_2*(x^(n-1))+...+p_n*x+p_n+1
z(x) = s_1*(x^m)+s_2*(x^(m-1))+...+s_m*x+s_m+1
i need to add the coefficients of the terms with the same power when m=n, m<n, and m>n.
h(x) = y(x) + z(x)
The input to the script will be vectors:
p = [p_1,p_2...p_n,p_n+1]
s = [s_1,s_2...s_m,s_m+1]
an example if the input was:
p = [1,2,3,4] and s = [10,20,30,40]
I should get the answer [11,22,33,44]
please help i am very new to matlab and im really having trouble with this one
1 commentaire
lowcalorie
le 4 Mar 2012
Réponse acceptée
Plus de réponses (1)
Wayne King
le 4 Mar 2012
p = [1,2,3,4];
s = [10,20,30,40];
z = s + p;
should work just fine, so please show your code and what error you are getting.
1 commentaire
lowcalorie
le 4 Mar 2012
Catégories
En savoir plus sur Polynomials dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!