Skip to content

Instantly share code, notes, and snippets.

@Shekharrajak
Last active July 11, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shekharrajak/17fdcd2320f572fc9fc8674823137e20 to your computer and use it in GitHub Desktop.
Save Shekharrajak/17fdcd2320f572fc9fc8674823137e20 to your computer and use it in GitHub Desktop.
# examples how we can use factor to reduce number of imageset :
# current master branch
In [110]: solveset(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------------ eq(1)
Out[110]:
7π ⎫ ⎧ 11π ⎫ ⎧ 5π ⎫ ⎧ 3π ⎫ ⎧ 7π ⎫ ⎧ π
2nπ + ─── | n⎬ ∪ ⎨2nπ + ──── | n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ +| n
6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
In [123]: solveset((4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1).rewrite(exp))
Out[123]:
5π ⎫ ⎧ π ⎫ ⎧ 3π ⎫ ⎧ π ⎫ ⎧ 3π ⎫ ⎧ π
2nπ - ─── | n⎬ ∪ ⎨2nπ -| n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ +| n⎬ ∪ ⎨2nπ - ─── | n⎬ ∪ ⎨2nπ -| n
6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
# first factor the trig eq
In [112]: fact = factor_list(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------- eq(1) factors
In [113]: fact
Out[113]:
⎛ ⎡ ⎛ 2 ⎞⎤⎞
1, ⎣(2sin(x) + 1, 1), ⎝2sin (x) - 1, 1⎠⎦⎠
# see the factors exp form(factor them also to remove extra exp)
In [114]: factor((2*sin(x) + 1).rewrite(exp)) # -------eq(1), factor (1)
Out[114]:
2x x-x
- - - ⎠⋅
In [115]: factor((2*sin(x)**2 - 1).rewrite(exp)) # -------eq(1), factor (2)
Out[115]:
4x-2x
- + 1⎠⋅
──────────────────────
2
# both outer exp will not give any solution
In [116]: solveset(exp(-I*x)) # --------- outside bracket - factor (1)
Out[116]: ∅
In [117]: solveset(exp(-2*I*x)) # --------- outside bracket - factor (2)
Out[117]: ∅
# these both will contribute in soln
In [118]: solveset(I*exp(2*I*x) - exp(I*x) - I) # --------- inside bracket - factor (1)
Out[118]:
5π ⎫ ⎧ π
2nπ - ─── | n⎬ ∪ ⎨2nπ -| n
6 ⎭ ⎩ 6
In [122]: solveset(exp(4*I*x) + 1) # --------- inside bracket - factor (2)
Out[122]:
nπ π
⎨─── +| n
2 4
# now compare if we direclty solve the trig factor
# this looks same as above
In [120]: solveset(2*sin(x) + 1) # ---------current branch solves without factoring, so soln is similar - factor (1)
Out[120]:
7π ⎫ ⎧ 11π
2nπ + ─── | n⎬ ∪ ⎨2nπ + ──── | n
6 ⎭ ⎩ 6
# but this contains many imageset that is reduced above
In [121]: solveset(2*sin(x)**2 - 1) # ---------current branch solves without factoring, so soln is larger than Out[122] - factor (2)
Out[121]:
5π ⎫ ⎧ 3π ⎫ ⎧ 7π ⎫ ⎧ π
2nπ + ─── | n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ + ─── | n⎬ ∪ ⎨2nπ +| n
4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
# so overall we have (if we use factor correctly, less imagesets we get)
# so ans from factor(1) and factor(2) is here(which is simpler than current master) :
5π ⎫ ⎧ π
2nπ - ─── | n⎬ ∪ ⎨2nπ -| n⎬ ∪
6 ⎭ ⎩ 6
nπ π
⎨─── +| n
2 4
# =============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment