Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Extract linear/quadratic/nonlinear terms from nonlinear expressions #2275

@ZedongPeng

Description

@ZedongPeng

Summary

I want to extract linear/quadratic/nonlinear terms from nonlinear expressions.

Description

I first tried expressions.args and check the polynomial_degree() of each subexpressions. However, if the subexpression is a constant. An error will be reported since int and float have no polynomial_degree().

Then I tried first transforming expressions into repn and then obtaining the linear/quadratic/nonlinear terms. I got stuck in the second step. The nonlinear_expr is stored in the repn, but linear_expr and quadratic_expr are not stored.

I know that linear_coefs, linear_vars, quadratic_coefs and quadratic_vars are provided. linear_expr and quadratic_expr can be obtained by SUMPRODUCT.

Is there an existing function to do this? I think to_expression might be the best candidate. Can we add some args, like linear_only, quadratic_only for this function?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions