Questions tagged [polynomial-math]

Polynomial Math is a subset of mathematics dealing with mathematical expressions constructed from variables and constants using only the operations of addition, subtraction, multiplication, and non-negative integer exponents. Any polynomial math question should be programming related.

630 questions
13
votes
2 answers

Fast factorization of polynomial with integers coefficients

I want to fast decompose polynomial over ring of integers (original polynomial has integer coefficients and all of factors have integer coefficients). For example I want to decompose 4*x^6 + 20*x^5 + 29*x^4 - 14*x^3 - 71*x^2 - 48*x as (2*x^4 + 7*x^3…
petRUShka
  • 9,812
  • 12
  • 61
  • 95
13
votes
2 answers

Roots of a polynomial mod a prime

I'm looking for a speedy algorithm to find the roots of a univariate polynomial in a prime finite field. That is, if f = a0 + a1x + a2x2 + ... + anxn (n > 0) then an algorithm that finds all r < p satisfying f(r) = 0 mod p, for a given prime p. I…
Kevin Johnson
  • 820
  • 11
  • 24
12
votes
1 answer

Why is `poly` complaining about degree less than number of unique points?

I am trying to generate orthogonal polynomials in R, but I keep getting an error I don't understand > poly(1:1000, 50) Error in poly(1:1000, 50) : 'degree' must be less than number of unique points Surely the number of unique points is 1000? …
Corvus
  • 7,548
  • 9
  • 42
  • 68
11
votes
1 answer

How to implement polynomial logistic regression in scikit-learn?

I'm trying to create a non-linear logistic regression, i.e. polynomial logistic regression using scikit-learn. But I couldn't find how I can define a degree of polynomial. Did anybody try it? Thanks a lot!
Inna
  • 663
  • 8
  • 12
11
votes
2 answers

Vertical line fit using polyfit

Its just a basic question. I am fitting lines to scatter points using polyfit. I have some cases where my scatter points have same X values and polyfit cant fit a line to it. There has to be something that can handle this situation. After all, its…
Naresh
  • 633
  • 1
  • 7
  • 26
10
votes
8 answers

Solving a Linear Diophantine Equation(see description for examples)

Let me start off by clarifying that(before you guys dismiss me), this is not a homework problem and I'm not a university student. :) EDIT Thanks to @Klas and others, my question now boils down to a mathematical equation which needs to be solved…
pavanlimo
  • 4,122
  • 3
  • 32
  • 47
10
votes
4 answers

Lagrange interpolation in Python

I want to interpolate a polynomial with the Lagrange method, but this code doesn't work: def interpolate(x_values, y_values): def _basis(j): p = [(x - x_values[m])/(x_values[j] - x_values[m]) for m in xrange(k + 1) if m != j] …
rubik
  • 8,814
  • 9
  • 58
  • 88
10
votes
2 answers

Need to fit polynomial using chebyshev polynomial basis

I have been fitting linear least-squares polynomials to data using the polyfit function in matlab. From what I read, this uses standard polynomial basis (monomial basis). I have read that using Chebyshev polynomial basis to fit leads to greater…
user1593853
  • 127
  • 1
  • 1
  • 7
9
votes
1 answer

Most efficient way to compute a polynomial

Polynomial: a0x^0 + a1x^1 +a2x^2 + a3x^3 + ... + anx^n Array: array_a[] = {a0, a1, a2, a3 ... an}; I wrote a function to calculate this polynomial in Java: public double cal(double x) { double y = 0.0; for (int index = array_a.length - 1;…
Louis Tran
  • 1,154
  • 1
  • 26
  • 46
9
votes
2 answers

Finding polynomial roots using Python -- Possible Numpy Extension Bug

I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'. My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3. (Simple) But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?) Could…
Fake Howard
  • 93
  • 1
  • 1
  • 3
8
votes
1 answer

Bairstow's method initial quadratic approximations

Bairstow's root finding method needs very good initial approximations for the quadratic factors in order to converge. I tried various constants, random numbers, fractions out of the trailing coefficient (-a1/a2, -a0/a2; by Lin?) to no avail. Please,…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
8
votes
2 answers

identify graph uptrend or downtrend

I am attempting to read in data and plot them on to a graph using python (standard line graph). Can someone please advise on how I can classify whether certain points in a graph are uptrends or downtrends programmatically? Which would be the most…
godzilla
  • 3,005
  • 7
  • 44
  • 60
8
votes
3 answers

Solving system of nonlinear equations with python

Can I solve a system of nonlinear equations in terms of parameters in python? Is there a example or tutorial? I can do this easily in maple, but the expressions for my particular system are pretty big and copying them over is quite hard. Example:…
8
votes
4 answers

Optimize conversion between list of integer coefficients and its long integer representation

I'm trying to optimize a polynomial implementation of mine. In particular I'm dealing with polynomials with coefficients modulo n(might be >2^64) and modulo a polynomial in the form x^r - 1(r is < 2^64). At the moment I represent the coefficient as…
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
8
votes
8 answers

How to store a polynomial?

Integers can be used to store individual numbers, but not mathematical expressions. For example, lets say I have the expression: 6x^2 + 5x + 3 How would I store the polynomial? I could create my own object, but I don't see how I could represent…
fdh
  • 5,256
  • 13
  • 58
  • 101
1
2
3
41 42