polynomial-math

How can I create functions that handle polynomials?

时间秒杀一切 提交于 2020-01-23 07:03:40
问题 I have these problems about polynomials and I've spent about 4 hours on this, but I just can't get it. I'm new to Python and programming and I've tried working it out on paper, but I just don't know. Write and test a Python function negate(p) that negates the polynomial represented by the list of its coeffeicients p and returns a new polynomial (represented as a list). In other words, write a function that makes the list of numbers negative. Write a Python function eval_polynomial(p, x) that

Horner's rule for two-variable polynomial

狂风中的少年 提交于 2020-01-21 11:26:07
问题 Horner's rule is used to simplify the process of evaluating a polynomial at specific variable values. https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML I've easily applied the method using SML, to a one variable polynomial, represented as an int list: fun horner coeffList x = foldr (fn (a, b) => a + b * x) (0.0) coeffList This works fine. We can then call it using: - val test = horner [1.0, 2.0, 3.0] 2.0; > val test = 17.0 : real Where [1.0, 2.0, 3.0] is the

How do you compute the XOR Remainder used in CRC?

半世苍凉 提交于 2020-01-04 01:15:29
问题 I'm trying to remember how the math is worked out to compute the remainder of an XOR algorithm in Cyclical Redundancy Checks to verify the remainder bits of a network message. I shouldn't have tossed that text book. This is easily done in code, but how is it worked out by hand? I know it looks something like a standard division algorithm, but I can't remember where to go from there to get the remainder. ___________ 1010 | 101101000 Note: I did google it, but wasn't able to find a place where

How do you compute the XOR Remainder used in CRC?

青春壹個敷衍的年華 提交于 2020-01-04 01:15:07
问题 I'm trying to remember how the math is worked out to compute the remainder of an XOR algorithm in Cyclical Redundancy Checks to verify the remainder bits of a network message. I shouldn't have tossed that text book. This is easily done in code, but how is it worked out by hand? I know it looks something like a standard division algorithm, but I can't remember where to go from there to get the remainder. ___________ 1010 | 101101000 Note: I did google it, but wasn't able to find a place where

Polynomials with negative exponents in Python

夙愿已清 提交于 2020-01-03 17:50:31
问题 Is there a library to work with polynomial arithmetic when polynomials can have negative exponents? I found the poly1d class in numpy, but I cannot figure out how I could represent a polynomial like x**-3 + x**-2 + x**2 + x**3 . 回答1: To quote Wikipedia: In mathematics, a polynomial is an expression of finite length constructed from variables (also called indeterminates) and constants, using only the operations of addition, subtraction, multiplication, and non-negative integer exponents. What

numpy.polyfit with adapted parameters

只愿长相守 提交于 2020-01-02 05:58:30
问题 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. 回答1: 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

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

若如初见. 提交于 2020-01-02 02:28:33
问题 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 a list of integers(*) and I've implemented all the basic operations in the most straightforward way. I'd like the exponentiation and multiplication to be as fast as possible, and to obtain this I've already tried different approaches. My

Using Prolog to compute the GCD of a polynomial

和自甴很熟 提交于 2019-12-31 03:51:25
问题 The title kind of says it all. I'm looking to compute the GCD of two polynomials. Is there any way this can be done in Prolog? If so, what's a good starting point? Specifically, I'm having trouble with how to implement polynomial division using Prolog. Edit to include example input and output: Example input: ?- GCD(x^2 + 7x + 6, x2 − 5x − 6, X). Example output: X = x + 1. Solution On the off chance that someone else needs to do this, here's my final solution: tail([_|Tail], Tail). head([Head

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

好久不见. 提交于 2019-12-28 13:21:31
问题 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 numpy.polyfit but for a 2D polynomial. This question is similar, but the solution is provided via MATLAB. 回答1: Here is an example showing how you can use numpy.linalg.lstsq for this task: import numpy as np x = np.linspace(0, 1, 20) y = np.linspace(0, 1

How to extend the line of 2 PolyFit from either side to intersect and get a combined fit line

99封情书 提交于 2019-12-25 08:34:41
问题 I am trying to get combined fit line made from two linear polyfit from either side (should intersect), here is the picture of fit lines: I am trying to make the two fit (blue) lines intersect and produce a combined fit line as shown in the picture below: Note that the crest can happen anywhere so I cannot assume to be in the center. Here is the code that creates the first plot: xdatPart1 = R; zdatPart1 = z; n = 3000; ln = length(R); [sX,In] = sort(R,1); sZ = z(In); xdatP1 = sX(1:n,1); zdatP1