Skip to content

Commit

Permalink
Taylor expand equations
Browse files Browse the repository at this point in the history
  • Loading branch information
hersle committed Oct 8, 2024
1 parent 92dfd5f commit cb9343d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ function taylor_coeff(f, x, n; rationalize=true)
end
return c
end
function taylor_coeff(eq::Equation, args...; kwargs...)
return taylor_coeff(eq.lhs, args...; kwargs...) ~ taylor_coeff(eq.rhs, args...; kwargs...)
end

"""
taylor(f, x, [x0=0,] n; rationalize=true)
Expand Down Expand Up @@ -56,3 +59,6 @@ function taylor(f, x, x0, n; kwargs...)
# 3) substitute back x = x′ + x0
return substitute(s, x′ => x - x0)
end
function taylor(eq::Equation, args...; kwargs...)
return taylor(eq.lhs, args...; kwargs...) ~ taylor(eq.rhs, args...; kwargs...)
end
6 changes: 6 additions & 0 deletions test/taylor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ end

# around x ≠ 0
@test substitute(taylor((x), x, 1, 0:6), x => x + 1) - taylor((1+x), x, 0:6) == 0

# equations
eq = sin(2*x) ~ 2*sin(x)*cos(x)
eq = taylor(eq, x, 0:7)
eqs = [Symbolics.taylor_coeff(eq, x, n) for n in 0:7]
@test all(isequal(eq.lhs, eq.rhs) for eq in eqs)

0 comments on commit cb9343d

Please sign in to comment.