Showing posts with label squares. Show all posts
Showing posts with label squares. Show all posts

Sunday, August 4, 2024

TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module

 TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module


Introduction


Here are four scripts to draw shapes:


RECT8: rectangles and squares centered at (0, 0)

ELLIPSE8: ellipses and circles centered at (0, 0)

POLYGON8: polygons given the vertex points and number of vertices

INVFUNC8: draws a function f(x) and it’s inverse f^-1(x). Define the function is defined in the f(x) subroutine in the program.


The plot window is sized in sync with the TI-84’s screen size (320 pixels x 220 pixels) so that squares look like squares and circles look like circles. The window parameters are set as such:

Xmin = -16, Xmax = 16

Ymin = -10.5, Ymax = 10.5



TI-84 PLUS CE Python Script: RECT8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("horiz. length? "))

b=eval(input("vert. length? "))


# plot routine

plt.cls()

plt.title("Rectangle")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


# color: blue

plt.color(0,0,192)


# pen size

plt.pen("medium","solid")


plt.line(-a/2,b/2,a/2,b/2,"")

plt.line(-a/2,-b/2,a/2,-b/2,"")

plt.line(-a/2,-b/2,-a/2,b/2,"")

plt.line(a/2,-b/2,a/2,b/2,"")


plt.show_plot()


TI-84 PLUS CE Python Script: ELLIPSE8.py





import ti_plotlib as plt

from math import *


# draw an ellipse using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("x axis? "))

b=eval(input("y axis? "))


# plot routine

plt.cls()

plt.title("Ellipse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.pen("medium","solid")

plt.grid(1,1,"dot")


# color: green

plt.color(0,192,0)


for i in range(128):

  x=a*cos(i*pi/64)

  y=b*sin(i*pi/64)

  plt.plot(x,y,"o")


plt.show_plot()



TI-84 PLUS CE Python Script: POLYGON8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")


n=int(input("# of vertices? "))

a=eval(input("x1? "))

b=eval(input("y1? "))


x=[a]

y=[b]


for i in range(n-1):

  print("vertex ",i+2)

  c=eval(input("x? "))

  d=eval(input("y? "))

  x.append(c)

  y.append(d)

x.append(a)

y.append(b)



# plot routine

plt.cls()

plt.title("Polygon")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")

plt.color(75,0,130)

plt.pen("medium","solid")


for i in range(n):

  x0=x[i]

  y0=y[i]

  x1=x[i+1]

  y1=y[i+1]

  plt.line(x0,y0,x1,y1,"")


plt.show_plot()



TI-84 PLUS CE Python Script: INVFUNC8.py





Define f(x) in the def f(x) function routine. The math module is imported.



import ti_plotlib as plt

from math import *


# f(x) and f**-1(x)

# define f(x)

def f(x):

  return x**2+6


# plot routine

plt.cls()

plt.title("f(x) and its inverse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


plt.pen("medium","solid")


for i in range(320):

  x=-16+i*32/320

  y=f(x)

  plt.color(0,0,192)

  plt.plot(x,y,"o")

  plt.color(255,165,0)

  plt.plot(y,x,"o")



plt.show_plot()



Download the four scripts here: https://drive.google.com/file/d/1ELL6mEzMXrIJlOSSFocOZGJTza-kBZoU/view?usp=sharing



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Monday, July 23, 2018

Algebra: Multiplying a * b Trick (Using the Difference between a and b)


Algebra:  Multiplying a * b Trick (Using the Difference between a and b)

Can we find a formula to find products where two values are an equal-distant apart

The Values of a and b Differ by 2

Let a and b be real numbers which differ by 2, that is b – a = 2.  Here I am assuming that b > a. 

Let n be the midpoint between a and b.  That is:

n = b – 1 and
n = a + 1

Therefore:

b = n + 1
a = n - 1

Then:

a * b
= (n - 1) * (n + 1)
= n^2 - n + n – 1
= n^2 - 1

Example:  51 * 49

Notice that:

51 – 49 = 2, and
51 - 1 = 50
49 + 1 = 50

Hence:

51 * 49 = 50^2 – 1 = 2499

Can we expand this included products of a * b, where the difference is b – a = 2 * w

The Values of a and b Differ by 2*w

Let’s look at a more general case. 

Let b – a = 2*w

Then:

b = n + w and a = n – w

Then:

a * b
= (n – w) * (n + w)
= n^2 – n*w + n*w – w^2
= n^2 – w^2

Example:  37 * 43.

43 – 37 = 6
w = 6/2 = 3
Then:
n = 43 – 3 = 37 + 3 = 40

Then:

37 * 43 = 40^2 – 3^2 = 1600 – 9 = 1591


Try another example:  57 * 49

57 – 49 = 8
8 / 2 = 4
57 – 4 = 53, 49 + 4 = 53

Then:

57 * 49 = 53^2 – 4^2 = 2809 – 16 = 2793


In summary for a * b with b > a.

Let w = (b – a)/2 and n = a + w or n = b – w

Then a * b = n^2 – w^2

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Saturday, January 5, 2013

Growing Squares and Circles inside Squares

Happy New Year everyone! I am blogging from Stories Books and Cafè in Los Angeles. Today's blog is about geometry mixed a little calculus. Let's have fun!

Growing a Square inside a Square

Imagine a blue square with length x. Then from the center of the blue square, a pink square grows at a constant rate r. How long will it take for the pink square to grow as big as the blue square?

Let a = the length of pink's square side. If A represents the area of a square, then let:

Ab = area of the blue square = x² and
Ap = area of the pink square = a².

Note Ap is also a function of time, t, as Ap is changing.

The growth of the pink square can be described as:

dAp/dt = r with the initial condition Ap(0) = 0. Here I assume that the pink square starts out so small it's initial area is negligible.

Then:

∫ dAp/dt dt = ∫ r dt
Ap(t) = r * t + C, for constant C.

Considering the initial condition Ap(0) = 0, implies that C = 0, and Ap(t) = r * t.

So how long does it take for the pink square to grow as big as the blue square? Simply, this happens when the areas of both blue and pink squares equal.

Ab = Ap
x² = r * t
⇒ t = x²/r

For example, if the length of the blue square is x = 5 inches and the rate of the pink square grows at r = 0.5 in/sec, then it takes 5²/0.5 = 50 seconds for the pink square to grow as big as the pink square.

Two Squares Growing

Now let's consider two squares that start out as dots (with virtually no initial area of their own). Start with our blue square with length x and area x^2.

Then place one square, let it be purple and label it A with its center located at (x/4, x/2). Place another square, let it be pink and label it B with its center located at (3x/4, x/2).

Assume the following:

1. The growth of both the purple and pink square is constant, r.

2. The purple and pink squares stop growing when they touch each other.

3. The growth of both squares start simultaneously.

Let:
S = Area of the blue square = x²
A = Area of the purple square
B = Area of the pink square

Both A and B are functions of time, t since they change. Then:

dA/dt = r
∫ dA/dt dt = ∫ r dt
A = r * t + C

Considering the initial condition A(0) = 0, A = r * t.

Likewise, B = r * t.

When do the purple and pink squares meet? Inferring from the picture above, both squares meet when the length of each square reaches the length x/2. Since both squares grow at the same time, we can find out the time for each square by considering only one of the two squares. Without loss of generality, consider the purple square.

The maximum area of A is x²/4. Since A = r * t,

x²/4 = r * t
⇒ t = x²/(4*r)

How big will the two squares get? Considering the maximum size of the purple (and pink) square is x²/4, the largest the two squares will grow (without intersection) is:

x²/4 + x²/4 = x²/2

Growth of a Circle inside of a Square at a Constant Rate

Now consider a circle with radius r with its center located at the center of a square (x/2, x/2). Consider the growth of the circle constant, at rate α. The circle starts as a dot with virtually no area.

How long will it take until the circle grows as big as it can inside the square?

The circle will touch the square when its radius extends from the center of the square to one of its edges. But where?

Consider the measure of the radius as a line of coming from the center of the square and growing in a direction parallel to any on of its sides ("up", "down", "left", or "right"). (Hopefully this makes sense). For the moment, allow the circle to grow only when it's entire shape lies inside the square. Then the circle gets to its largest shape when r = x/2.

When will that happen?

Let A be the area of the circle, so A = Ï€ * r² and dA/dt = α.

With the initial condition A(0) = 0, A = α * t.

With r = x/2,

α * t = (x/2)² * Ï€
α * t = (x² * Ï€)/4
⇒ t = (x² * Ï€)/(4 * α)

How big is the largest circle? At the largest radius, A = (x² * Ï€)/4

The area of the square is x². Clearly, the area of the square is larger than the circle. Taking a ratio of the circle's area to the square's area:

((x² * Ï€)/4) / x² = Ï€ /4 ≈ 0.78540

The largest circle that can be completely contained inside the square has an area that is about 78.5% of the square's area. Cool huh?

What if the Circle is allowed to grow beyond the Square's Borders?

At what point does the circle completely encompass the square? In other words, at what point does the circle start containing the square?

This happens with the square's corners, and only its corners touches the circle. Let's determine the area of the circle at this point.

Consider the point P in the above diagram. P is also on one of the square's corners. Since the center of the circle and the center of the square are at the same location, the length from point P to the center is r.

Then by the Pythagorean Theorem:

r^2 = (x/2)^2 + (x/2)^2
⇒ r = x/√2

Then the circle's area is A = x^2 * π * 1/2 and the time it takes for the circle to get that large is t = (x^2 * π)/(2 * α).

At this point the area of the circle is π/2, or about 1.57080 times the area of the square.



By the way, the chili was spicy, and good. Thanks and stay safe! Eddie

This blog is property of Edward Shore. 2013


Python – Earth’s Radius and Gravity in US Units

Python – Earth’s Radius and Gravity in US Units Introduction The following script, gravus2.py, estimates the Earth’s gravity i...