martes, 26 de junio de 2018

Some Regular Star Polygons

Regular Polygons and Star Polygons 

A  regular star polygon is a polygonal line whose vertices are vertices of a regular polygon. Their sides are line segments joining vertices of a regular polygon, skipping one or more of them, clockwise or counterclockwise.

The following are samples of star polygons made with logo programs in Python language.
The 3.7 Python program must be previously installed .

# 5-reg-star
from turtle import*
mode('logo')
for i in range(5):
    fd(100),lt(216)
Terminator

# 7-reg-star(1)
from turtle import*
mode('logo')
for i in range(7):
    fd(100),rt(102.9)
Terminator




# 7-reg-star(2)
from turtle import*
mode('logo')
for i in range(7):
    fd(100),rt(154.3)
Terminator

# 8-reg-star
from turtle import*
mode('logo')
for i in range(8):
    fd(100),rt(135)
Terminator

# 9-reg-star(1)
from turtle import*
mode('logo')
for i in range(9):
    fd(70),rt(80)
Terminator


# 9-reg-star(2)
from turtle import*
mode('logo')
for i in range(9):
    fd(70),rt(160)
Terminator


# 10-reg-star
from turtle import*
mode('logo')
for i in range(10):
    fd(100),rt(108)
Terminator




# 12-reg-star
from turtle import*
mode('logo')
for i in range(12):
    fd(100),rt(150)
Terminator






lunes, 25 de junio de 2018

Some Regular Polygons

Drawing Regular Polygons

In what follows some regular polygons are drawn using logo programs in Python 3.7 language. This program must be previously installed.

#Equilateral triangle
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(3):
    fd(100),lt(120)


 Terminator





#Square
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(4):
    fd(100), lt(90)
Terminator






# Regular Pentagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(5):
    fd(100), lt(72)
Terminator


#Regular Hexagon.
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(6):
    fd(50),lt(60)
Terminator


#Regular Octagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(8):
    fd(50),lt(45)
Terminator

#Regular Nonagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(10):
    fd(50),lt(40)
Terminator



#Regular Decagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(10):
    fd(50),lt(36)
Terminator


#Regular Dodecagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(12):
    fd(50),lt(30)
Terminator

miércoles, 6 de junio de 2018

Integer Pythagorean Triples


Pythagorean Triples

With positive integers

The following is a Python 3.7 program. It must be previously installed.

print('Type a positive integer')
integer=input()
integer=int(integer)
for a in range(1,integer):
    for b in range(1, integer):
        for c in range(1, integer):
            if a**2+b**2==c**2:
                if a <b<c                   
                    print([a,b,c])


Example (1): For numbers not greater than 8

Type a positive integer
8
[3, 4, 5]

Example (2): For numbers not grater than 30

Type a positive integer
30
[3, 4, 5]
[5, 12, 13]
[6, 8, 10]
[7, 24, 25]
[8, 15, 17]
[9, 12, 15]
[10, 24, 26]
[12, 16, 20]
[15, 20, 25]
[20, 21, 29]

Divisors of a positive integer

All the divisors...

of a positive integer

The following is a 3.7 Python program. It has to be previously installed

#Divisors of a positive integer
x=int(input('Type a positive integer  '))
for j in range(1,x+1):
    if x//j==x/j:
        print(j,end=',')
        j=j+1

Example (1): For 3780

Type a positive integer  3780
1,2,3,4,5,6,7,9,10,12,14,15,18,20,21,27,28,30,35,36,42,45,54,60,63,70,84,90,105,108,126,135,140,180,189,210,252,270,315,378,420,540,630,756,945,1260,1890,3780,

Example (2): For 3781

Type a positive integer  3781
1,19,199,3781,

Example 3: For 3701

Type a positive integer  3701
1,3701,

martes, 5 de junio de 2018

Fractions and decimals

Fractions and decimal representation

The following is a Python 3.7. It must be previously installed,

#Fractions and decimal representation
print('Type integer part and no periodical part, without decimal point')
a=int(input())
print('Type the same figures and add the figures of the first period')
b=int(input())
numerator=b-a
print('Type 9 a number of times equal to number of figures in the period')
print('and type 0 a number of times equal to number of figures')
print('before the periodic part, and to the right of decimal point')
denominator=int(input())
print('The generator fraction is',numerator,'/',denominator)

Example (1): Given 25.36124242424...

Type integer part and no periodical part, without decimal point
25361
Type the same figures and add the figures of the first period
2536124
Type 9 a number of times equal to number of figures in the period
and type 0 a number of times equal to number of figures
before the periodic part, and to the right of decimal point
99000
The generator fraction is 2510763 / 99000
or, simplyfying, 836921/33000

Example(2): Given 4.23232323...

Type integer part and no periodical part, without decimal point
4
Type the same figures and add the figures of the first period
423
Type 9 a number of times equal to number of figures in the period
and type 0 a number of times equal to number of figures
before the periodic part, and to the right of decimal point
99
The generator fraction is 419 / 99

lunes, 4 de junio de 2018

Three points for a plane

Plane determined by...

three points


The following is a Python 3.7 program. It must be previously installed.

#Equation of a plane, (Ax + By + Cz + D = 0) known three of its points
#(a, b, c), (d, e, f,), (g, h, t)

print('type, one at a time, a, b, c, d, e, f, g, h, t')

a = float(input())
b = float(input())
c = float(input())
d = float(input())
e = float(input())
f = float(input())
g = float(input())
h = float(input())
t = float(input())

A=b*f+c*h+e*t-f*h-c*e-b*t
B=-a*f-c*g-d*t+f*g+c*d+a*t
C=a*e+b*g+d*h-b*d-e*g-a*h
D=a*e*t+b*f*g+c*d*h-c*e*g-b*d*t-a*f*h
    
print('lthe equation of the plane is')
print(A,'x+',B,'y+',C,'z+',D,'=0')


Example (1). For (-3, 1, -2), (5, -4, -1), (4, 5, 2)

-3
1
-2
5
-4
-1
4
5
2
the equation of the plane is
-24.0 x+ -25.0 y+ 67.0 z+ -87.0 =0

This equation could be rewritten as 24x + 25y - 67z -87 = 0.

Example(2): For (2, 3, 1), (4, -2, 5), (6, 1, 6)

2
3
1
4
-2
5
6
1
6
the equation of the plane is
-17.0 x+ 6.0 y+ 16.0 z+ 0.0 =0
This equation could be rewritten as 17x - 6y -16z = 0  (The point (0, 0, 0) is in the plane)

Example (3):For (1, -2, 5), (13, 7, 11), 37, 25, 23)

1
-2
5
13
7
11
37
25
23
1
-2
5
13
7
11
37
25
23
the equation of the plane is
0.0 x+ 0.0 y+ 0.0 z+ 0.0 =0

That is, 0x + 0y + 0z + 0 = 0

In this case, the three given points are collinear 

Circle, known three points

Center and radius of a circle...

given three points in a plane

What follows is a Python.3.7 program. It must be installed to get results.

#Given three points (a,b),(c,d),(e,f) in a plane

print ('type, one at a time, a, b, c, d, e, f')

a=float(input())
b=float(input())
c=float(input())
d=float(input())
e=float(input())
f=float(input())

if a*d+b*e+c*f-e*d-b*c-a*f==0:
    print('collinear points')
    quit()
else:
    a1=(2*(a-e))
    a2=(2*(e-c))
    b1=(2*(b-f))
    b2=(2*(f-d))
    c1=(-a**2-b**2+e**2+f**2)
    c2=(c**2+d**2-e**2-f**2)
    k=(a2*b1-a1*b2)
    m=(c1*b2-c2*b1)*(k**-1)
    g=(a1*c2-a2*c1)*(k**-1)
    t=m-a
    u=g-b
    h1=t**2+u**2
    h2=h1**.5

    print('Center coordinates are: (',m,',',g,')')
    print('Radius ',h2)

Example (1) For (3,-4), (1, 5), (2,0)
3
-4
1
5
2
0
Center coordinates are: ( 96.5 , 21.5 )
Radius,  96.91491113342673

Example(2) For (2, 3), (1, 5), (4, -1)
2
3
1
5
4
-1
collinear points

The program must be closed.



sábado, 2 de junio de 2018

Quadratic equations

Solving quadratic equations (automated)

What follows is a Python.3.7 program. It must be previously installed.

#Quadratic equation
print('For the equation ax**2 + bx + c= 0')
print('type, one at a time, a, b, c')

a=float(input())
b=float(input())
c=float(input())

d =b**2-4*a*c

print('discriminant =',b**2-4*a*c)

e1=(-b+(d**.5))*(2*a)**-1
e2=(-b-(d**.5))*(2*a)**-1
f1=-b*(2*a)**-1
f2=((-d)**.5)*(2*a)**-1

if(d>=0):
    print('real solutions')
    print('x1 =',e1)
    print('x2 =',e2)

else:
    print('complex solutions')
    print('x1 =',f1,'+',f2,'i')
    print('x2 =',f1,'-',f2,'i')

Example 1. Given x**2 - x - 20 = 0
1
-1
-20
discriminant = 81.0
real solutions
x1 = 5.0
x2 = -4.0

Example 2. Given 5x**2 - 2x + 7 = 0
5
-2
7
discriminant = -136.0
complex solutions
x1 = 0.2 + 1.1661903789690602 i
x2 = 0.2 - 1.1661903789690602 i

viernes, 1 de junio de 2018

Equation of any line in a plane

Equation of a line in a plane (automated)


What follows is a Python.3.7 program. It must be installed to get results

#Equation of any line in a plane in the form Ax + By + C =0
#given two points, (a,b), (c,d)

print('type, one at a time,  a, b, c, d')
a=float(input())
b=float(input())
c=float(input())
d=float(input())
print('the equation is')
print((b-d),'x+',(c-a),'y+',(a*d-b*c),'=0')

Example(1): for (3, 4), (5, -2)
3
4
5
-2
the equation is 6.0 x+ 2.0 y+ -26.0 = 0
 That is, 6x + 2y -26 = 0

Example (2): for (4, 5), (4, -2)
4
5
4
-2
the equation is 7.0 x+ 0.0 y+ -28.0 =0
That is, 7x - 28 = 0

Example (3): for (6, 7), (-4, 7)
6
7
-4
7
the equation is 0.0 x+ -10.0 y+ 70.0 =0
That is, -10y + 70 = 0

GCF and LCM


GCF and LCM, automated


What follows is a working Python.3.7 program.  It must be installed to get results.

#gcf and lcm
def gcf(a,b):
    if a%b==0:
        return b
    else:
        return gcf(b,a%b)

def lcm(a,b):
    m = int()
    m = a*b//gcf(a,b)
    return m
print("Type gcf(a,b), for a,b positive integers")
print("Type lcm(a,b), for a,b positive integers")


Example:

 gcf(358, 456)
2
 lcm(358,456)
81624
 
Note: a % b means the residue for division between a and b
Example: 7 % 4 =3.