polynomials

SymPy: Factorization of polynomials over symbolic roots with combined square roots

╄→гoц情女王★ 提交于 2020-06-28 03:55:32
问题 SymPy factor function can factorize over symbolic roots, e.g. : In [1]: from sympy import * In [2]: init_printing(use_latex=False) In [3]: z, a, b = symbols('z a b') In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [5]: poly Out[5]: 2 √a⋅√b - √a⋅z - √b⋅z + z In [6]: factor(poly, z) Out[6]: (-√a + z)⋅(-√b + z) but the factorization fails if b = a : In [10]: b = a In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [12]: poly Out[12]: 2 -2⋅√a⋅z + a + z In [13]: factor(poly, z) Out

SymPy: Factorization of polynomials over symbolic roots with combined square roots

自作多情 提交于 2020-06-28 03:55:03
问题 SymPy factor function can factorize over symbolic roots, e.g. : In [1]: from sympy import * In [2]: init_printing(use_latex=False) In [3]: z, a, b = symbols('z a b') In [4]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [5]: poly Out[5]: 2 √a⋅√b - √a⋅z - √b⋅z + z In [6]: factor(poly, z) Out[6]: (-√a + z)⋅(-√b + z) but the factorization fails if b = a : In [10]: b = a In [11]: poly = expand((z - sqrt(a))*(z - sqrt(b)), z) In [12]: poly Out[12]: 2 -2⋅√a⋅z + a + z In [13]: factor(poly, z) Out

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

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-25 09:11:18
问题 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 question. I believe it is the "duplicated" question to have a misleading title. I am very new with SymPy. I have an expression that, once expressed in terms to an other expression, should become very nice. The problem is that I don't know how to "force" to express the original expression in terms

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

让人想犯罪 __ 提交于 2020-06-25 09:10:58
问题 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 question. I believe it is the "duplicated" question to have a misleading title. I am very new with SymPy. I have an expression that, once expressed in terms to an other expression, should become very nice. The problem is that I don't know how to "force" to express the original expression in terms

How to find the best degree of polynomials?

纵然是瞬间 提交于 2020-05-09 18:55:06
问题 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 bias. import numpy as np from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures from sklearn.metrics import mean_squared_error poly_features = PolynomialFeatures(degree=2, include_bias=False) X_poly = poly_features.fit_transform(X) poly_reg =

Setting up array of complex coefficients, avoiding the leading zero's

半世苍凉 提交于 2020-03-25 04:22:41
问题 I have created a class for complex numbers: public class Complex { private double x; //Real part x of the complex number x+iy. private double y; //Imaginary part y of the complex number x+iy. public Complex(double x, double y) { //Constructor: Initializes x, y. this.x=x; this.y=y; } public Complex(double x) { //Real constructor - initialises with a real number. this(x, 0.0); } public Complex() { //Default constructor; initialiase x and y to zero. this(0.0, 0.0); } } What I would like to do is

What's a floating-point operation and how to count them (in MATLAB)?

こ雲淡風輕ζ 提交于 2020-02-03 12:18:52
问题 I have an assignment where I basically need to count the number of floating point operations in a simple program, which involves a loop, a matrix, and operations such as *, + and ^. From my understanding, a floating-point operation is an operation that involves floating-point numbers, and we may be interested in counting these operations because I think they may be more expensive for the computer. If you want to add more details to this part, it would be nice. My problem is that I've no idea

Get the inverse function of a polyfit in numpy

一笑奈何 提交于 2020-01-23 07:53:33
问题 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 specific y-value? 回答1: Here's an example that shows how you can combine your poly with my answer at Inverse function of numpy.polyval(). First some data: In [44]: x Out[44]: array([0, 1, 2, 3, 4, 5, 6, 7]) In [45]: y Out[45]: array([ 9, 4, 0, -1, -1, 4, 8, 16]) Fit a polynomial to the data: In [46]: