使用python在一组二次方程式中查找系数时出现的问题“ ImmutableDenseNDimArray”对象没有属性“ coeff”

问题描述

问题:“ ImmutableDenseNDimArray”对象没有属性“ coeff” 描述: 第一步:简单地用一组不同的值(x0,x1,x2,xd)和variable2的二次方程式 步骤2:提取多个二次方程式的系数 第三步:找到二次方程的根

单独求解二次方程很简单,但是使用循环为多个二次方程生成根变得越来越困难,并且由于“ ImmutableDenseNDimArray”对象没有属性“ coeff”而面临错误。 我是python的初学者,可以帮助我摆脱这个错误。 期望值:如果以下解决方案不正确,我们将如何使用for循环找到多个二次方程的系数。

import math
import sympy as sym

x_input = np.zeros(12,100)
variable2 = 10

#The values of x0,x1,x3 and xd are dynamically generated values in my code,for simplication,values are written manually
x0 = [1,2,3,4,5,6,7,8,9,10,11,12] 
x1 = [1,12]
x2 = [1,12]
xd = [1,12]

for i in range(12):
    x_input = sym.symbols('x_input')
    #Quadratic Equation
    quadratic_exp = ((x2[i] - xd[i]) * (abs(x_input) - x0[i])**2) + (2*x1[i])*(xd[i] * abs(x_input)) - 2*x1[i])*variable2
    # Simplified Quadratic Equation
    quadratic_exp_smpfy = sym.simplify(quadratic_exp)
    # Finding Coefficients of polynomial 2nd order equation
    x_input_A = quadratic_exp_smpfy.coeff(x_input,2)
    x_input_B = quadratic_exp_smpfy.coeff(x_input,1)
    x_input_C = quadratic_exp_smpfy.coeff(x_input,0)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)