Problem One. Write a Sage function which takes as an input a polynomial p. The polynomial p will be a symbolic expression with integer coefficients. The function will return the count of how often the...

1 answer below »



  1. Problem One. Write a Sage function which takes as an input a polynomial p. The polynomial p will be a symbolic expression with integer coefficients. The function will return the count of how often the sign of the coefficients has changed. For instance the polynomial p(x) = x3 − x2 + x + 15 changes sign twice since the coefficients are 1, −2, 1, 15.


    Input example :



    problem1(11*x^6 - 6*x^5 + 5*x^4 - 58*x^3 - 51*x^2 + 9*x + 22)

    Output example: 4


    As part of your solution to this problem, provide the Sage function and the output for


    p = -2*x^7 + 3*x^6 - 28*x^5 + 44*x^4 - 11*x^3 - 71*x^2 + 6*x - 14

    Problem Two. Write a Sage function which takes as an input an integer M. Output the number of prime numbers ≤ M that are of the form k2 + k + 1. If M = 30 then the output would be 3 since there are three prime numbers ≤ 30 that are of the form k2 +k+1: 3 = 12 +11 +1,7 = 22 +22 +1 and 13=32 +3+1.


    Input example :



    problem2(300)

    Output example: 9






Solutions to this project must consist of a single, computer typed, PDF document, called project1.pdf, containing the Sage code and the answers for the four problems. For each problem, write a Sage func- tion, titled def problem1(), def problem2(), etc, with the appropriate input arguments. Problem One. Write a Sage function which takes as an input a polynomial p. The polynomial p will be a symbolic expression with integer coefficients. The function will return the count of how often the sign of the coefficients has changed. For instance the polynomial p(x) = x3 − x2 + x + 15 changes sign twice since the coefficients are 1, −2, 1, 15. Input example : problem1(11*x^6 - 6*x^5 + 5*x^4 - 58*x^3 - 51*x^2 + 9*x + 22) Output example: 4 As part of your solution to this problem, provide the Sage function and the output for p = -2*x^7 + 3*x^6 - 28*x^5 + 44*x^4 - 11*x^3 - 71*x^2 + 6*x - 14 Problem Two. Write a Sage function which takes as an input an integer M. Output the number of prime numbers ≤ M that are of the form k2 + k + 1. If M = 30 then the output would be 3 since there are three prime numbers ≤ 30 that are of the form k2 +k+1: 3 = 12 +11 +1,7 = 22 +22 +1 and 13=32 +3+1. Input example : problem2(300) Output example: 9 As part of your solution to this problem, provide the Sage function and the output for M = 10000. Problem Three. Write a Sage function which takes as an input a polynomial f with integer coefficients and a list L. The polynomial f will be a symbolic expression in the variable x. The list L consists of an unspecified number of sub-lists, each of which contains two integers which will be thought of as x and y coordinates. As an example of L, consider L = [[x1, y1], [x2, y2], [x3, y3], ...[xk, yk]]. This Sage functions returns all sub-lists in L, for which f(xi) = yi, for all xi and yi in sub-lists of L. Input example : problem3( 2*x^2-2*x+3, [[0, 3], [1, 4], [2, 7], [3, 17], [4, 33], [5, 43], [6, 63], [7, 87], [8, 116], [9, 147]]) Output example: [[0, 3], [2, 7], [5, 43], [6, 63], [7, 87], [9, 147]] As your solution to this problem, provide the Sage function and the output for f = x3 − x2 − 1 and L = [[0, −1], [1, −2], [2, 4], [3, 17], [4, 48], [5, 99], [6, 189], [7, 332]], that is, your output for problem3( x^3-x^2-1, [[0, -1], [1, -2], [2, 4], [3, 17], [4, 48], [5, 99], [6, 189], [7, 332]]) Problem Four. (a) Write a Sage function which takes on input as its argument an integer n and returns a random n degree polynomial with randomly generated integer coefficients. The randomly generated integer coefficients range from -50 to +50, inclusive. In addition to returning the randomly generated polynomial of degree n, the Sage function must return the number of real roots of the randomly generated polynomial. In particular, this Sage function returns the randomly generated polynomial and the number of its real roots in form of a Python tuple or a list. Input example : problem4(6), where n = 6. Output example: (11*x^6 - 13*x^5 + 47*x^4 + 6*x^3 - 14*x^2 + 14*x - 39, 2) · As your solution to this problem, provide the Sage function and the output for n = 4 and n = 11. · · (b) Using your function from part (a), generate 100 random polynomials of degree 13 and compute the average number of real roots. Do not output all polynomials, just output the average number of real roots.
Answered 12 days AfterSep 18, 2021

Answer To: Problem One. Write a Sage function which takes as an input a polynomial p. The polynomial p will be...

Ankur answered on Sep 30 2021
135 Votes
Solutions to this project must consist of a single, computer typed, PDF document, called project1.pdf, containing the Sage code and the answers for the four problems. For each problem, write a Sage func- tion, titled def problem1(), def problem2(), etc, with the appropriate input arguments.
Problem One.
Write a Sage function which takes as an input a polynomial p. The polynomial p will be a symbolic expression with integer coefficients. The function will return the count of how often the sign of the coefficients has changed. For instance the polynomial p(x) = x3 − x2 + x + 15 changes sign twice since the coefficients are 1, −2, 1, 15.
Solution: Sage function
Var(‘x’)
f= x3 − x2 + x + 15 %% Any polynomial can use
Sage : f.coefficients(sparse=False)
Sage :...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here