Question

Write a function that takes a list L = [a0,a1,....,an] of coefficients of a polynomial p(x)...

Write a function that takes a list L = [a0,a1,....,an] of coefficients of a polynomial p(x) = a0xn+a1xn-1+...+ an

as a single argument, factors the free coefficient , and prints all integer roots or an empty list if there is no integer roots

in Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import numpy as np


# Utility method to find a number is integer or not
def is_int(x):
    if x % 1 == 0:
        return True
    else:
        return False


# Calculate roots and check if root is integer then print other
# print empty list is no integer roots found.

def calculate_roots(coefficient):
    roots = np.roots(coefficient)
    found = False
    for root in roots:
        if is_int(root):
            found = True
            print(root)

    if not found:
        print([])


# Call the method pass list of coefficients
calculate_roots([2, -2])
Add a comment
Know the answer?
Add Answer to:
Write a function that takes a list L = [a0,a1,....,an] of coefficients of a polynomial p(x)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Horner: Given the coefficients of a polynomial a0, a1, . . . , an, and a...

    Horner: Given the coefficients of a polynomial a0, a1, . . . , an, and a real number x0, find P(x0), P′ (x0), P′′(x0), P(3)(x0), . . . , P(n) (x0) Sample input representing P(x) = 2 + 3x−x 2 + 2x 3 , x0 = 3.5: 3 2 3 -1 2 3.5 the first number is the degree of the polynomial (n), the coefficients are in order a0, a1, . . . , an, the last number is x0....

  • Theorem. Let p(x) = anr" + … + ao be a polynomial with integer coefficients, i,...

    Theorem. Let p(x) = anr" + … + ao be a polynomial with integer coefficients, i, e. each ai E Z. If r/s is a rational root of p (expressed in lowest terms so that r, s are relatively prime), then s divides an and r divides ao Use the rational root test to solve the following: + ao is a monic (i.e. has leading coefficient 1) polynomial with integer coefficients, then every rational root is in fact an integer....

  • write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and...

    write easiest program to under stand:- a) Python program that takes three coefficients (a, b, and c) of a Quadratic equation (ax2+bx+c=0) as input and compute all possible roots b).User defined function isprime(num) that accepts an integer argument and returns 1 if the argument is prime, a 0 otherwise. Write a Python program that invokes this function to generate prime numbers between the given ranges

  • Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e....

    Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return: 1. List (of tuples) containing all pairs of numbers in L that are coprime. 2. Empty list, If no pair of numbers in L is coprime. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is...

  • 1. Write a Lisp function called piece which takes a single argument x and implements the followin...

    1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...

  • Write a polynomial function in standard form with leading coefficient 1, degree 4, integer coefficients, and...

    Write a polynomial function in standard form with leading coefficient 1, degree 4, integer coefficients, and some of its zeros are 2, -1, 5i. Show all work.

  • Consider the recurrence relation an=n2an−1−an−2an=n2an−1−an−2 with initial conditions a0=1a0=1 and a1=2a1=2. Write a Python function called...

    Consider the recurrence relation an=n2an−1−an−2an=n2an−1−an−2 with initial conditions a0=1a0=1 and a1=2a1=2. Write a Python function called sequence_slayer that takes a nonnegative integer argument NN less than 50 and returns the NN-th term in the sequence defined by the above recurrence relation. For example, if N=2N=2, your function should return sequence_slayer(2) = 7, because aN=a2=(2)2⋅(2)−(1)=7aN=a2=(2)2⋅(2)−(1)=7. For example: Test Result print(sequence_slayer(2)) 7 print(sequence_slayer(3)) 61 print(sequence_slayer(8)) 2722564729

  • Python 2.7 Write a function cumsum() that takes a list l as argument and returns the...

    Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....

  • Write a Python function named print_nums that takes a single parameter, a list of float values,...

    Write a Python function named print_nums that takes a single parameter, a list of float values, and prints out the list on a single line.enclosed in brackets, each value with three places after the decimal point, the values separated by two spaces. You do not have to provide comments for this code. Example 1: print_nums([3/3, 4/3, 573, 6/3]) prints: [1.000 1.333 1.667 2.000] Example 2: print_nums([3]) prints: [3.000] Example 3: print_nums([]) prints: []

  • Write a recursive function sum-odds that takes a non-empty list of integers

    in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT