polynomial-math

Find the coefficients of the polynomial given its roots

家住魔仙堡 提交于 2019-12-10 18:27:12
问题 I am trying to write an algorithm which will find a(0),..., a(n-1) , given the values of n, x_1, ..., x_n, a(n) , such that: a(n)*p^n + a(n-1)*p^(n-1) + ... + a(1)*p + a(0) = a(n)(p-x_1)(p-x_2)...(p-x_n) for all real p. After multiplying a(n)(p-x_1)(p-x_2) I've thought of using Viete's formulas to find the coefficients. But it turns out writing the code down isn't as obvious as I expected. I want to use only the basics in my code - that is loops, if-s addition and multiplication - no ready/

Evaluation issue using accumulators in Prolog to evaluate a polynomial

青春壹個敷衍的年華 提交于 2019-12-10 16:48:24
问题 Background I need to write a predicate eval(P,A,R), where: P represents a list of polynomial coefficients, i.e. 1+2x+3x^2 is represented as [1,2,3]. A represents the value for X. R is the result of the polynomial at X=A. Example: eval([3,1,2],3,R) produces R = 24. *edit, previously incorrect example I am trying to use accumulators from this article and example on Learn Prolog Now. My Algorithm: 0. Initialize result and exponent variables to 0. 1. Take the head of the list. 2. Multiply the

Isabelle: degree of polynomial multiplied with constant

一笑奈何 提交于 2019-12-10 12:13:02
问题 I am working with the library HOL/Library/Polynomial.thy . A simple property didn't work. E.g., the degree of 2x *2 is equal to the degree of 2x - How can I prove the lemmas (i.e., remove "sorry"): lemma mylemma: fixes y :: "('a::comm_ring_1 poly)" and x :: "('a::comm_ring_1)" shows "1 = 1" (* dummy *) proof- have "⋀ x. degree [: x :] = 0" by simp from this have "⋀ x y. degree (y * [: x :] ) = degree y" sorry (* different notation: *) from this have "⋀ x y. degree (y * (CONST pCons x 0)) =

i need to find the upper bound of this: or the tight bound:

人走茶凉 提交于 2019-12-10 11:56:05
问题 lets say i have an expression: (n)+((n-1)*2)+((n-2)*3)+((n-3)*4)+...+(3*(n-2))+(2*(n-1))+(1*(n)) what is the tight bound of this? or the upper bound? is this n^3? is this n^4? the maximum amount of number i can get out of this? thanks EDIT: so: for i=1 then: the ans is 1. i=2: (1*2 + 2*1) 1=3: (1*3 + 2*2 + 3*1) i=4: (1*4 + 2*3 + 3*2 + 4*1 ) and so on 回答1: Try Wolfram Alpha ... Sum[(i + 1) (n - i), {i, 0, n - 1}] 来源: https://stackoverflow.com/questions/4382014/i-need-to-find-the-upper-bound-of

Fast Exponentiation for galois fields

房东的猫 提交于 2019-12-10 08:09:02
问题 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

Vertical line fit using polyfit

牧云@^-^@ 提交于 2019-12-10 02:02:15
问题 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. 回答1: First

Print a polynomial using minimum number of calls

核能气质少年 提交于 2019-12-09 14:34:36
问题 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

How to calculate CRC-16 from HEX values?

人走茶凉 提交于 2019-12-09 06:54:41
问题 In my code i need to calculate CRC-16 16 bit values for the HEX values stored as NSdata, below is the code snippet to calculate CRC-16 in c. void UpdateCRC(unsigned short int *CRC, unsigned char x) { // This function uses the initial CRC value passed in the first // argument, then modifies it using the single character passed // as the second argument, according to a CRC-16 polynomial // Arguments: // CRC -- pointer to starting CRC value // x -- new character to be processed // Returns: //

Why do different methods for solving Xc=y in python give different solution when they should not?

扶醉桌前 提交于 2019-12-09 01:21:42
问题 I was trying to solve a linear system Xc=y that was square. The methods I know to solve this are: using inverse c=<X^-1,y> using Gaussian elimination using the pseudo-inverse It seems as far as I can tell that these don't match what I thought would be the ground truth. First generate the truth parameters by fitting a polynomial of degree 30 to a cosine with frequency 5. So I have y_truth = X*c_truth . Then I check if the above three methods match the truth I tried it but the methods don't

Roots of a Quartic Function

风流意气都作罢 提交于 2019-12-06 05:54:47
问题 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