Polynomial Calculus
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
In this problem, we'll explore methods for computing symbolic derivatives and integrals of polynomials.
For this question, let's represent Polynomials in x as lists of coefficients,
starting with the zeroth-order coefficient. For example, we would represent
x^2 as [0, 0, 1]
and 4x^3 + 7x - 8 as [-8, 7, 0, 4]
.
Write a program that computes the symbolic derivative of a polynomial given in this form. This problem relies heavily on the power rule, or the fact that the derivative is x^n is nx^{n-1}. We can perform the derivative on each term of the polynomial independently.
The first line of your program should set a variable poly
to hold the input
polynomial, in the form described above. When run, your code should print a
single list representing the derivative of the given polynomial, in the same
format.
For example, if your program is run with the following polynomial (representing 4x^3 + \frac{1}{2}x^2):
poly = [0, 0, 1/2, 4] # representing 1/2 x^2
then your program should print a list representing 12x^2 + x:
[0, 1, 12]
Notes
- In order to print the proper value in the end, you'll want to construct a new list. Here are two possible strategies for this:
- Figure out the length that the output list will be. Make a list of that length which contains only zeros, or only
None
s (or some othe default value). Then, replace the entries in that list with the appropriate values. - Start with an empty list,
[]
, and add the appropriate values one by one usingappend
.
- Figure out the length that the output list will be. Make a list of that length which contains only zeros, or only
- In some cases, you may find it helpful to loop over the indices of a list, rather than over the elements in the list. A nice way to loop over those indices is to write, for example,
for index in range(len(my_list))
instead offor value in my_list
. This allows you to use the index in computation, and you can still get the associated element via, for example,my_list[index]
. - You should choose some of your favorite polynomials and use those as test cases on your own machine.
Once you have simulated by hand and tested on your own machine, and are convinced that your program will do the right thing, upload your file below for testing:
Now we'll do symbolic integration of polynomials. We'll represent polynomials in the same form we used above, and like before we can use the power rule for integration on each term where x^n would have an integral of \frac{1}{n+1}x^{n+1}
The first two lines of this program should define two
variables: poly
should store the input polynomial (as before), as const
should store a single number:
poly = [0, 0, 1/2]
const = 15
then your program should print a list representing 15 + \frac{1}{6}x^3:
[15, 0, 0, 1/6]
Your program should print the coefficient list associated with the symbolic
integral of poly
, with the specified constant const
as the constant term.
As before, you should make a plan, write and simulate by hand, and then run and test on your own machine.
Once you have simulated by hand and tested on your own machine, and are convinced that your program will do the right thing, upload your file below for testing: