Mentions légales du service

Skip to content
Snippets Groups Projects

Truncate a polynomial expression up to a given order using SymPy in Julia

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by LEJAY Antoine
    Edited
    truncate_polynomial.jl 300 B
    using SymPy
    
    # Keep only terms of a given orders in a polynomial expression
    function truncate_upto(ex::Sym, x::Sym, order::Int)
        if ex.func.__name__ != "Add" 
    	error("The main expression should be an addition") 
        end
        return ex.func(ex.args[findall(y->degree(y,x)  order,ex.args)]...)
    end
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment