Practical 6
Adding and Subtracting
The coefficient arrays of the polynomials can be added and subtracted.
> Exercise: Adding Polynomials with Coefficient Arrays > Add the following polynomial coefficient arrays: p = [3 -4 0 7 -9 3] q = [4 5 -6] p + q > What is the problem here? Re-define q as follows and check whether the addition works as you would expect. q = [0 0 0 4 5 -6] %Now terms with corresponding powers will be added p + q |
Note: To add or subtract two polynomials one should adjust their coefficient arrays putting zeros for absent powers, so that coefficients of terms with the same power will be on the same positions within both coefficient arrays. |