我希望能够订购Polynomes,首先按长度(度)进行比较,然后按系数进行比较.Polynomes是双打的列表[1,2,3] = 3x²+2x+1.但是如果最后一个元素为零,那么它应该被删除,所以我写了一个函数来做那个调用realPolynom.realPolynom [1,2,3,0] = [1,2,3]
现在,我的Ord实例看起来像:
instance Ord Polynom where
compare a b = compare ((realLength a), reverse (pol2list (realPolynom a))) ((realLength b), reverse (pol2list (realPolynom b)))
Run Code Online (Sandbox Code Playgroud)
realLength 只是最后没有零的多项式的长度.
pLength :: Polynom -> Int
pLength (Polynom(a)) = length a
realLength :: Polynom -> Int
realLength a = pLength(realPolynom(a))
Run Code Online (Sandbox Code Playgroud)
pol2list 是 Polynom p = p
pol2list :: Polynom -> [Double]
pol2list (Polynom p) = p
Run Code Online (Sandbox Code Playgroud)
问题是:
[0,2,0] < [0,2,3] 是的,这很好
[0,2,0] < [0,2] 虚假,也很好
[0,2,0] …
我收到错误:
类型错误: x 的预期一维向量
关于这一行:
系数 = np.polyfit(x1, y1, 1)
coefficients = np.polyfit(x1, y1, 1)
polynomial = np.poly1d(coefficients)
ys = polynomial(x1)
Run Code Online (Sandbox Code Playgroud)
x1 和 y1 是;
x = frame_query("select * from table",db)
y = frame_query("select * from table",db)
x1 = np.array(x)
y1 = np.array(y)
Run Code Online (Sandbox Code Playgroud)
由736行数据组成。我想将一行回归到另一行。有人可以帮忙吗?
谢谢。
我正在尝试使用 math.numerics 找到三次多项式的根ax^3+bx^2+cx+d=0。这个包很棒,但我很难开始使用它。请有人解释一下如何找到根,以及如何从Github运行示例包的简单解释?
我添加了对包的引用
using MathNet.Numerics;
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的:
var roots = FindRoots.Cubic(d, c, b, a);
double root1=roots.item1;
double root2=roots.item2;
double root3=roots.item3;
Run Code Online (Sandbox Code Playgroud)
但我收到错误"The type 'Complex' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Numerics'"。使用 System.Numerics 添加会出现错误,并且不能解决问题。
请问有什么建议吗?
我正在尝试绘制多项式的曲线,但是有一些点使得曲线在某些地方看起来非常直.如何在多项式上测试更多点,这样我就能得到更好的曲线?图片说明了下面的问题,代码试图解决问题.
library('MonoPoly') # monotonic polynomials
dataT = read.csv("data.csv", header=TRUE, sep=",")
x <- dataT[,'x']
y <- dataT[,'y']
fitResult <- monpol(y~x, degree=3,algorithm="Hawkins")
fitted <- fitted(fitResult) # not enough data points. Only 120
z = predict(fitResult, seq(1, 5, 0.01)) # attempt at making more data points
plot(1:5, 1:5, type = "n")# setting up coord system
points(x,y,col="red") # plotting data fitting to
lines(sort(x), sort(fitted),col="blue") #plotting fitted because z isn't working
points(x,z,col="blue") # plotting curve
Run Code Online (Sandbox Code Playgroud) 我正在使用在 ASUS x75 上运行的 GP 和最小多项式,如下所示:
(19:25) gp > elt=Mod(a*x^3+b*x^2+c*x+d,('x^5-1)/('x-1))
%122 = Mod(a*x^3 + b*x^2 + c*x + d, x^4 + x^3 + x^2 + x + 1)
(19:25) gp > (poly=minpoly(elt,x='x))
%123 = x^4 + (a + (b + (c - 4*d)))*x^3 + (a^2 + (-3*b + (2*c - 3*d))*a + (b^2 + (2*c - 3*d)*b + (c^2 - 3*d*c + 6*d^2)))*x^2 + (a^3 + (-2*b + (3*c - 2*d))*a^2 + (-2*b^2 + (c + 6*d)*b + (-2*c^2 - …Run Code Online (Sandbox Code Playgroud) 我在MATLAB中对符号多项式进行了部分分数分解,它给出了一个符号表达式,如下所示:
poly = -2i/(x - 1.0 - 1.7i) + 0.57i/(x - 1.0 + 1.1559i)
Run Code Online (Sandbox Code Playgroud)
如您所见,此符号表达式包含x变量和常量复数.如何从MATLAB中提取此表达式中的所有数值?不得丢失数字是真实的还是复杂的信息.
因此,对于给定的表达式poly,我将如何获得以下矩阵A:
A = [-2i, -1-1.7i; .57i, -1+1.1559i]
A =
0 - 2i -1 - 1.7i
0 + 0.57i -1 + 1.1559i
Run Code Online (Sandbox Code Playgroud)
还请注意,A应包含数字,而不是符号表达式poly.
我读了coeffs-function,但它要求输入是多项式.使用children-function我可以将符号表达式中的求和项除以符号表达式的向量,如下所示:
p = - 0.57735026918962576450914878050196i/(x - 1.0 - 1.7320508075688772935274463415059i) + 0.57735026918962576450914878050196i/(x - 1.0 + 1.7320508075688772935274463415059i);
terms = children(p)
terms =
[ -0.57735026918962576450914878050196i/(x - 1.0 - 1.7320508075688772935274463415059i), 0.57735026918962576450914878050196i/(x - 1.0 + 1.7320508075688772935274463415059i)]
Run Code Online (Sandbox Code Playgroud) 我有一个parametric polynomial regressionin R,我像这样适合我的数据:
poly_model <- lm(mydataframef$y ~ poly(mydataframe$x,degree=5))
Run Code Online (Sandbox Code Playgroud)
mydf显然包含y和x。然后我像这样绘制它
plot(mydataframe$x, mydataframe$y, xlab='regressor or predictor variable polynomial regression', ylab='outcome or label')
Run Code Online (Sandbox Code Playgroud)
然后我想添加拟合的多项式,所以我执行以下操作:
abline(poly_model)
Run Code Online (Sandbox Code Playgroud)
这给了我一个警告:
Warning message:
In abline(poly_model) :
only using the first two of 6 regression coefficients
当然,情节完全不正常,因为正如承诺的那样,它只使用前两个,即截距和斜率。当我只有一个预测变量时,为什么只使用前两个系数?所以,无论如何,情节应该是二维的?使困惑。谢谢。
我尝试找到多项式函数的根,并使用以下代码:
import sympy
from sympy import Poly, roots
g=sympy.var("x")
p = Poly(x**25-96*x**12-4*x**3+2, gen=g)
print(roots(p))
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不起作用。如果我使用像 x**2-1 这样更简单的多项式函数,它就可以工作
我正在写一个类来添加,减去和乘法多项式(现在进行1周!).无论如何,代码编译,但我看到输出中似乎是内存地址.
我无法弄清楚为什么会这样.
任何人都可以引导我朝着正确的方向前进吗?
在此先感谢您的光临!瑞安
代码:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Poly
{
private:
// int ord; // the order of the polynomial
// int coeff[100];
public:
int ord; // the order of the polynomial
int coeff[100];
int a, b, c;
Poly(); // constructor
Poly addition(Poly b); // adds 2 polynomials
Poly subtraction(Poly b); // subtracts 2 polynomials
Poly multiplication(Poly b); // multiplies 2 polynomials
int evaluate(int); // uses Horner's method to compute and return the …Run Code Online (Sandbox Code Playgroud)