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
93
votes
5 answers

Fitting polynomial model to data in R

I've read the answers to this question and they are quite helpful, but I need help. I have an example data set in R as follows: x <- c(32,64,96,118,126,144,152.5,158) y <- c(99.5,104.8,108.5,100,86,64,35.3,15) I want to fit a model to these data…
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
38
votes
2 answers

What's the opposite of JavaScript's Math.pow?

I'm having a mental block here, and algebra not really being my thing, can you tell me how to re-write the JavaScript code below to derive the variable, c, in terms of a and b?: a = Math.pow(b, c); c = ? Thanks!
Prem
  • 15,911
  • 11
  • 31
  • 35
35
votes
4 answers

Implementing SSE 4.2's CRC32C in software

So I have a design which incorporates CRC32C checksums to ensure data hasn't been damaged. I decided to use CRC32C because I can have both a software version and a hardware-accelerated version if the computer the software runs on supports SSE…
LMS
  • 4,117
  • 5
  • 27
  • 37
32
votes
5 answers

Equivalent of `polyfit` for a 2D polynomial in Python

I'd like to find a least-squares solution for the a coefficients in z = (a0 + a1*x + a2*y + a3*x**2 + a4*x**2*y + a5*x**2*y**2 + a6*y**2 + a7*x*y**2 + a8*x*y) given arrays x, y, and z of length 20. Basically I'm looking for the equivalent of…
Justin Gabitzsch
  • 395
  • 1
  • 4
  • 7
25
votes
1 answer

What type of orthogonal polynomials does R use?

I was trying to match the orthogonal polynomials in the following code in R: X <- cbind(1, poly(x = x, degree = 9)) but in python. To do this I implemented my own method for giving orthogonal polynomials: def get_hermite_poly(x,degree): …
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
18
votes
3 answers

Problems in implementing Horner's method in Python

So I have written down the codes for evaluating polynomial using three different methods. Horner's method should be the fastest, while the naive method should be the slowest, right? But how come the time for computing it is not what I expect? And…
Physicist
  • 2,848
  • 8
  • 33
  • 62
17
votes
3 answers

How to represent polynomials with numeric vectors in R

In R how would one represent polynomial expressions and do polynomial math with the numeric vector objects? For example: x1 <- c(2,1) # 2 + x x2 <- c(-1,3) # -1 + 3*x And want: x1 * x2 # to return -2 + 5*x + 3*x^2 Note: I answered a question…
IRTFM
  • 258,963
  • 21
  • 364
  • 487
16
votes
1 answer

"Polynomial too big for FFT" error on NTL

I'm trying to perform a multiplication of polynomials of degree 4096 using ZZ_pEX class from NTL. However, it returns the error "Polynomial too big for FFT", and I couldn't find a way to make it works (or even something that could help on NTL's…
Pedro Alves
  • 1,667
  • 4
  • 17
  • 37
15
votes
4 answers

How to calculate coefficients of polynomial using Lagrange interpolation

I need to calculate coefficients of polynomial using Lagrange interpolation polynomial, as my homework, I decide to do this in Javascript. here is definition of Lagrange polynomial (L(x)) Lagrange basis polynomials are defined as follows Calculate…
jcubic
  • 61,973
  • 54
  • 229
  • 402
15
votes
5 answers

efficiently determining if a polynomial has a root in the interval [0,T]

I have polynomials of nontrivial degree (4+) and need to robustly and efficiently determine whether or not they have a root in the interval [0,T]. The precise location or number of roots don't concern me, I just need to know if there is at least…
user168715
  • 5,469
  • 1
  • 31
  • 42
15
votes
1 answer

fft division for fast polynomial division

I'm trying to implement fast polynomial division using Fast Fourier Transform (fft). Here is what I have got so far: from numpy.fft import fft, ifft def fft_div(C1, C2): # fft expects right-most for significant coefficients C1 = C1[::-1] …
gaborous
  • 15,832
  • 10
  • 83
  • 102
15
votes
2 answers

Complex-coefficient polynomial root finding in Java

I'm trying to find a way to compute roots of a polynomial with complex coefficients in Java (i.e. an equivalent of what is ridiculously easily done with roots() in MATLAB). I'm ready to recode a root finding algorithm that builds the companion…
Virginie
  • 289
  • 3
  • 11
13
votes
1 answer

Print a polynomial using minimum number of calls

I keep getting these hard interview questions. This one really baffles me. You're given a function poly that takes and returns an int. It's actually a polynomial with nonnegative integer coefficients, but you don't know what the coefficients…
Daniel
  • 944
  • 1
  • 7
  • 24
13
votes
1 answer

How to perform a complicated change of variables for a polynomial (in Mathematica)

I have an integer polynomial in four variables (w, x, y, and z) that I know can be written as an integer polynomial in these six variables: a = w z b = x y c = w^3 + z^3 d = x + y e = w^3 x + y z^3 f = w^3 y + x z^3 How can I use Mathematica (or…
Tyson Williams
  • 1,630
  • 15
  • 35
13
votes
2 answers

How to implement sklearn's PolynomialFeatures in tensorflow?

I am trying to implement scikit-learn's PolynomialFeatures as a layer in a feedforward neural network in tensorflow and Keras. I'll give an example using NumPy arrays for the sake of simplicity. If a batch has three samples and the activations of a…
Charlie Brummitt
  • 651
  • 6
  • 11
1
2 3
41 42