Questions tagged [polynomials]

In mathematics, a polynomial is an expression consisting of variables (or indeterminates) and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponents.

Filter by
Sorted by
Tagged with
59votes
1answer
52kviews

In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)

I'm trying to get my head around the use of the tilde operator, and associated functions. My 1st question is why does I() need to be used to specify arithmetic operators? For example, these 2 plots ...
user avatar
  • 4,763
34votes
2answers
28kviews

What does the capital letter "I" in R linear regression formula mean?

I haven't been able to find an answer to this question, largely because googling anything with a standalone letter (like "I") causes issues. What does the "I" do in a model like this? data(rock) lm(...
user avatar
  • 3,739
18votes
5answers
34kviews

Cannot understand with sklearn's PolynomialFeatures

Need help in sklearn's Polynomial Features. It works quite well with one feature but whenever I add multiple features, it also outputs some values in the array besides the values raised to the power ...
user avatar
13votes
2answers
6kviews

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 < ...
user avatar
13votes
2answers
2kviews

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 + ...
user avatar
  • 9,420
10votes
2answers
5kviews

Sympy: Drop higher order terms in polynomial

Using Sympy, say we have an expression f, which is a polynomial of the Symbol "x" (and of potentially other symbols). I would like to know what if there is an efficient way to drop all terms in f of ...
user avatar
  • 223
10votes
2answers
11kviews

Fitting a polynomial using np.polyfit in 3 dimensions

I have an array of data, with dimensions (N,3) for some integer N, that specifies the trajectory of a particle in 3D space, i.e. each row entry is the (x,y,z) coordinates of the particle. This ...
user avatar
10votes
1answer
2kviews

How to rewrite an expression in terms of an other expression in sympy

EDIT: I am not asking how to solve an equation in terms of a given variable (as in this supposed duplicated question), but how to represent an expression in terms of an other one, as specified in the ...
user avatar
  • 4,993
10votes
4answers
9kviews

Map which allows to provide the equals-comparator and the hashing function separately

While trying to model polynomials, in particular their multiplication, I run into the following problem. During the multiplication, the individual monomials of the two polynomials are multiplied and ...
user avatar
  • 3,998
10votes
2answers
520views

Ratio of polynomials approximation

I am trying to fit a polynomial to my dataset, which looks like that (full dataset is at the end of the post): The theory predicts that the formulation of the curve is: which looks like this (for x ...
user avatar
  • 225
9votes
2answers
2kviews

Color calibration with color checker using using Root-Polynomial Regression not giving correct results

For a quantification project, I am in need of colour corrected images which produce the same result over and over again irrespective of lighting conditions. Every image includes a X-Rite color-checker ...
user avatar
  • 401
9votes
1answer
2kviews

SymPy polynomials over finite fields

import sympy as S F = S.FiniteField(101) When I call f = S.poly(y ** 2 - x ** 3 - x - 1,F) I get the following error: 'FiniteField' object has no attribute 'is_commutative' But finite fields are ...
user avatar
8votes
5answers
10kviews

How to fit a polynomial with some of the coefficients constrained?

Using NumPy's polyfit (or something similar) is there an easy way to get a solution where one or more of the coefficients are constrained to a specific value? For example, we could find the ordinary ...
user avatar
8votes
2answers
2kviews

Python equivalent to R poly() function?

I'm trying to understand how to replicate the poly() function in R using scikit-learn (or other module). For example, let's say I have a vector in R: a <- c(1:10) And I want to generate 3rd ...
user avatar
8votes
3answers
2kviews

efficient way to take powers of a vector

I wrote a code that numerically uses Legendre polynomials up to some high n-th order. For example: .... case 8 p = (6435*x.^8-12012*x.^6+6930*x.^4-1260*x.^2+35)/128; return case 9 ... If the ...
user avatar
8votes
1answer
914views

A few questions about CRC basics

I am an electronic engineer and have not found it important to consider CRC from a purely mathematical perspective. However, I have the following questions: Why do we add n zeros to the message when ...
user avatar
  • 2,170
8votes
1answer
1kviews

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 ...
user avatar
  • 9,600
7votes
3answers
10kviews

Get the inverse function of a polyfit in numpy

I have fit a second order polynomial to a number of x/y points in the following way: poly = np.polyfit(x, y, 2) How can I invert this function in python, to get the two x-values corresponding to a ...
user avatar
  • 7,725
7votes
3answers
526views

How to find polynomial roots correctly?

Consider a polynomial such as: p = [1 -9 27 -27]; obviously the real root is 3: polyval(p,3) 0 While using the roots function q = roots([1 -9 27 -27]); with format short: q = 3.0000 + 0....
user avatar
  • 6,312
7votes
2answers
12kviews

Fit 3D Polynomial Surface with Python

I have a python code that calculates z values dependent on x and y values. Overall, I have 7 x-values and 7 y-values as well as 49 z-values that are arranged in a grid (x and y correspond each to one ...
user avatar
  • 962
7votes
1answer
2kviews

Fitting a polynomial with a known intercept

I am using lm(y~poly(x,2)) to fit a second-order polynomial to my data. But I just couldn't find a way to specify a known intercept value. How can I fit a polynomial model with a known intercept value ...
user avatar
  • 1,140
7votes
3answers
7kviews

Collecting like term of an expression in Sympy

I am currently dealing with functions of more than one variable and need to collect like terms in an attempt to simplify an expression. Say the expression is written as follows: x = sympy.Symbol('x')...
user avatar
  • 137
6votes
3answers
4kviews

List of coefficients to polynomial

How do I create a polynomial out of a list of coefficients in SymPy? For example, given a list [1, -2, 1] I would like to get Poly(x**2 - 2*x + 1). I tried looking at the docs but could not find ...
user avatar
  • 9,600
6votes
1answer
3kviews

Coefficients of polynomials maxima

Is there a built-in function in maxima to get from a polynomial function a list with its coefficients? And to get the degree of the polynomial? The most similar function I found is args, but it also ...
user avatar
6votes
2answers
2kviews

numpy calculate polynom efficiently

I'm trying to evaluate polynomial (3'd degree) using numpy. I found that doing it by simpler python code will be much more efficient. import numpy as np import timeit m = [3,7,1,2] f = lambda m,x: ...
user avatar
  • 1,296
6votes
1answer
411views

How is naive evaluation of polynomials bad for accuracy?

In this Code Review answer: https://codereview.stackexchange.com/a/59405/11633 I found the following (nested quote ahead!): Let me quote the wonderful book Numerical Recipes in C++ (but also ...
user avatar
6votes
3answers
846views

Function for polynomials of arbitrary order (symbolic method preferred)

I've found polynomial coefficients from my data: R <- c(0.256,0.512,0.768,1.024,1.28,1.437,1.594,1.72,1.846,1.972,2.098,2.4029) Ic <- c(1.78,1.71,1.57,1.44,1.25,1.02,0.87,0.68,0.54,0.38,0.26,0....
user avatar
6votes
1answer
189views

How to analyse a sparse adjacency matrix?

I am researching sparse adjacency matrices where most cells are zeros and some ones here-and-there, each relationship between two cells has a polynomial description that can be very long and their ...
user avatar
  • 47.3k
6votes
1answer
1kviews

Should I use numpy.polyfit or numpy.polynomial.polyfit or numpy.polynomial.polynomial.Polynomial?

What is the difference between https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html and https://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.polynomial.polyfit....
user avatar
  • 10.7k
6votes
4answers
4kviews

How to detect in real time a "knee/elbow" (maximal curvature) in a curve

In the following curve (blue line) I'm trying to detect the "knee/elbow" which should be located around x = 2.5 This is the set of values I'm using: x = {-10, -9, -8, -7, -6, -5, -4, -3, -...
user avatar
  • 301
6votes
1answer
4kviews

When can the Master Theorem actually be applied?

I am quite frustrated over this. In CLRS 3rd edition, page 95 (chapter 4.5), it mentions that recurrences like T(n) = 2T(n/2) + n lg n cannot be solved with the Master Theorem because the ...
user avatar
  • 1,874
5votes
1answer
2kviews

High (or very high) order polynomial regression in R (or alternatives?)

I would like to fit a (very) high order regression to a set of data in R, however the poly() function has a limit of order 25. For this application I need an order on the range of 100 to 120. model &...
user avatar
5votes
1answer
3kviews

Export fitted regression splines (constructed by 'bs' or 'ns') as piecewise polynomials

Take for instance the following one-knot, degree two, spline: library(splines) library(ISLR) fit.spline <- lm(wage~bs(age, knots=c(42), degree=2), data=Wage) summary(fit.spline) I see estimates ...
user avatar
  • 53
5votes
3answers
13kviews

How to find the best degree of polynomials?

I'm new to Machine Learning and currently got stuck with this. First I use linear regression to fit the training set but get very large RMSE. Then I tried using polynomial regression to reduce the ...
user avatar
5votes
3answers
1kviews

Polynomial function cannot be solved by Python sympy

I have problems by solving a polynomial function with sympy. The following example shows a case which gives an error message that I cannot manage. If the polynomial gets simpler the solver works ...
user avatar
  • 93
5votes
1answer
561views

Why is Numpy inconsistent in ordering polynomial coefficients by degree?

numpy.polynomial.polynomial.Polynomial stores polynomial coefficients in order of increasing degree, while numpy.poly1d stores polynomial coefficients in order of decreasing degree. Is there a reason ...
user avatar
  • 429
5votes
3answers
10kviews

Checking the error detection capabilities of CRC polynomials

I tried to find out how to calculate the error detection capabilities of arbitrary CRC polynomials. I know that there are various error detection capabilities that may (or may not) apply to an ...
user avatar
  • 7,797
5votes
2answers
507views

numpy polynomial.Polynomial.fit() gives different coefficients than polynomial.polyfit()

I do not understand why polynomial.Polynomial.fit() gives coefficients very different from the expected coefficients : import numpy as np x = np.linspace(0, 10, 50) y = x**2 + 5 * x + 10 print(np....
user avatar
  • 1,372
5votes
1answer
4kviews

Confidence interval of polynomial regression

I have a little issue with R and statistics. I fitted a model with the Maximum Likelihood method, who gave me the following coefficients with their respective Standard Errors (among other parameters ...
user avatar
  • 109
5votes
1answer
50views

How to create Polynomial Ring which has Float coefficients Julia

I want to create a polynomial ring which has float Coefficients like this. I can create with integers but, Floats does not work. using Oscar S, (a,b,c,d) = PolynomialRing(QQ,["a","b&...
user avatar
5votes
1answer
594views

Yun's algorithm

I would like to try to implement Yun's algorithm for square-free factorization of polynomials. From Wikipedia (f is the polynomial): a0 = gcd(f, f'); b1 = f/a0; c1 = f'/a0; d1 = c1 - b1'; i = 1 ...
user avatar
  • 463
5votes
1answer
376views

Java library for estimating a polynomial based on a set of points

The polynomial's degree should be # of points - 1 e.g. if there are 2 points given it should be a line. I know I can solve this using a matrix e.g. if there are 4 points: the polynomial would be y ...
user avatar
5votes
1answer
1kviews

Plotly: How to add polynomial fit line to plotly go.scatter figure using a DASH callback?

I'd like to add a polynomial curve to a scatter plot that is rendered using a callback. Following is my callback function which returns the scatter plot. @app.callback(Output('price-graph', 'figure'), ...
user avatar
  • 1,323
5votes
1answer
2kviews

How to exclude values from a polynomial fit?

I fit a polynomial to my data, as shown in the figure: Using the script: from scipy.optimize import curve_fit import scipy.stats from scipy import asarray as ar,exp xdata = xvalues ydata = ...
user avatar
  • 151
5votes
1answer
1kviews

Solving polynomials with complex coefficients using sympy

I'm very new to python so forgive me if this has a simple fix. I'm trying to solve polynomials with complex coefficients using sympy. I find that I get a blank output if k is 'too complicated'... I'm ...
user avatar
5votes
2answers
1kviews

Naive Recursive Algorithm for Polynomial Multiplication in Python

I am trying to implement the divide-and-conquer algorithm for polynomial multiplication. Here is the pseudocode given in the lecture notes: where A, B are lists of coefficients of each polynomial, n ...
user avatar
5votes
1answer
1kviews

Reading a text file and converting them into polynomials

I currently have a text file as follows: 3 5 6 9 3 4 6 7 2 3 5 7 2 5 3 The file when read into java should be displayed as 3x^5 + 6x^9. The second line would be read as 4x^4 + 6x^7 + 2. The cannot ...
user avatar
5votes
2answers
2kviews

How do you make R poly() evaluate (or "predict") multivariate new data (orthogonal or raw)?

With the poly function in R, how do I evaluate a multivariate polynomial? This post has 4 questions total, highlighted below. I'm seeking to evaluate the output of a poly()-output object (orthogonal ...
user avatar
  • 119
5votes
1answer
829views

Why does Sympy cut off polynomial terms with small coefficients?

I am trying to convert an expression containing terms with various degrees of a symbolic variable z_s into a polynomial in python using sympy.Poly() so that I can then extract the coefficients using ....
user avatar
5votes
1answer
178views

Optimizing a set of polynomials for computation speed

I have a set of polynomial expressions produced by a computer algebra system (CAS). For example, this is one element of this set. -d*d*l*l*q-b*b*l*l*q+2*d*f*j*l*q+2*b*f*h*l*q-f*f*j*j*q-b*b*j*j*q+2*b*...
user avatar

15 30 50 per page
1
2 3 4 5
18