python - 将数组转换为多项式
问题描述
我正在做一个数值分析,我得到了一个矩阵作为我的结果。因此,我想使用matrix
or 数组来快速创建多项式。
import matplotlib.pyplot as plt
import matplotlib.collections
import numpy as np
x1 = -2
x2 = -2 + (8 / 3)
x3 = -2 + (16 / 3)
x4 = -2 + (24 / 3)
A = np.array(
[
[1, x1, x1 ** 2, x1 ** 3],
[1, x2, x2 ** 2, x2 ** 3],
[1, x3, x3 ** 2, x3 ** 3],
[1, x4, x4 ** 2, x4 ** 3],
]
)
R1 = np.array([[1], [0], [0], [0]])
N1 = np.linalg.solve(A, R1)
# The N1..N4 are my coefficients for my polynomium of third order.
# below I try to transform the N1 into a polynomium N1p`
N1p = np.array(N1.transpose()).tolist()
P1 = np.poly(N1p)
它给了我一个尺寸错误。有没有人可以帮助我?
解决方案
这是您的预期输出吗?
N1p = N1.transpose().reshape(-1)
P1 = np.poly(N1p)
P1
array([ 1.00000000e+00, 3.41796875e-02, -3.67412567e-02, 2.04887241e-03,
2.08630809e-05])
P1.tolist()
[1.0,
0.0341796875,
-0.03674125671386719,
0.002048872411251068,
2.0863080862909555e-05]
推荐阅读
- r - 根据三个类别中的最高相似度匹配来自 2 个组的人
- python - ipopt 缺少 cyggcc_s-1.dll 和 cyggfortran-3.dll
- c++ - 在 C++ 中监控命名管道 (FIFO) 中的数据
- android - Kotlin Coroutines,饼图不旋转
- r - 如何根据 R 中的 url 拆分字符行
- arrays - 从c中的函数返回数组时,静态数组声明和指针数组声明有什么区别
- python - 如何检查通过Django中模型类的变量?
- go - 什么是rand的碰撞。阅读
- javascript - 如何修复“无法读取未定义的属性'get'”
- javascript - React/NextJS 错误:元素类型无效:应为字符串或类/函数,但得到:未定义