天道酬勤,学无止境

polynomial-math

使用法拉利的方法找到四次方程的实根(Finding real roots of quartic equation using ferrari's method)

问题 我目前正在尝试使用维基百科中的法拉利方法求解四次方程。 我只想检索真正的根,丢弃虚构的根。 我的实现没有为真正的根返回良好的价值。 我找不到公式中的错误。 我的CubicEquation按预期工作,我的双二次求解也是如此。 现在,我只是想念法拉利的方法,但我不能让它发挥作用! 这是我的课: public class QuarticFunction { private final double a; private final double b; private final double c; private final double d; private final double e; public QuarticFunction(double a, double b, double c, double d, double e) { this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; } public final double[] findRealRoots() { if (a == 0) { return new CubicEquation(b, c, d, e).findRealRoots(); } if (isBiquadratic()) { //This part works as expected

2021-09-16 03:42:10    分类:技术分享    java   math   trigonometry   polynomial-math   equation-solving

使用霍纳算法评估多项式并计算步骤 (Java)(Evaluating a polynomial with Horner's Algorithm and calculating steps (Java))

问题 我需要有关我的 Java 代码的帮助。 我想要完成的是计算多项式上每一步的大小: double s = (ba)/nsteps; 为将要创建的多项式的输入为度,系数,启动的值x ,停止的值x ,和步数。 每当我尝试运行测试时, x和y输出都是0 ,我不确定我的代码缺少什么。 这是我对其应该如何工作的运行测试,但我对x和y结果是0 : Enter degree:2 Enter coefficient 2:1 Enter coefficient 1:0 Enter coefficient 0:0 f(x) = 1.0x^2 + .0x^1 + 0.0 Enter initial x:0 Enter final x:10 Enter number of steps:20 x = 0.0; f(x) = 0.0 x = 0.5; f(x) = 0.25 x = 1.0; f(x) = 1.0 x = 1.5; f(x) = 2.25 x = 2.0; f(x) = 4.0 x = 2.5; f(x) = 6.25 x = 3.0; f(x) = 9.0 x = 3.5; f(x) = 12.25 x = 4.0; f(x) = 16.0 x = 4.5; f(x) = 20.25 x = 5.0; f(x) = 25.0 x = 5.5; f(x) = 30.25 x = 6.0

2021-09-12 03:14:07    分类:技术分享    java   evaluation   polynomial-math

对两个多项式求和(Summing two polynomials)

问题 我正在寻找对两个多项式求和的内置 Matlab 函数。 例子: p1(x) 和 p2(x) 用代码标准 Matlab 向量表示: p1 = [500 400 300 200 100 50]; p2 = [3 2 1 5]; 我如何使用内置的 Matlab 函数对这两个多项式求和以获得 ps(x); 无需编写显式的 m 文件函数? 回答1 我当然希望有更好的方法来做到这一点(我可能会将其放入辅助函数中),但这似乎工作得很好: [zeros(1, size(p1,2)-size(p2,2)) p2] + [zeros(1, size(p2,2)-size(p1,2)) p1] ans = 500 400 303 202 101 55 回答2 简单的。 编写一个小函数,命名为leftpadz。 leftpadz = @(p1,p2) [zeros(1,max(0,numel(p2) - numel(p1)))),p1]; 所以如果我们有... p1 = [500 400 300 200 100 50]; p2 = [3 2 1 5]; p3 = leftpadz(p1,p2) + leftpadz(p2,p1) p3 = 500 400 303 202 101 55 回答3 function c = polyadd( a, b) assert( isrow(a)) assert(

2021-09-11 00:57:09    分类:技术分享    matlab   sum   polynomial-math   built-in

How to generate a symbolic multivariate polynomial of a given dimension in SymPy?

I want to use power series to approximate some PDEs. The first step I need to generate symbolic multivariate polynomials, given a numpy ndarray. Consider the polynomial below: I want to take a m dimensional ndarray of D=[d1,...,dm] where djs are non-negative integers, and generate a symbolic multivariate polynomial in the form of symbolic expression. The symbolic expression consists of monomials of the form: Fo example if D=[2,3] the output should be For this specific case I could nest two for loops and add the expressions. But I don't know what to do for Ds with arbitrary length. If I could

2021-09-09 03:09:51    分类:问答    python   numpy   sympy   polynomial-math   power-series

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

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[13]: 2 -2⋅√a⋅z + a + z Thus, the factorization fails if the identity sqrt(a) * sqrt(a) = a is applied

2021-09-08 09:17:29    分类:问答    python   math   sympy   polynomials   polynomial-math

Summing two polynomials

I'm looking for a built-in Matlab function that sums two polynomial. Example: p1(x) and p2(x) are represented in code standard Matlab vectors: p1 = [500 400 300 200 100 50]; p2 = [3 2 1 5]; How do I sum these two polynomials to get ps(x) with using built-in Matlab function(s); without writing an explicit m-file function?

2021-09-07 12:43:22    分类:问答    matlab   sum   polynomial-math   built-in

How can I use gsl to calculate polynomial regression data points?

(Disclaimer: I am terrible with math and am coming from JavaScript, so I apologize for any inaccuracies and will do my best to correct them.) The example on Rosetta Code shows how to calculate coefficients using gsl. Here is the code: polifitgsl.h: #ifndef _POLIFITGSL_H #define _POLIFITGSL_H #include <gsl/gsl_multifit.h> #include <stdbool.h> #include <math.h> bool polynomialfit(int obs, int degree, double *dx, double *dy, double *store); /* n, p */ #endif polifitgsl.cpp: #include "polifitgsl.h" bool polynomialfit(int obs, int degree, double *dx, double *dy, double *store) /* n, p */ { gsl

2021-09-05 15:01:07    分类:问答    c   polynomial-math   gsl

Evaluating a polynomial with Horner's Algorithm and calculating steps (Java)

I need help on my java code. What I'm trying to accomplish is to calculate the size of each step on a polynomial: double s = (b-a)/nsteps; The inputs for the polynomial to be created is degree, coefficient, start value of x, stopping value of x, and the number of steps. Whenever I try to run a test, my output is 0 for x and y and I'm not sure what I am missing on my code. Here is my run test on how its supposed to work, but my result for x and y is 0: Enter degree:2 Enter coefficient 2:1 Enter coefficient 1:0 Enter coefficient 0:0 f(x) = 1.0x^2 + .0x^1 + 0.0 Enter initial x:0 Enter final x:10

2021-09-04 16:26:48    分类:问答    java   evaluation   polynomial-math

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

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 create a function Polynomial, which would take an array of coefficients, and filter it so that if for

2021-09-04 07:13:29    分类:问答    java   math   numbers   polynomials   polynomial-math

Java中多项式x^16 + x^12 + x^5 + 1计算CCITT标准CRC(Calculation of CCITT standard CRC with polynomial x^16 + x^12 + x^5 + 1 in Java)

问题 我需要在 Java 中使用多项式 x^16 + x^12 + x^5 + 1 (0x1081) 计算 CCITT 标准 CRC 的帮助。 我在互联网上尝试了许多示例,但每个示例都返回示例中的值以外的其他值。 例如,对于这个数组 [0xFC] [05] [11],结果需要是 [27] [56]。 使用此代码: public static void main(String[] args) { byte[] array = new byte[3]; array[0] = (byte) 0xFC; array[1] = (byte) 0x05; array[2] = (byte) 0x11; // array[3] = (byte) 0x00; // array[4] = (byte) 0x00; System.out.println(Integer.toHexString(crc16(array))); } private static final int POLYNOMIAL = 0x1081; private static final int PRESET_VALUE = 0xFFFF; public static int crc16(byte[] data) { int current_crc_value = PRESET_VALUE; for (int i = 0; i <

2021-09-01 02:13:46    分类:技术分享    java   calculator   polynomial-math   crc16