Skip to content

Commit

Permalink
various fixes in interacts
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Jan 28, 2019
1 parent 5ea46ee commit 1ba117f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
24 changes: 10 additions & 14 deletions src/sage/interacts/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def distance(x1_y1, x2_y2):
# are adjacent and the side c is opposite to the angle
def angle(a, b, c):
a,b,c = map(float,[a,b,c])
return acos((b**2 + c**2 - a**2)/(2*b*c))
return acos(0.5 * (b**2 + c**2 - a**2) / (b * c))

# Returns the area of a triangle when an angle alpha
# and adjacent sides a and b are known
Expand Down Expand Up @@ -454,14 +454,10 @@ def area(alpha, a, b):
labels = a_label + b_label + c_label

show(unit_circle + triangle + triangle_points + labels, figsize=[5, 5], xmin=-1, xmax=1, ymin=-1, ymax=1)
angl_txt = r"$\angle A = {%s}^{\circ},$ $\angle B = {%s}^{\circ},$ $\angle C = {%s}^{\circ}$" % (
math.degrees(ak[0]),
math.degrees(ak[1]),
math.degrees(ak[2])
)
html(angl_txt)
html(r"$AB = %s,$ $BC = %s,$ $CA = %s$"%(al[2], al[0], al[1]))
html(r"Area of triangle $ABC = %s$"%A)
html(r"$\angle A = {%.3f}^{\circ},$ $\angle B = {%.3f}^{\circ},$ $\angle C = {%.3f}^{\circ}$"
% (math.degrees(ak[0]), math.degrees(ak[1]), math.degrees(ak[2])))
html(r"$AB = %.6f$, $BC = %.6f$, $CA = %.6f$" % (al[2], al[0], al[1]))
html(r"Area of triangle $ABC = %.6f$" % A)

@library_interact
def unit_circle(
Expand Down Expand Up @@ -1595,12 +1591,12 @@ def polar_prime_spiral(
t = SR.var('t')
a=1.0
b=0.0
if n > (floor(sqrt(n)))**2 and n <= (floor(sqrt(n)))**2 + floor(sqrt(n)):
c = -((floor(sqrt(n)))**2 - n)
c2= -((floor(sqrt(n)))**2 + floor(sqrt(n)) - n)
S = int(sqrt(n))
if n <= S * (S + 1):
c = n - S**2
else:
c = -((ceil(sqrt(n)))**2 - n)
c2= -((floor(sqrt(n)))**2 + floor(sqrt(n)) - n)
c = n - (S + 1)**2
c2 = n - S * (S + 1)
html('Pink Curve: $n^2 + %s$' % c)
html('Green Curve: $n^2 + n + %s$' % c2)
m = SR.var('m')
Expand Down
20 changes: 5 additions & 15 deletions src/sage/interacts/test_jupyter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Test all interacts from the Sage interact library::
dpi: IntSlider(value=100, description=u'dpi', max=300, min=10, step=10)
<h2>Polar Prime Spiral</h2> <div style="white-space: normal;"> For more information about the factors in the spiral, visit <a href="http://www.dcs.gla.ac.uk/~jhw/spirals/index.html" target="_blank"> Number Spirals by John Williamson</a>.</div>
<script type="math/tex">n = 89</script>
Pink Curve: <script type="math/tex">n^2 + 8.0</script>
Green Curve: <script type="math/tex">n^2 + n + -1.0</script>
Pink Curve: <script type="math/tex">n^2 + 8</script>
Green Curve: <script type="math/tex">n^2 + n + -1</script>

sage: test(interacts.calculus.taylor_polynomial)
Interactive function <function taylor_polynomial at ...> with 3 widgets
Expand Down Expand Up @@ -103,16 +103,6 @@ Test all interacts from the Sage interact library::
<script type="math/tex">Ax^2 + Bx + C = 0</script>
<script type="math/tex">x = \frac{-B\pm\sqrt{B^2-4AC}}{2A} = \frac{-1\pm\sqrt{1^2-4*1*-2}}{2*1} = \frac{-1\pm\sqrt{\color{Green}{9}}}{2} = \begin{cases}1\\-2\end{cases}</script>

sage: test(interacts.calculus.trigonometric_properties_triangle)
Interactive function <function trigonometric_properties_triangle at ...> with 3 widgets
a0: IntSlider(value=30, description=u'A', max=360)
a1: IntSlider(value=180, description=u'B', max=360)
a2: IntSlider(value=300, description=u'C', max=360)
<h2>Trigonometric Properties of a Triangle</h2>
<script type="math/tex">\angle A = {60.0}^{\circ},</script> <script type="math/tex">\angle B = {45.0}^{\circ},</script> <script type="math/tex">\angle C = {75.0}^{\circ}</script>
<script type="math/tex">AB = 1.93185165258,</script> <script type="math/tex">BC = 1.73205080757,</script> <script type="math/tex">CA = 1.41421356237</script>
Area of triangle <script type="math/tex">ABC = 1.18301270189</script>

sage: test(interacts.calculus.secant_method)
Interactive function <function secant_method at ...> with 5 widgets
title: HTMLText(value=u'<h2>Secant method for numerical root finding</h2>')
Expand Down Expand Up @@ -270,9 +260,9 @@ Test all interacts from the Sage interact library::
a1: IntSlider(value=180, description=u'B', max=360)
a2: IntSlider(value=300, description=u'C', max=360)
<h2>Trigonometric Properties of a Triangle</h2>
<script type="math/tex">\angle A = {60.0}^{\circ},</script> <script type="math/tex">\angle B = {45.0}^{\circ},</script> <script type="math/tex">\angle C = {75.0}^{\circ}</script>
<script type="math/tex">AB = 1.93185165258,</script> <script type="math/tex">BC = 1.73205080757,</script> <script type="math/tex">CA = 1.41421356237</script>
Area of triangle <script type="math/tex">ABC = 1.18301270189</script>
<script type="math/tex">\angle A = {60.000}^{\circ},</script> <script type="math/tex">\angle B = {45.000}^{\circ},</script> <script type="math/tex">\angle C = {75.000}^{\circ}</script>
<script type="math/tex">AB = 1.931852</script>, <script type="math/tex">BC = 1.732051</script>, <script type="math/tex">CA = 1.414214</script>
Area of triangle <script type="math/tex">ABC = 1.183013</script>

sage: test(interacts.geometry.special_points)
Interactive function <function special_points at ...> with 10 widgets
Expand Down

0 comments on commit 1ba117f

Please sign in to comment.