polynomial-math

How to properly set contrasts in R

浪子不回头ぞ 提交于 2019-12-06 04:01:21
问题 I have been asked to see if there is a linear trend in 3 groups of data (5 points each) by using ANOVA and linear contrasts. The 3 groups represent data collected in 2010 , 2011 and 2012 . I want to use R for this procedure and I have tried both of the following: contrasts(data$groups, how.many=1) <- contr.poly(3) contrasts(data$groups) <- contr.poly(3) Both ways seem to work fine but give slightly different answers in terms of their p-values. I have no idea which is correct and it is really

Fast Exponentiation for galois fields

假如想象 提交于 2019-12-05 18:17:03
I want to be able to compute g^x = g * g * g * ... * g (x times) where g is in a finite field GF(2^m). Here m is rather large, m = 256, 384, 512, etc. so lookup tables are not the solution. I know that there are really fast algorithms for a similar idea, modpow for Z/nZ (see page 619-620 of HAC ). What is a fast, non-table based way to compute cycles (i.e. g^x)? This is definitely a wishful question but here it comes: Can the idea of montgomery multiplication/exponentiation be 'recycled' to Galois fields? I would like to think so because of the isomorphic properties but I really don't know.

numpy.polyfit with adapted parameters

喜你入骨 提交于 2019-12-05 13:38:14
Regarding to this: polynomial equation parameters where I get 3 parameters for a squared function y = a*x² + b*x + c now I want only to get the first parameter for a squared function which describes my function y = a*x² . With other words: I want to set b=c=0 and get the adapted parameter for a . In case I understand it right, polyfit isn't able to do this. Bas Swinckels This can be done by numpy.linalg.lstsq . To explain how to use it, it is maybe easiest to show how you would do a standard 2nd order polyfit 'by hand'. Assuming you have your measurement vectors x and y , you first construct a

Vertical line fit using polyfit

半城伤御伤魂 提交于 2019-12-05 01:58:01
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 just a line fit. I can try swapping X and Y and then fir a line. Any easier method because I have lots of sets of scatter points and want a general method to check lines. Main goal is to find good-fit lines and drop non-linear features. Andrey Rubshtein First of all, this happens due to the method of fitting that you are using. When doing polyfit ,

Roots of a Quartic Function

大城市里の小女人 提交于 2019-12-04 10:03:07
I came across a situation doing some advanced collision detection, where I needed to calculate the roots of a quartic function. I wrote a function that seems to work fine using Ferrari's general solution as seen here: http://en.wikipedia.org/wiki/Quartic_function#Ferrari.27s_solution . Here's my function: private function solveQuartic(A:Number, B:Number, C:Number, D:Number, E:Number):Array{ // For paramters: Ax^4 + Bx^3 + Cx^2 + Dx + E var solution:Array = new Array(4); // Using Ferrari's formula: http://en.wikipedia.org/wiki/Quartic_function#Ferrari.27s_solution var Alpha:Number = ((-3 * (B *

Lagrange interpolation in Python

五迷三道 提交于 2019-12-04 05:45:14
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] return reduce(operator.mul, p) assert len(x_values) != 0 and (len(x_values) == len(y_values)), 'x and y cannot be empty and must have the same length' k = len(x_values) return sum(_basis(j) for j in xrange(k)) I followed Wikipedia , but when I run it I receive an IndexError at line 3! Thanks Check the indices, Wikipedia says "k+1 data points", but you're setting k = len(x

Why is this polynomial equation badly conditioned?

半城伤御伤魂 提交于 2019-12-04 05:03:11
问题 I have 1x1024 matrix. So I'd like to estimate a polynomial equation. X= (0:1023)' Y= acquired data. A 1024 element vector Then I try this in MATLAB: polyfit(x,y,5) But MATLAB makes an abnormal result with warning. Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the ... I don't understand what am I doing wrong? Update I got a bunch of numbers like this. Y= -0.0000000150 ... 0.00001 ... 0 ... 0.17 X= 0~255 polyfit(X,Y,4) I got a polynomial but

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

有些话、适合烂在心里 提交于 2019-12-04 00:21:55
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 one. Right now I'm using interval arithmetic as a quick check to see if I can prove that no roots can exist. If I can't, I'm using Jenkins-Traub to solve for all of the polynomial roots. This is obviously inefficient since it's checking for all real roots and finding their exact positions, information I don't end up needing. Is there a standard

Print a polynomial using minimum number of calls

血红的双手。 提交于 2019-12-04 00:14:39
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 are. You have to write a function that determines the coefficients using as few calls to poly as possible. My idea is to use recursion knowing that I can get the last coefficient by poly(0) . So I want to replace poly with (poly - poly(0))/x , but I don't know how to do this in code, since I can only call poly . ANyone have an idea how to do this? Here's

How to calculate coefficients of polynomial using Lagrange interpolation

亡梦爱人 提交于 2019-12-03 16:20:44
问题 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 y value for specific X (W(x) function) is simple but I need to calculate coefficients of polynomial (array of [a0, a1, ..., an]) I need to do this to n<=10 but it will be nice to have arbitrary n, then I can put that function into horner function