Developers Heaven Forum

Desktop Programming => HLA => Topic started by: David on January 27, 2016, 04:56:58 AM

Title: High School type Math questions solved using Python 3.x ...
Post by: David on January 27, 2016, 04:56:58 AM
Update: Update: please see this next link:

http://developers-heaven.net/forum/index.php/topic,2636.0.html


FREE homework help NOW available ...

You can contact me via:
http://sites.google.com/site/andeveryeyeshallseehim/home/he-comes
http://developers-heaven.net/forum/index.php/topic,2587.0.html


This first question was not solved completely by any? student ...

It was the last question on an Ontario grade 10 term test (in January 2016).

Here is the problem:

A curve is described by the quadratic relation:

f(x) = a*x*x + b*x + c

If f(0) = 4 and f(24) = 0 and the max value ever reached by f(x), for all x, is 14,
then find value(s) of x where f(x) = 10


Note!

The students were expected to be familiar with the following expressions (and concepts):

(1)  f(x) = a*x*x + b*x + c 
      and  that if f(x) = 0, then the two 'roots' are:  ( -b + sqrt(b*b - 4*a*c) ) / (2*a)  AND  ( -b - sqrt(b*b - 4*a*c) ) / (2*a)
      and that (both) the roots are real if (b*b - 4*a*c) > 0, i.e. the graph 'cuts' the x-axis,
      and that there is just one (real) root if (b*b - 4*a*c) = 0, i.e. the graph 'just touches' the x-axis,
      else, both (distinct) roots are 'imaginary', i.e. the graph does NOT touch or cut the x-axis.

(2)  f(x) = a*(x-r1)*(x-r2)

(3) f(x) = a*(x-h)*(x-h) + k

(4) An extreme value for f(x), i.e. a max value if 'a' is negative, a min if 'a' is positive, occurs when x = -b/(2*a) ... wrt to (1) above.


OK ... below is a solution coded in Python 3:


Code: [Select]
# find_abcx_ver1.py #  # 2016-01-26 #

# wrt f(x) = a*x*x + b*x + c

# (1) Since when   x = 0, f(0) = 4 implies c = 4
# AND THUS    f(x) = a*x*x + b*x + 4

# (2) Since when   x = 24, f(24) = 0 implies 0 = 24*24*a + 24*b + 4
#     then divide all by 24 ...              0 = 24*a + b + 1/6
# i.e.                                       b = -(24*a + 1/6)
# i.e.  f(x) = a*x*x - (24*a + 1/6)*x + 4
# thus     b = -(24*a + 1/6)
# and      c = 4
# wrt the form:  f(x) = a*x*x + b*x + c

# (3) Now to find a = ? in f(x) = a*x*x - (24*a + 1/6)*x + 4

# SINCE the max value of 14 occurs when ...
#          x = (24*a + 1/6)/(2*a)
# thus:   14 = (24*a + 1/6)^2/(4*a) - (24*a + 1/6)^2/(2*a) + 4
# i.e.    10 = (24*a + 1/6)^2/(4*a) - (24*a + 1/6)^2/(2*a)
#       40*a = - (24*a + 1/6)^2
#       40*a = - (24*24*a*a + 8*a + 1/36)
#          0 = (24*24*a*a + 48*a + 1/36)   
# THUS          a*a + (1/12)*a + 1/((6*24)*(6*24)) = 0
# i.e.          a*a + (1/12)*a + 1/(12^4) = 0);

from math import sqrt

#   roots = ( -b +- sqrt(b*b - 4*a*c) ) / (2*a)

# now define Python function to calculate and return both roots
def roots( a, b, c ):
    return (-b + sqrt(b*b - 4*a*c))/(2*a), (-b - sqrt(b*b - 4*a*c))/(2*a)

a1, a2 = roots( 1, 1/12, 1/12**4 )

print( "In f(x) = a*x*x + b*x + c" )
print( "a takes TWO value, b = -24*a -1/6 and c = 4" )
print( "a1 =", a1, "and a2 =", a2 )

# a Python function to calculate 'b' from the passed in 'a' value
def b( a ):
    return -24*a - 1/6

# a Python function to calculate 'f(x)' from the passed values for a, b, c and x
def f( a, b, c, x ):
    return (a*x + b)*x + c

print( "\nCHECK: For a1 =", a1 )
print( "f(0) =", f(a1, b(a1), 4, 0), "and f(24) =", f(a1, b(a1), 4, 24) )

print( "\nCHECK: For a2 =", a2 )
print( "f(0) =", f(a2, b(a2), 4, 0), "and f(24) =", f(a2, b(a2), 4, 24) )

# if   10 = a*x**2 + b*x + 4
# i.e.  0 = a*x**2 + b*x - 6


print( "\nFor a1 =", a1, "and b1 =", b(a1), "and c = 4" )
x1, x2 = roots(a1, b(a1), -6)
print( "when x1 =", x1, "or x2 =", x2 )
print( "CHECK: f(x1) =", f(a1, b(a1), 4, x1), "and f(x2) =", f(a1, b(a1), 4, x2) )

print( "\nFor a2 =", a2, "and b2 =", b(a2), "and c = 4"  )
x1, x2 = roots(a2, b(a2), -6)
print( "when x1 =", x1, "or x2 =", x2 )
print( "CHECK: f(x1) =", f(a2, b(a2), 4, x1), "and f(x2) =", f(a2, b(a2), 4, x2) )

input( "\nPress 'Enter' to continue/exit ... " )

"""
OUTPUT:
In f(x) = a*x*x + b*x + c
a takes TWO value, b = -24*a -1/6 and c = 4
a1 = -0.0005827792840304435 and a2 = -0.08275055404930289

CHECK: For a1 = -0.0005827792840304435
f(0) = 4.0 and f(24) = 0.0

CHECK: For a2 = -0.08275055404930289
f(0) = 4.0 and f(24) = -1.7763568394002505e-15

For a1 = -0.0005827792840304435 and b1 = -0.152679963849936 and c = 4
when x1 = -213.84017796050352 or x2 = -48.14573683388753
CHECK: f(x1) = 10.000000000000002 and f(x2) = 10.0

For a2 = -0.08275055404930289 and b2 = 1.8193466305166026 and c = 4
when x1 = 4.040400677928648 or x2 = 17.945514116462135
CHECK: f(x1) = 10.0 and f(x2) = 10.000000000000002

Press 'Enter' to continue/exit ... ...
"""


Version 2 below, also finds and shows both the other roots (beside the given root of 24) ...
for each of the possible 2 (pairs of) 'a' and 'b' values in the relation f(x) = a*x*x + b*x + 4

Code: [Select]
# find_abcx_ver2.py #  # 2016-01-26 #

# (1) Since we are given 24 is a root of the quadratic, we can use the form:
#             f(x) = a*(x-r)*(x-24)
#                  = a*( x*x -(r+24)*x + 24*r )

# (2) But when   x = 0, f(0) = 4 implies 4 = a*24*r and that implies r = 1/(6*a)
# AND THUS    f(x) = a*x*x - a*(1/(6*a) + 24)*x + a*24*(1/(6*a))
# OR          f(x) = a*x*x - (1/6 + 24*a)*x + 4
# thus           b = -(1/6 + 24*a) = -24*a - 1/6
# and            c = 4
# re. form    f(x) = a*x*x + b*x + c

# (3) Now to find a  = ? in f(x) = a*x*x - (24*a+ 1/6)*x + 4

# SINCE the max value of 14 occurs when x = (24*a + 1/6)/(2*a)

# thus:   14 = (24*a + 1/6)^2 /(4*a) - (24*a + 1/6)^2 /(2*a) + 4

# i.e.    10 = (24*a + 1/6)^2 /(4*a) - (24*a + 1/6)^2 /(2*a)
#         10 = - (24*a + 1/6)^2 /(4*a)
#       40*a = - (24*24*a*a + 8*a + 1/36)
#          0 = 24*24*a*a + 48*a + 1/(6*6)   
# THUS         a*a + (1/12)*a + 1/((6*24)*(6*24)) = 0
# i.e.         a*a + (1/12)*a + 1/(12^4) = 0


# define a Python function to find and return both of the roots ...
def roots( a, b, c ):
    return (-b + (b*b - 4*a*c)**.5)/(2*a), (-b - (b*b - 4*a*c)**.5)/(2*a)

a1, a2 = roots( 1, 1/12, 1/12**4 )

print( "In f(x) = a*x*x + b*x + c" )
print( "a takes TWO value, b = -24*a -1/6 and c = 4" )
print( "a1 =", a1, "and a2 =", a2 )


# define a Python function to find and return the (other) 'r' for this passed in 'a'
# from (2) above ...
def r( a ):
    return 1/(6*a)

print( "\nIn f(x) = a*(x-r)*(x-24), since f(0) = 4, THUS r = 1/(6*a)" )
print( "r(a1) =", r(a1), "and r(a2) =",r(a2) )


# define a Python function to find and return 'b' for the passed in value of 'a' ...
def b( a ):
    return -24*a - 1/6

# define a Python function to evaluate f(x) for passed in values for a,b,c,x ...
def f( a, b, c, x ):
    return (a*x + b)*x + c


print( "\nCHECK: For a1 =", a1 )
print( "f(0) =", f(a1, b(a1), 4, 0), "and f(24) =", f(a1, b(a1), 4, 24) )
print( "f(0) =", a1*(0-r(a1))*(0-24), "and f(24) =", a1*(24-r(a1))*(24-24) )

print( "\nCHECK: For a2 =", a2 )
print( "f(0) =", f(a2, b(a2), 4, 0), "and f(24) =", f(a2, b(a2), 4, 24) )
print( "f(0) =", a2*(0-r(a2))*(0-24), "and f(24) =", a2*(24-r(a2))*(24-24) )



# Now re...
# 10 = a*x*x + b*x + 4
#  0 = a*x*x + b*x - 6

print( "\nFor a1 =", a1, "and b1 =", b(a1), "and c = 4" )
x1, x2 = roots(a1, b(a1), -6)
print( "when x1 =", x1, "or x2 =", x2 )
print( "CHECK: f(x1) =", f(a1, b(a1), 4, x1), "and f(x2) =", f(a1, b(a1), 4, x2) )

print( "\nFor a2 =", a2, "and b2 =", b(a2), "and c = 4"  )
x1, x2 = roots(a2, b(a2), -6)
print( "when x1 =", x1, "or x2 =", x2 )
print( "CHECK: f(x1) =", f(a2, b(a2), 4, x1), "and f(x2) =", f(a2, b(a2), 4, x2) )

input( "\nPress 'Enter' to continue/exit ... " )

"""
OUTPUT:
In f(x) = a*x*x + b*x + c
a takes TWO value, b = -24*a -1/6 and c = 4
a1 = -0.0005827792840304435 and a2 = -0.08275055404930289

In f(x) = a*(x-r)*(x-24), since f(0) = 4, THUS r = 1/(6*a)
r(a1) = -285.9859147943911 and r(a2) = -2.014085205609215

CHECK: For a1 = -0.0005827792840304435
f(0) = 4.0 and f(24) = 0.0
f(0) = 4.0 and f(24) = -0.0

CHECK: For a2 = -0.08275055404930289
f(0) = 4.0 and f(24) = -1.7763568394002505e-15
f(0) = 4.0 and f(24) = -0.0

For a1 = -0.0005827792840304435 and b1 = -0.152679963849936 and c = 4
when x1 = -213.84017796050352 or x2 = -48.14573683388753
CHECK: f(x1) = 10.000000000000002 and f(x2) = 10.0

For a2 = -0.08275055404930289 and b2 = 1.8193466305166026 and c = 4
when x1 = 4.040400677928648 or x2 = 17.945514116462135
CHECK: f(x1) = 10.0 and f(x2) = 10.000000000000002

Press 'Enter' to continue/exit ...
"""


To see this graphed ... go to a Google search window ... then copy the following line and paste it there:

graph y = 10,   -0.000582x^2  -0.153x + 4,   -0.08275x^2 + 1.8193x + 4

Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on January 31, 2016, 11:29:31 AM
Another typical quadratic problem is one like this ...

Given the graph  ...

or the equation:   h = –4.9t^2 + 50t + 1.5

of a quadratic relation representing the height of a ball,
(thrown straight up, beginning from 1.5 meters above the ground),
over elapsed time, (seconds),
answer questions such as the following:

1) What is the maximum height of the ball?  ==> k = (50^2/(4*4.9) + 1.5) = 129.1

2) After what length of time (from time 0) will the ball hit the ground? ==> 10.23

3) Over what time interval is the height of the ball greater than 3 m   ==>  t1 = 0.0301, t2 = 10.17, interval = 10.14


A Python 3 solution is coded below:
(You can copy/paste the following text into a text editor and save this file with file name as:  find_max_and_time.py
 To run the program, 'find_max_and_time.py', i.e. to see the OUTPUT produced,
 click on the file name, after you have installed a version of Python 3 - if you have not done that already.)


Code: [Select]
# find_max_and_time.py #  # 2016-01-31 #

"""
Solve: –4.9t^2 + 50t + 1.5 = 0
by using algebra ... and by graphing h = –4.9t^2 + 50t + 1.5 using technology.

Note alternate (VERTEX) form:
h = -4.9( t - 50/(4.9*2) )^2 + (50^2/(4*4.9) + 1.5)

Given the graph or the equation of the above quadratic relation,
representing the height of a ball over elapsed time,
answer questions such as the following:
1) What is the maximum height of the ball?  ==> k = (50^2/(4*4.9) + 1.5) = 129.1
2) After what length of time will the ball hit the ground? (10.23)
3) Over what time interval is the height of the ball greater than 3 m
   t1 = 0.0301, t2 = 10.17
"""

# if h = –4.9t2 + 50t + 1.5
def h( a, b, c, t ):
    return (a*t + b)*t + c

def roots( a, b, c ):
    return (-b + (b*b - 4*a*c)**.5)/(2*a), (-b - (b*b - 4*a*c)**.5)/(2*a)

t1, t2 = roots( -4.9, 50, 1.5 )
print( "t1 =", t1, "t2 =", t2 )
print( "Flight ends after", max(t1,t2), "units of time from 'time 0'." )

# max occurs at t = -b/(2a)
tmax = -50/(2*(-4.9))
print( "Max height was", h( -4.9, 50, 1.5, tmax), "units. CHECK =", 50**2/(4*4.9) + 1.5 )

#if h = 3,
t3, t4 = roots( -4.9, 50, -1.5 )
print( "t3 =", t3, "t4 =", t4 )
print( "Time interval flight was above '3' was", abs(t4-t3), "units of time." )

input( "\nPress 'Enter' to continue/exit ... " )

"""
OUTPUT:
t1 = -0.029912314835277086 t2 = 10.233993947488337
Flight ends after 10.233993947488337 units of time from 'time 0'.
Max height was 129.05102040816325 units. CHECK = 129.05102040816325
t3 = 0.030088722459485746 t4 = 10.173992910193574
Time interval flight was above '3' was 10.143904187734089 units of time.

Press 'Enter' to continue/exit ...
"""


Now you can paste a copy of the text below into a Google search window, to see this graphed:

graph of y = –4.9t^2 + 50t + 1.5 ,  y = 50^2/(4*4.9) + 1.5 , y = 3
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 08:42:47 AM
Review of equations of a line ...

Firstly the form A*x + B*y + C = 0 and how it converts to the form y = m*x + b

Code: [Select]
# lines_1.py #  # 2016-03-19 #

'''
For 'slope, y-intercept form' (m is slope, b is y-intercept)
y = m*x + b

or (inverse) ...
x = (y-b)/m

y(at x=0) = b
x(at y=0) = -b/m


For 2 point form, (x1,y1) and (x2,y2) ...
determine the line ?

Firstly ...
m = (y2-y1)/(x2-x1)

y2 = m*x2 + b implies that ...
b  = y2 - m*x2
   = y2 - (y2-y1)/(x2-x1) * x2

THUS ...
y      = m*x + b implies ...
y      = (y2-y1)/(x2-x1) * x  +  y2 - (y2-y1)/(x2-x1) * x2
y - y2 = (y2-y1)/(x2-x1) * x - (y2-y1)/(x2-x1) * x2
y - y2 = m * (x - x2 )

and/or we also can find the equation of the line using (x1, y1)  ...
(if given 2 distinct points (x1, y1) and (x2, y2) that determine the line)
y - y1 = m * (x - x1 )

(Recall that the slope 'm' here is given by: (y2-y1) / ((x2-x1)


Or if start with ...     A*x + B*y + C = 0

(If B != 0) same as: (A/B)*x + y + C/B = 0

and same as:                         y = -(A/B)*x - C/B
thus ... m = -A/B and b = -C/B
'''

def slopeIntercept( A, B, C ):
    return -A/B, -C/B

A, B, C = 1, 2, 3;
m, b = slopeIntercept( A, B, C )

print( "For equation of line with form: A*x + B*y + C = 0" )

print( "For A = {}, B = {}, C = {}, slope m = {:.2e}, intercept b = {:.2e}".
       format( A, B, C, m, b ) )

more = True
while more :
    line = input( "Enter A B C: " ) # prompt and take in a line #

    # split the line elements separated by spaces,
    # into a list of strings
    lst = line.split()
   
    goodData = True
    newLst = []
    try:
        newLst = [eval(stg) for stg in lst]
    except:
        goodData = False
        print( "\nNumbers only please ... Try again.\n" )

    if not goodData:
        continue # start at top of 'while loop' #

    if len(newLst) != 3:
        print( "\nMust enter 3 and ONLY 3 numbers ... Try again.\n" )
        continue # start at top of 'while loop' #
       
    A, B, C = tuple(newLst)
    if B == 0:
        print( "\nB can NOT be zero ... Try again.\n" )
        continue # start at top of 'while loop' #
   
    try:
        m, b = slopeIntercept( A, B, C )
    except:
        goodData = False

    if not goodData:
        print( "\nData entry error ... Try again, 3 numbers, spaces between.\n" )
        continue # start at top of 'while loop' #
       
    print( "For A = {}, B = {}, C = {}, slope m = {:.2e}, intercept b = {:.2e}".
       format( A, B, C, m, b ) )

    if input( "More (y/n) ? " ).lower() == "n":
        more = False



Now ... if you have two lines, (with finite slope), can you solve and find the (one) point of intersection, (if the lines are NOT parallel)?

Code: [Select]
# lines_2.py #  # 2016-03-19 #

'''
For 'slope, y-intercept form' (m is slope, b is y-intercept)
y = m*x + b

or (inverse) ...
x = (y-b)/m

y(at x=0) = b
x(at y=0) = -b/m


For 2 point form, (x1,y1) and (x2,y2) ...
determine the line ?

Firstly ...
m = (y2-y1)/(x2-x1)

y2 = m*x2 + b implies that ...
b  = y2 - m*x2
   = y2 - (y2-y1)/(x2-x1) * x2

THUS ...
y      = m*x + b implies ...
y      = (y2-y1)/(x2-x1) * x  +  y2 - (y2-y1)/(x2-x1) * x2
y - y2 = (y2-y1)/(x2-x1) * x - (y2-y1)/(x2-x1) * x2
y - y2 = m * (x - x2 )


Or if start with ...     A*x + B*y + C = 0

(If B != 0) same as: (A/B)*x + y + C/B = 0

and same as:                         y = -(A/B)*x - C/B
thus ... m = -A/B and b = -C/B
'''

def slopeIntercept( A, B, C ):
    return -A/B, -C/B

A, B, C = 1, 2, 3;
m, b = slopeIntercept( A, B, C )

print( "For equation of line with form: A*x + B*y + C = 0" )

print( "For A = {}, B = {}, C = {}, slope m = {:.2e}, intercept b = {:.2e}".
       format( A, B, C, m, b ) )

A2, B2, C2 = 2, 3, 4;
m2, b2 = slopeIntercept( A2, B2, C2 )

print( "For A = {}, B = {}, C = {}, slope m = {:.2e}, intercept b = {:.2e}".
       format( A2, B2, C2, m2, b2 ) )


'''
At intersection y1 is same y2 and this implies ...

set m*x + b equal to m2*x + b2 ... and this implies ...
m*x - m2*x = b2 - b

x = (b2 - b) / (m - m2 )
y = m*x + b
'''

def intersection( m, b, m2, b2 ):
    x = (b2 - b) / (m - m2 )
    return x, m*x + b

x, y = intersection( m, b, m2, b2 )
print( "The lines intersect at ({:.2e},{:.2e})".format( x, y ) )

def getABC( msg ):
    while( True ):
        line = input( msg ) # prompt and take in a line #

        # split the line elements separated by spaces,
        # into a list of strings
        lst = line.split()
       
        numsOk = True
        newLst = []
        try:
            newLst = [eval(stg) for stg in lst]
        except:
            numsOk = False
            print( "\nNumbers only please ... Try again.\n" )

        if not numsOk:
            continue # start at top of 'while loop' #

        if len(newLst) != 3:
            print( "\nMust enter 3 and ONLY 3 numbers ... Try again.\n" )
            continue # start at top of 'while loop' #

        A, B, C = tuple(newLst)
       
        if B == 0:
            print( "\nB can NOT be zero ... Try again.\n" )
        else:
            break

    return A, B, C
   

more = True
while more:
   
    A, B, C = getABC( "Enter A B C: " )
    try:
        m, b = slopeIntercept( A, B, C )
    except:
        print( "\nBad data entry ... Try again, 3 numbers, spaces between.\n" )
        continue
   
    print( "For A = {}, B = {}, C = {}, slope m = {:.2e}, intercept b = {:.2e}".
       format( A, B, C, m, b ) )

    A2, B2, C2 = getABC( "Enter A2 B2 C2: " )
    try:
        m2, b2 = slopeIntercept( A2, B2, C2 )
    except:
        print( "\nBad data entry ... Try again, 3 numbers, spaces between.\n" )
        continue
   
    print( "For A2 = {}, B2 = {}, C2 = {}, slope m2 = {:.2e}, intercept b2 = {:.2e}".
       format( A2, B2, C2, m2, b2 ) )

    if m != m2:
        x, y = intersection( m, b, m2, b2 )
        print( "Lines intersect at Point ({:.2e},{:.2e})".format(x, y) )
    else:
        print( "\nParallel lines will NEVER intersect ...\n" )
       

    if input( "More (y/n) ? " ).lower() == "n" :
        more = False

Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 08:45:23 AM
Now for, a little more interesting, 3 questions ...

Firstly, here is some reference material to get some needed data to do these questions.

Questions for beginning grade 10 (advanced) review ...


(1) How long after a solar flare erupts, can it be seen from earth?

https://en.wikipedia.org/wiki/Astronomical_unit

The astronomical unit (symbol au), is a unit of length,
roughly the distance from Earth to the Sun.

However, that distance varies as Earth orbits the Sun,
from a maximum (aphelion) to a minimum (perihelion)
and back again once a year.

*Originally conceived as the average of Earth's aphelion and perihelion*,
it is now defined as exactly
149,597,870,700 metres
(about 150 million kilometres, or 93 million miles) ...


https://en.wikipedia.org/wiki/Speed_of_light

The speed of light in vacuum, commonly denoted c,
is a universal physical constant important in many areas of physics.
Its precise value is 299,792,458 metres per second
(approximately 3.00 * 10**8 m/s) ...



(2) Find an estimate of the number of red blood cells in an average adult male?

https://en.wikipedia.org/wiki/Mean_corpuscular_volume

Normally, MCV (Mean 'Cell' Volume) ... is expressed in femtoliters (fL),
(or 10**(-15) L),

and [RBC] is the quantity expressed in millions per microliter
(or 10**6 / µL) ... (or 10**12 / L)

The normal range for MCV is 80–100 fL.

( Note that a µL is 10**(-6) L. i.e. there are 10**6 µL in each L )

Now, take as an example ...
if the (measured) Hct = 42.5% (packed cells/to whole blood) and the ...
machine counted [RBC] = 4.58 million per microliter (4,580,000/µL),
and the (machine measured) MCV (was) = 92.8 * 10**(-15) L or 92.8 fL


If we assume 5.00 L of (whole) blood in this person ...
thus ... 5.00 * 0.425 L (packed cells) = 2.125 L (packed cells)


The total RBC count in all (assumed) 5 L is:

4.58 * 10**6 * 10**6  cells/L * (5 L)
=
4.58 * 10**12 cells/L * (5 L)
=
22.9 * 10**12 cells
=
2.29 * 10**13 cells

So our answer is: there are about 2.29 * 10**13 rbcs in this person,
(i.e. ....if the person had 5 L of (whole) blood.)


Also note ... X-checking ...
we can get a calculated average volume per (red) cell, (i.e a calculated MCV):

((assumed) packed cell_volume) / ((assumed) total number of cells)
(2.125) / (2.29 * 10**13)   (L/cell)
= 0.928 * 10**(-13) (L/cell)
= 92.8 *10**(-15) (L/cell)
= 92.8 fL / cell

This is the average (calculated) volume per each red blood cell (rbc),
(and note, it agrees here, with the machine measured value ... yeh :)


Thus ...
interesting here, to also note, we can get a calculated Hct ...
(from blood counting machine values for MCV and [RBC])

MCV * [RBC]  (L/cell * cells/L)
=
92.8 * 10**(-15)  *  (4.58 * 10**12)
=
425 * 10**(-3)
=
.425
= (same value as Hct measured here ... Yeh!!!)



(3)

Using data at ...

http://agron-www.agron.iastate.edu/Courses/Agron212/Calculations/Seed_acre.htm

find the average volume occupied in an 100 bag, by a single grain of wheat ?

(Use very ROUGH estimates for bag radius and height - bag treated as a cylinder)
Volume (Vb) 100 lb bag r = 8 cm, h = 30 cm ...  Vb =  pi * r**2 * h

12500 seeds / lb (given at above link)
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 08:47:36 AM
Here is an easy Python program solution for question (1) re. time of transit ...

Code: [Select]
# scientificNotation_transitTime.py #  # 2016-03-21 #

'''
Question:

Find transit time of light from sun to earth?

https://en.wikipedia.org/wiki/Astronomical_unit

Distance (d) earth to sun is 93,000,000 miles = 9.3 * 10**7 miles
Speed    (v) of light is 300,000 km/sec =       3.00 * 10**5 km/sec
'''

d = 1.50 * 10**8 # km
print( "distance (km)   : {:.2e}".format( d ) )

v = 3.00 * 10**5 # km/sec
print( "speed (km/sec)  : {:.2e}".format( v ) )

t = d/v # seconds
print( "time (second)   : {:.2e}".format( t ) )

t = t/60 # minutes
print( "time (minute)   : {:.2e}".format( t ) )
print()
 

'''
distance (km)   : 1.50e+08
speed (km/sec)  : 3.00e+05
time (second)   : 5.00e+02
time (minute)   : 8.33e+00
'''


'''
Distance (d) earth to sun is 93,000,000 miles = 9.3 * 10**7 miles
Speed    (v) of light is 186,000 miles/sec    = 1.86 * 10**5 miles/sec
'''

d = 9.3 * 10**7 # miles
print( "distance (mile) : {:.2e}".format( d ) )

v = 1.86 * 10**5 # mph
print( "speed (mps)     : {:.2e}".format( v ) )

t = d/v # seconds
print( "time (second)   : {:.2e}".format( t ) )

t = t/60 # minutes
print( "time (minute)   : {:.2e}".format( t ) )

input( "\nPress 'Enter' to continue/exit ... " )

'''
distance (mile) : 9.30e+07
speed (mps)     : 1.86e+05
time (second)   : 5.00e+02
time (minute)   : 8.33e+00

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 08:50:09 AM
Now ... and easy Python solution to the problem of ...

(2) Find an estimate of the number of red blood cells in an average adult male?

Code: [Select]
# scientificNotation_numberRBCs.py #  # 2016-03-22 #


'''
Quetion was ... find estimate of the total rbc count for an adult male?

Here we assume, the total blood volume is 5 liters ...
and that 1/2 of this is taken up by the red cells, (i.e., the Hct = 50%)
and the measured (average or mean) cell volume was 90 fL
Note that 1 fL = 10**(-15) L

Volume blood (liter) Vblood = 5
Volume rbcs  (liter) Vcells = 5/2
Volume 1 rbc (liter) Vrbc   = 90 * 10**(-15)
'''

Vcells = 5/2
print( "Volume of packed cells (liter) : {:.2e}".format( Vcells ) )
Vrbc   = 90 * 10**(-15)
print( "Volume of single rbc (liter)   : {:.2e}".format( Vrbc ) )
n = Vcells / Vrbc
print( "number of rbcs                 : {:.2e}".format( n ) )

input( "\nPress 'Enter' to continue/exit ... " )

'''
Volume of packed cells (liter) : 2.50e+00
Volume of single rbc (liter)   : 9.00e-14
number of rbcs                 : 2.78e+13

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 08:51:04 AM
And thirdly ... a Python (version 3.x) solution to the problem ...

(3a) Find an estimate to the average volume occupied in an 100 bag, by a single grain of wheat ?

Code: [Select]
# scientificNotation_numberSeeds.py #  # 2016-03-21 #

from math import pi

'''
Question?

Using data at ...

http://agron-www.agron.iastate.edu/Courses/Agron212/Calculations/Seed_acre.htm

find the average volume occupied in an 100 bag, by a single grain of wheat ?

(Use very ROUGH estimates for bag radius and height - bag treated as a cylinder)
Volume (Vb) 100 lb bag r = 8 cm, h = 30 cm ...  Vb =  pi * r**2 * h

12500 seeds / lb (given at above link)
'''

n = 100 * 12500 # 1,250,000 seeds in 100 lb bag #
print( "number of seeds  : {:.2e}".format( n ) )

r  = 8 # in cm #
print( "bag radius (cm)  : {:.2e}".format( r ) )
h  = 30 # in cm #
print( "bag height (cm)  : {:.2e}".format( h ) )
Vb = pi * r**2 * h
print( "bag Vb (cm^3)    : {:.2e}".format( Vb ) )
Vb = Vb * 1000
print( "bag Vb (mm^3)    : {:.2e}".format( Vb ) )

Vs = Vb/n # mm^3
print( "seed Vs (mm^3)   : {:.2e}".format( Vs ) )



wps = 100/n # lbs per seed
print( "Weight/seed (lb) : {:.2e}".format( wps ) )
print( "X-check seeds/lb : {:.2e}".format( 1/wps ) )

wps = wps * 1000 # lbs per 1000 seeds
print( "Per k seeds (lb) : {:.2e}".format( wps ) )
wps = ( wps / 2.2 ) * 1000
print( "Per k seeds (gm) : {:.2e}".format( wps ) )

print( "\nRecall 2.2 lb is 1.0 kg" ) # 0.453592 kg = 1 lb #

print( "Better is 1 lb   : {:.5e} gm".format(453.592) )
print( "and 1 kg         : {:.5e} lb".format(2.20462) )

       
input( "\nPress 'Enter' to continue/exit ... " )

'''
number of seeds  : 1.25e+06
bag radius (cm)  : 8.00e+00
bag height (cm)  : 3.00e+01
bag Vb (cm^3)    : 6.03e+03
bag Vb (mm^3)    : 6.03e+06
seed Vs (mm^3)   : 4.83e+00
Weight/seed (lb) : 8.00e-05
X-check seeds/lb : 1.25e+04
Per k seeds (lb) : 8.00e-02
Per k seeds (gm) : 3.64e+01

Recall 2.2 lb is 1.0 kg
Better is 1 lb   : 4.53592e+02 gm
and 1 kg         : 2.20462e+00 lb

Press 'Enter' to continue/exit .... 
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 21, 2016, 01:58:30 PM
And (3b)

(3b.1) Find number of seeds harvested from 10 acres.
(3b.2) Find weight of all this new wheat in lbs

Code: [Select]
# scientificNotation_numberSeeds2.py #  # 2016-03-21 #

'''
Questions ?

1) Find number of seeds harvested from 10 acres.
2) Find weight of all this new wheat in lbs

Using data at ...

http://agron-www.agron.iastate.edu/Courses/Agron212/Calculations/Seed_acre.htm

From the link above, it was shown that 653.4 lbs will seed 10 acres
i.e. 6.53 * 10**2 (rounded to 3 significant figures, and in scientific notation)
12500 seeds / lb (given at above link)
'''

print( "For 10 acres seeded with wheat ..." )

w = 6.53 * 10**2 # num lbs seed to seed 10 acres
print( "seed weight (lb)            : {:.2e}".format( w ) )
 
n = 6.53 * 10**2 * 12500 # told that 12500 seeds / lb #
print( "number of seeds             : {:.2e}".format( n ) )

f = 80 # 100 * .80 = 80 fold gain over seeds planted #
print( "net fold gain (multiplier)  : {:.2e}".format( f ) )

h = n * f # harvested number of seed #
print( "number seeds harvested      : {:.2e}".format( h ) )

wh_old = h / 12500 # lbs if same weight per seed as the weight per seed planted
print( "weight harvested (old-lbs)  : {:.2e}".format( wh_old ) )

wh_new = wh_old * 1.2 # (lbs) Note: the new seeds weigh 20% more on the average than the old seeds planted #
print( "weight harvested (new-lbs)  : {:.2e}".format( wh_new ) )

wh_check = w * 80 * 1.2
print( "weight gain check (new-lbs) : {:.2e}".format( wh_check ) )

       
input( "\nPress 'Enter' to continue/exit ... " )


'''
For 10 acres seeded with wheat ...
seed weight (lb)            : 6.53e+02
number of seeds             : 8.16e+06
net fold gain (multiplier)  : 8.00e+01
number seeds harvested      : 6.53e+08
weight harvested (old-lbs)  : 5.22e+04
weight harvested (new-lbs)  : 6.27e+04
weight gain check (new-lbs) : 6.27e+04

Press 'Enter' to continue/exit ..
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on March 24, 2016, 01:10:05 PM
Beginning quadratics ...

Recall that quadratics have several forms
and 3 independent parameters
to determine the parabola
(just as linear relations have several forms
(and 2 independent parameters to determine the line.)



Review for linear relations ...

Recall that the equation for a line has 3 forms, but really only 2 ... **** why? ***:


(1) slope and y-intercept form, with parameters m, b ... the slope & intercept
y = f(x) = m*x + b


(2) two point form given P1(x1, y1) and P2(x2, y2)
We know that the slope, m = (y2 -y1) / (x2 -x1)
Thus we now have, y = m*x + b = (y2 - y1) / (x2 - x1) * x + b
But both points P1 and P2 are on the line,
so each point MUST satisfy the equation.
Using p2, we have ...
y2 = (y2 - y1) / (x2 - x1) * x2 + b
and thus b = ...
b = y2 - (y2 - y1) / (x2 - x1) * x2
And substituting this in y = m*x + b gives us ...
y = (y2 - y1) / (x2 - x1) * x + y2 - (y2 - y1) / (x2 - x1) * x2
and that is same as ...
y - y2 =
     (y2 - y1) / (x2 - x1) * x  - (y2 - y1) / (x2 - x1) * x2
Note that if  we had used P1 above, we would ALSO have ...
y - y1 =
     (y2 - y1) / (x2 - x1) * x  - (y2 - y1) / (x2 - x1) * x1

... and this is the same as:
  (y - y1) / (x - x1)  = m = (y2 - y1) / (x2 - x1)


(3) A*x + B*y + C = 0 form that reduces to y = m*x + b
If we divide through by B, (if B != 0), we have ...
(A/B)*x + y + C/B = 0
and this gives us ...
y = -(A/B)*x - C/B
Thus slope m is -(A/B) and y-intercept b is - C/B

*** So if you are given 2 distinct points,
    or the slope and one point for the line,
    you can then DETERMINE the unique line so specified.***




Now for a parabola ...

we might suspect that 3 distinct points ...
or the vertex point and one other distinct point ...
(note that the other, not vertex point, also gives us the symetric other 3rd point) ...

or that ...
3 independant parameters ... like (a, b, c) in ...
y = f(x) = a*x*x + b*x +c

that this would fully determine a (vertically orientated) parabolic curve ...
Why?


(1) root form with roots r1, r2 (Note: roots often are called p, q)
y = f(x) = a*(x - r1)*(x - r2)
Note that ...
if x = r1, then factor (r1 - r1) = 0 and y becomes 0
or ...
if x = r2, then (r2 - r2) = 0 and y also becomes 0
So in either case, y, i.e. f(x), then becomes 0

What do changes in value of 'a' do here to the shape of the (parabolic) curve ?

if sign of 'a' is reversed ?

Answer: if sign of value 'a' is reversed, curve has same vertex but is flipped over,
if 'a' is positive, curve 'opens up', if 'a' is negative, curve 'opens down'

if |a| > 1 ?  ... recall that |a| means the absolute value of (value) 'a'
Answer: as |a| grows, the curve rises MORE quickly ...

if |a} < 1 ?
Answer:
curve is 'flattened out' as |a| gets smaller
curve with |a| < 1, compared to curve with |a| > 1, is 'MUCH flatter'.


If we multiply 'a' through ... we get ...

y  = a*x*x - a*(r1 + r2)*x + a*r1*r2
which suggests that we can factor a quadratic back into the form:
y = a*(x - r1)*(x - r2)
which suggests that if a quadratic has a root, say r1, (i.e. if x = r1 makes y = 0),
then it can be factored into the form:
y = a*(x - r1)*(x - r2)

This suggests a 'factor therom' ...
i.e. if f(x) = 0 has the root 'r', (i.e. f(r) evaluates to 0 for x = r),
      then (x - r) is a factor of f(x)


(2) Vertex form
y = f(x) = a*(x - h)*(x - h) + k
Note that here, if x = h, then (h - h) is 0, and then y = k,
and 'k' is the extreme (vertex) 'y' value (either a max or a min depending on ?)

So here, the vertex point is given by (h, k)

Now if we expand this form ... we get ...

y = a*x*x - 2*a*h*x + a*h*h + k
  = a*x*x + (-2*a*h)*x + (a*h*h + k)



(3) 'general' or 'standard' form for quadratic (with graph a parabola)
y = f(x) = a*x*x + b*x + c



Now note that for all 3 forms, each have 3 independant parameters,
and that values for those 3 parameters together will determine an unique parabola.


Comparing coefficients for the 'x' (power 1) terms ...

we can see ... from parabola forms (3) and (2) above ... that ...
-2*a*h = b

and thus ...
h = - b / (2*a)

and recall that this is the value of x where the 'vertex' (the extreme value) is reached.


Also ...
comparing coefficients for the 'x' (power 1) terms ...

we can see ... from parabola forms (1) and (2) above ... that ...
-2*a*h = - a*(r1 + r2)

and thus ...
h = (r1 + r2)/2  ... (which we already knew from symetry considerations) ...

and recall that this is the value of x where the 'vertex' (the extreme value) is reached.



Practice questions:


(i)  if y = 2*x*x + 4*x + 2, describe the graph.
Answer:
We can factor out 2 and thus we have:
y = 2*(x*x + 2*x + 1)
And this is same as y = 2*(x + 1)*(x + 1)
So graph 'opens up' and has root -1 (i.e. '2 equal roots' with both same, i.e. -1)
i.e. the graph just 'touches' the x-axis at (i.e y = 0 ONLY at) x = -1
i.e. the vertex is (-1, 0)


(ii) if y = f(x) = -2*(x - 2)*(x + 1), describe the graph.
Answer:
Graph 'opens down'
Roots are 2 and -1, i.e. f(x) = 0 for these values of x
Expanded (and re-arranged in vertex form) is:
y = -2*(x*x - x - 2)
  = -2*(x*x - x) + 4
  = -2*(x*x - x + 1/4 - 1/4) + 4   ... Note that here we 'complete the square'
  = -2*(x*x - x + 1/4) + 2/4 + 4
  = -2*(x - 1/2)*(x - 1/2) + 9/2

Thus, the vertex point is: (1/2, 9/2)

Another way to do this would be to expand to:
y = -2*(x*x - x - 2)
  = -2*x*x + 2*x + 4

Then recall that for form y = a*x*x + b*x + c,
that x = -b/(2*a) is the 'x' for the vertex ...

THUS, by inspecting the coefficients,
(i.e. using b = 2 and a = -2)
we get that the x at our vertex is: -(b) / (2*a) = -(2) / (2*(-2)) = 1/2
and f(1/2) = -2*(-3/2)*(3/2) = 9/2
So the vertex is: (1/2, 9/2)

BUT ... the SIMPLEST way to do this would be to note (from symetry considerations), 
that the axis of symmetry for this parabola, is a line drawn parallel to the y-axis,
that intersects the x-axis mid-way between the two roots,  x= -1 and x = 2

i.e. mid-point is at x = (2 + (-1))/2 = 1/2

and then to substitute that x = 1/2 value
back into f(x) = -2*(x - 2)*(x + 1) to get ...

f(1/2) = -2(-3/2)(3/2) = 9/2

And thus, the vertex is at point (1/2, 9/2)

q.e.d.



(iii) if y = -3*(x - 2)*(x - 2) + 10, describe the graph.
Answer:
Graph 'opens down' (since sign of x*x co-efficient is negative)
The max value is 10
The vertex point is (2, 10)
and expanding, we get ...
y = -3*(x*x - 4*x + 4) + 10
  = -3*x*x + 12*x - 2
If we solve for y = 0,
then 0 = 3*x*x - 12*x + 2

using formula for roots:  (-b +- sqrt(b*b - 4*a*c)) / (2*a)

So ... roots are: (12 +- sqrt(12*12 - 4*3*2)) / (2*3)
                      = (12 +- sqrt(144 - 24)) / 6
                      = (12 +- sqrt(120)) / 6
                      = 2 +- 1.825
                      = 3.825 and 0.175


BUT this y = 0 = -3*(x - 2)*(x - 2) + 10 could also be more easily solved (find roots/zeros) like this:

-10 = -3*(x - 2)*(x - 2)

10/3  = (x-2)*(x-2)

Thus  x-2 = +- sqrt(10/3) 
and so x  = 2 +- sqrt(10/3) ...

NOW note that sqrt(10/3) is the very same thing as sqrt(120)/6

PROOF: sqrt(120)/6 = sqrt(120/36) = sqrt(20/6) = sqrt(10/3)

q.e.d





ADVANCED question:
(iv) If a parabola goes through the points (0, 2) and (12, 0)
     and reaches a max value of 10,
     can you find an equation (equations) for the graph(s) ?



Next to do ...

what is ... (more on) Completing the square ?
what is ... (more about) general formula to find roots of quadratic ?
what is ... discriminant (D) ... what is meaning if D < 0, D = 0, D > 0 ?

Advanced:
what is slope at point ?
what is slope at extreme point (the vertex) ?






SOLUTION to (iv - ADVANCED question);

Code: [Select]
w.r.t. form ...
y = a*x*x + b*x + c

we are told that y = 2 if x = 0, thus we find that c = 2


Also the point (12, 0) being on the parabola, implies ...
0 = a*144 + b* 12 + 2

thus ...     a = (-12*b - 2) / 144
             a = -(6*b + 1)/72


And we know that max value of 10 occurs at x = -b/(2*a)

so we have: 10 = a * (-b/(2*a)) * (-b/(2*a)) + b * (-b/(2*a)) + 2
thus         8 = a* (b*b/(4*a*a) - b*b/(2*a)
               = b*b/(4*a) - b*b/(2*a)
               = -b*b/(4*a)

and       32*a = -b*b
so           a = -b*b/32

and now, substituting this back into, a = -(6*b + 1)/72 , this means that:
-b*b/32 = -(6*b + 1)/72

multiply through by -8 ...
b*b/4   = (6*b + 1) / 9

9*b*b / 36 = 4*(6*b + 1) / 36
9*b*b - 24*b - 4 = 0


Now use a Python program and root formula to find roots ...


Then X-check results ...


Code: [Select]
# problem_iv.py #  # 2016-04-21 #

INTRO = '''SOLUTION to (iv - ADVANCED question);

w.r.t. quadratic equation with form:
y = a*x*x + b*x + c

we are told that y = 2 if x = 0, thus we can easily find that c = 2


Also the point (12, 0) being on the parabola, implies ...
             0 = a*144 + b*12 + 2
thus:   -144*a = 12*b + 2
             a = (12*b + 2) / (-144)
             a = -(6*b + 1)/72
             
And we know that the max value of 10 occurs at x = -b/(2*a)

so we have: 10 = a*(-b/(2*a))**2 + b*(-b/(2*a)) + 2
thus:        8 = a*(b*b/(4*a*a) - b*b/(2*a)
               = b*b/(4*a) - b*b/(2*a)
               = -b*b/(4*a)
               
And thus: 32*a = -b*b
so           a = -b*b/32  (a is this ...
                           whatever b is,
                           so now we find b,
                           then sub back to find a)
Subbing this back into:
             a = -(6*b + 1)/72
means that:
       -b*b/32 = -(6*b + 1)/72
multiply both sides by -8 yields:
         b*b/4 = (6*b + 1)/9
multiply both sides by 36 yields:
        9*b*b  = 4*(6*b + 1)
       
And thus:
9*b*b - 24*b - 4 = 0

So we get this above relation to solve for 'b' to find
suitable values for b that work there.

'''

print( INTRO )

c = 2
# 9*b*b - 24*b - 4 = 0 #

def roots( a, b, c ): # here, we are using the general formula to find roots of any quadratic, given a,b,c #
    return (-b - (b*b-4*a*c)**0.5) / (2*a), (-b + (b*b-4*a*c)**0.5) / (2*a)

def get_a( b ):
    return -b*b / 32

def f( a, b, c, x ):
    return (a*x + b)*x + c



b1, b2 = roots( 9, -24, -4 ) # find both values for b #
print( "b1 =", b1, "b2 =", b2 )
a1 = get_a( b1 )
a2 = get_a( b2 )

print( "a1 =", a1, "a2 =", a2 )

#X-checking ...

y1 = f( a1, b1, c, 0 ) # 2 #
y2 = f( a1, b1, c, 12 ) # 0 #
if abs(y2) < 1e-12: y2 = 0.0  # if VERY NEAR ZERO, show as ZERO #
print( "y1 =", y1, "y2 =", y2 )

y1 = f( a2, b2, c, 0 ) # 2 #
y2 = f( a2, b2, c, 12 ) # 0 #
if abs(y2) < 1e-12: y2 = 0.0
print( "y1 =", y1, "y2 =", y2 )

print( "\nX-checking extreme values ..." )

print( "{:.5f}*({:.2f})**2 + ({:.2f})*({:.4f}) + {} = {:.2f}"
       .format(a1, -b1/(2*a1), b1, -b1/(2*a1), c, f(a1,b1,c,-b1/(2*a1)) ) )
print( "{:.5f}*({:.2f})**2 + ({:.2f})*({:.4f}) + {} = {:.2f}"
       .format(a2, -b2/(2*a2), b1, -b2/(2*a2), c, f(a2,b2,c,-b2/(2*a2)) ) )

input( "\nPress 'Enter' to continue/exit ... " )


# OUTPUT from running program ... #
'''
SOLUTION to (iv - ADVANCED question);

w.r.t. quadratic equation with form:
y = a*x*x + b*x + c

we are told that y = 2 if x = 0, thus we can easily find that c = 2


Also the point (12, 0) being on the parabola, implies ...
             0 = a*144 + b*12 + 2
thus:   -144*a = 12*b + 2
             a = (12*b + 2) / (-144)
             a = -(6*b + 1)/72
             
And we know that the max value of 10 occurs at x = -b/(2*a)

so we have: 10 = a*(-b/(2*a))**2 + b*(-b/(2*a)) + 2
thus:        8 = a*(b*b/(4*a*a) - b*b/(2*a)
               = b*b/(4*a) - b*b/(2*a)
               = -b*b/(4*a)
               
And thus: 32*a = -b*b
so           a = -b*b/32  (a is this ...
                           whatever b is,
                           so now we find b,
                           then sub back to find a)
Subbing this back into:
             a = -(6*b + 1)/72
means that:
       -b*b/32 = -(6*b + 1)/72
multiply both sides by -8 yields:
         b*b/4 = (6*b + 1)/9
multiply both sides by 36 yields:
        9*b*b  = 4*(6*b + 1)
       
And thus:
9*b*b - 24*b - 4 = 0

So we get this above relation to solve for 'b' to find
suitable values for b that work there.


b1 = -0.15737865166652654 b2 = 2.824045318333193
a1 = -0.0007740012500116843 a2 = -0.2492259987499883
y1 = 2.0 y2 = 0.0
y1 = 2.0 y2 = 0.0

X-checking extreme values ...
-0.00077*(-101.67)**2 + (-0.16)*(-101.6656) + 2 = 10.00
-0.24923*(5.67)**2 + (-0.16)*(5.6656) + 2 = 10.00

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on April 02, 2016, 06:45:07 PM
It's time to develope the formula to find the roots of the standard form of the quadratic ...
(using 'completing the square') ...


Find formula for roots of a quadratic by 'Completing the Square'


Re. 'Standard Form' :  y = a*x**2 + b*x + c

Code: [Select]
If   y = 0
then 0 = a*x**2 + b*x + c
and  0 = x**2 + (b/a)*x + (c/a) ... <divide all by a != 0>
and    = (x + (b/(2*a)))**2 - b**2/(4*a**2) + (c/a) ... <complete the square>

Thus (x + (b/(2*a)))**2 =  b**2/(4*a**2) - (c/a) 
                        = (b**2 - 4*a*c)/(4*a**2)

Then  x + (b/(2*a))     = +- sqrt(b**2 - 4*a*c)/(2*a) ... <sqrt both sides>

So    x                 = (-b +- sqrt(b**2 - 4*a*c)) / (2*a)
i.e.  r1                = (-b - sqrt(b**2 - 4*a*c))  / (2*a)
and   r2                = (-b + sqrt(b**2 - 4*a*c))  / (2*a)

if b**2 - 4*a*c  =  0,   (i.e. if b**2 = 4*a*c),
then   r  =  -b/(2*a)

Note: b**2 - 4*a*c is called the 'discriminant' (D)
If D < 0   i.e. D is a negative value ...
then there are NO REAL roots. (Look up 'imaginary' numbers'.)


Also re. 'Standard Form' :
(re-arranging to 'Vertex Form' we have ...)

Code: [Select]
y = a*x**2 + b*x + c
  = a*(x**2 + (b/a)*x) + c
  = a*(x + (b/(2*a)))**2  - b**2/(4*a) + c     ... Note: a/(4*a**2) = 1/(4*a)

So re. 'Vertex Form' :  y = a*(x - h)**2 + k
h = -b/(2*a)
k = c - b**2/(4*a) = (4*a*c - b**2)/(4*a)


Also re. 'Root Form' :  y = a*(x - r1)*(x - r2)
(to go to 'Vertex Form', we have ...)

we know that h = mid point of r1 and r2,

Code: [Select]
thus h = (r1+r2)/2

and  k = a*((r1+r2)/2 - r1)*((r1+r2)/2 - r2)
       = a*(-r1+r2)/2)*((r1-r2)/2)
       = a*(-r1**2 + 2*r1*r2 -r2**2) / 4
       = -a*(r1 - r2)**2 / 4

       
Or ... to go from 'Root Form' to 'Standard Form' :  y = a*x**2 + b*x + c

Code: [Select]
we have :
y = a*(x - r1)*(x - r2)
  = a*x**2 - a*(r1+r2)*x + a*r1*r2

and thus :
b = -a*(r1+r2) ... i.e. r1+r2 = -b/a
c = a*r1*r2    ... i.e. r1*r2 =  c/a 
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on April 02, 2016, 06:56:02 PM
A Python 3 example that prints a Table of Values for all three forms of the quadratic ...
(and does a little more ... at the end ... It demos how to code, in Python 3,  to take in some data and show it back.)

1) Standard Form :  y = f(x) = a*x*x + b*x + c

2) Vertex Form     :  y = f(x) = a*(x - h)*(x - h) + k

3) Root Form        :  y = f(x) = a*(x - r1)*(x - r2)


Code: [Select]
# will_first_program_revised.py #  # 2016-03-24 and updated 2016-04-01 #

# edited/fixed version, value of 'a' here fixed to be negative #


'''
You are given a TABLE of VALUES (and asked to find dif's ...)
( x,      :      f(x)) : 1st dif, : 2nd dif. : 3rd dif.
=============================================================
( 0,      :        1 )
                       :   5
( 1,      :        6 )            :   2         
                       :   3                 :   0
( 2,      :        9 )            :   2
                       :   1                 :   0
( 3,      :       10 )            :   2
                       :  -1                 :   0
( 4,      :        9 )            :   2
                       :  -3                 :   0
( 5,      :        6 )            :   2
                       :  -5
( 6,      :        1 )

Now, since the 2nd dif's are 'constant', this is a 'quadratic relationship'.

(Recall, if 1st dif's were 'constant', it would be a 'linear relationship').

Thus ...
with respect to 'VERTEX' form for quadratic: y = f(x) = a*(x - h)*(x - h) + k
it looks like h = 3, k = 10 and value of a is negative.

So using/(subbing in) the 1st given point, (0, 1), that is on the curve,
into: y = a*(x - 3)*(x - 3) + 10,
we have ...
1 = a*9 + 10,
thus:  9*a = -9
and:     a = -1

THUS y = f(x) = -(x - 3)*(x - 3) + 10
and that means we also have ...
y = f(x) = -x*x + 6*x + 1

THUS for the form:  y = f(x) = a*x*x + b*x + c
we have ...
a = -1, b = 6, c = 1

We will confirm these values for a, b and c in the (calculated) TABLE below:

'''


a = -1 # fixed, the *value* of 'a' is *negative one* #
b = 6
c = 1

h = 3
k = 10


def f( a, b, c, x ):
    return a*x*x + b*x + c # <--fixed version, (you had: -a*x*x + b*x + c) #

def fVertex( a, h, k, x ):
    return a*(x - h)*(x - h) + k

def fRoots( a, r1, r2, x ):
    return a*(x - r1)*(x - r2)

# using formula for roots of a quadratic #
def roots( a, b, c ):
    r1 = (-b + (b*b - 4*a*c)**0.5) / (2*a)
    r2 = (-b - (b*b - 4*a*c)**0.5) / (2*a)
    return r1, r2

r1, r2 = roots( a, b, c )



print( 'Table of x and f(x) and fVertex(x) and fRoots(x) ...' )
print( '( x,' )
print( ' '*10, 'f(x) = {}*x*x + {}*x + {}),'.format( a, b, c ) )
print( ' '*20, 'fVertex(x) = {}*(x - {})*(x - {}) + {},'.format( a, h, h, k ) )
print( ' '*35, 'fRoots(x) = {}*(x - {:.3f})*(x - {:.3f}) )'
       .format( a, r1, r2 ) )

for x in range( -1, 8 ): # expanded range from x = -1 to and including x = 7 #
    print( '({:2}, {:14}, {:14}, {:14.3f} )'
           .format(x, f(a, b, c, x), fVertex(a, h, k, x), fRoots(a, r1, r2, x)) )


print( "r1, r2 = {:.5f}, {:.5f}".format( r1, r2 ), end = ' and ' )

#print( "X-checking ...", end = ' ' )
y1 = f(a, b, c, r1)
if abs(y1) < 1e-12: # 1e-12 means 1 * 10**(-12) #
    y1 = 0 # handle 'zero' values to be really set to zero #
y2 = f(a, b, c, r2)
if abs(y2) < 1e-12:
    y2 = 0 # handle 'zero' values to be really set to zero #

print( "f(r1), f(r2) = {:.11f}, {:.11f}". format(y1, y2) )




print( "Table of powers of 2 ..." )

for x in range( 2, 24, 3 ):
    print( "2**{:2} = {:11}".format(x-2, 2**(x-2)), ' '*7,
           "2**{:2} = {:11}".format(x-1, 2**(x-1)), ' '*7,
           "2**{:2} = {:11}".format(x, 2**x) )


   
# print()

name = input( 'Enter your name: ' )
name = name[0:1].upper() + name[1:] # set first letter to *upper* case #

age  = input( 'Enter your age (years): ' )

def ending( age ):
    if age not in [11, 12, 13, 111, 112, 113]:
        if age % 10 == 1: return 'st' # Note that % is for modular division #
        if age % 10 == 2: return 'nd'
        if age % 10 == 3: return 'rd'
    # if reach here ...
    return 'th'

# See IF the characters entered for age represent a valid integer #
try:
    age = int(age)
    if age >= 0:
        print( '{}, you really are past {} years old and '
               'are now in your {}{} year.'.
               format( name, age, age+1, ending(age+1) ) )
    else:
        print( '{}, {} really?'.format( name, age ) )
except:
    print( "(You did not enter a valid number for your years.)" )
    print( '{}, are you really {} years old?'.format( name, age) )
 
input ( "Press 'Enter' to continue/exit ... " )

# Below is copy/paste of output for a run of this program: #
'''
Table of x and f(x) and fVertex(x) and fRoots(x) ...
( x,
           f(x) = -1*x*x + 6*x + 1),
                     fVertex(x) = -1*(x - 3)*(x - 3) + 10,
                                    fRoots(x) = -1*(x - -0.162)*(x - 6.162) )
(-1,             -6,             -6,         -6.000 )
( 0,              1,              1,          1.000 )
( 1,              6,              6,          6.000 )
( 2,              9,              9,          9.000 )
( 3,             10,             10,         10.000 )
( 4,              9,              9,          9.000 )
( 5,              6,              6,          6.000 )
( 6,              1,              1,          1.000 )
( 7,             -6,             -6,         -6.000 )
r1, r2 = -0.16228, 6.16228 and f(r1), f(r2) = 0.00000000000, 0.00000000000
Table of powers of 2 ...
2** 0 =           1         2** 1 =           2         2** 2 =           4
2** 3 =           8         2** 4 =          16         2** 5 =          32
2** 6 =          64         2** 7 =         128         2** 8 =         256
2** 9 =         512         2**10 =        1024         2**11 =        2048
2**12 =        4096         2**13 =        8192         2**14 =       16384
2**15 =       32768         2**16 =       65536         2**17 =      131072
2**18 =      262144         2**19 =      524288         2**20 =     1048576
2**21 =     2097152         2**22 =     4194304         2**23 =     8388608
Enter your name: will
Enter your age (years): 15
Will, you really are past 15 years old and are now in your 16th year.
Press 'Enter' to continue/exit ...
'''

Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on April 19, 2016, 08:49:08 AM
An other ball trajectory problem ... solved using Python 3 ... that illustrates what is constant acceleration.


Code: [Select]
# ballTrajectory.py #  # 2016-04-21 #

INTRO = '''INTRODUCTION to solving QUADRATIC EQUATIONS and PARABOLAS ...

What does it actually mean ...
if we have *constant* acceleration ...
for constant acceleration, a,
in units of feet per cecond per second,
starting with initial velocity, vi = 0,
in units of feet per second,
if the constant acceleration, a = 32 feet per second per second?

This means that ...
at 1 second point, the velocity reached is 32 feet per second
st 2 second point, the velocity reached is 64 feet per second
st 3 second point, the velocity reached is 96 feet per second
st 4 second point, the velocity reached is 128 feet per second
etc...

So what is the distance traveled in each second?

We can easily find the average velocity over each second,
to see the total change in distance *for that second* ...

Then we can add up all the changes in distance over all the seconds.

Over the 1st second, the average velocity was (0+32)/2 feet per second.
So distance travelled then was: 16 feet

Over the 2nd second, the average velocity was (32+64)/2 feet per second.
So distance travelled then was: 16+32 feet = 48 feet

Over the 3rd second, the average velocity was (64+96)/2 feet per second.
So distance travelled then was: 32+48 feet = 80 feet

Over the 4th second, the average velocity was (96+128)/2 feet per second.
So distance travelled then was:, 48+64 feet = 112 feet


Thus at time zero, at (0, 0)
and  at time    1, at (1, 16)
and  at time    2, at (2, 64)
and  at time    3, at (3, 144)
and  at time    4, at (4, 256)
etc...


Can you see a pattern ?

Thus at time    n, at (n, 16*n**2)

But notice that 16 is exactly 1/2 of 32,
(the constanct acceleration here) ...
Thus, we can see, here, that for constant acceleration, a, the distance, d, is:

d = (1/2)*a*t**2

but if we had an initial velocity, vi,
in the same direction as the constant acceleration, a,

the distance, d, then becomes:

d = vi*t + (1/2)*a*t**2

and if we started at initial distance, di,
then the distance. d = f(t), becomes:

d = di + vi*t + (1/2)*a*t*t



NOTE ALSO:

d(1) = (a*0 + a*1)/2
     = a/2
     = a/2 * (1)**2


d(2) = (a*0 + a*1)/2 + (a*1 + a*2)/2
     = a/2 + a/2 + a
     = 2*a
     = a/2 * (2)**2


d(3) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2
     = a/2 + a/2 + a + a + 3*a/2
     = 4.5*a
     = a/2 * (3)**2


d(4) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2
     = a/2 + a/2 + a + a + 3*a/2 + 3*a/2 + 2*a
     = 8*a
     = a/2 * (4)**2


d(5) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2 + (a*4 + a*5)/2
     = 8*a + 4.5*a
     = 12.5*a
     = a/2 * (5)**2

Demo of 'proof by induction' ...
We assume:  d(n) = a/2 * (n)**2

Then:  d(n+1) = a/2 * (n+1)**2
              = a/2 * (n**2 + 2*n + 1)
              = a/2 * (n)**2 + a/2 *(2*n + 1)
              = d(n) + a*(n + n+1)/2
And that fulfills the pattern ...
So ... d(n) = a/2 * n**2
AND    d(t) = a/2 * t**2 = (1/2) * a * t**2     
'''


print( INTRO, '\n' )

def getDiffs( lst ):
     diffs = []
     for i in range(1, len(lst)):
          diffs.append(lst[i] - lst[i-1])
     return diffs


# NEW example(s) ... ball is propelled up, at 8 feet above the ground
# with initial up velocity at 40 feet per second,
# and initial side-ways velocity component of 100 feet per second
# let distance up, be a function of time, d(t), then d(t) = ?

def d(t):
    return 8 + 16*t*(2.5 - t) # i.e. d(t) = 8 + 40*t - 16*t*t #
   
# compare with NO initial velocity at all ...
# i.e. ball is dropped from 8 feet #
def d2( t ):
    return 8 - 16*t*t # i.e. d2(t) = 8 - 16*t*t #

# compare with (positive) initial velocity at 40 feet per second DOWN,
# and ball is descending from 0 (as 8) feet
# but t here is starting from t = 0 (2.5) seconds
# so solving 8 = 16*t*(2.5 + t) ... and plotting ... (to find 'zeros')
def f( t ):
    return -8 + 16*t*(2.5 + t) # i.e. f(t) = -8 + 40*t - 16*t*t #


print( "So we have 3 quadratic relations demo'd here ..." )
print( "d(t)  = 8 + 16*t*(2.5 - t) " )
print( "d2(t) = 8 - 16*t*t " )
print( "f(t)  = -8 + 16*t*(2.5 + t) " )


# get a Lst of pairs (t, d(t), d2( t), f(t)(t)) #
print( "\n\nNow let's get and print Python lists of (x, f(x)) for x in range -3..5" )
print( "Note that at t = 0, ball is at 8 feet up,\n"
       "\n1st distance column in has vi(up component)   = 40 feet per second,\n"
       "i.e. (up)        d(t) = 8 + 16*t*(2.5 - t) \n"
       "\n2nd distance column in has vi                 =  0 feet per second,\n"
       "i.e. (up)       d2(t) = 8 - 16*t*t \n"
       "\n3rd distance column in has vi(down component) = 40 feet per second,\n"
       "and now find time it takes to go down 8 more feet to the ground,\n"
       "i.e. for (down) d3(t) = 16*t*(2.5 + t), solve for d3(t) = 8 \n"
       "i.e. solve f(t) = 0 for f(t) = -8 + 16*t*(2.5 + t) \n" )
print( "-"*24 )
print( "{:>3s} {:>6s} {:>6s} {:>6s}".format('t', 'd', 'd2', 'f(t)'),
       "\n" + "-"*24 )

Lst3 = []
Lst2 = []
Lst  = []
for t in range(-3, 6):
    Lst3.append( f(t) )
    Lst2.append( d2(t) )
    Lst.append( d(t) )
    print( '{:3} {:6} {:6} {:6}'.format(t, d(t), d2(t), f(t)) )

print( "\nFirst differences ... with ..." )
firstDiffsLst3 = getDiffs(Lst3)
firstDiffsLst2 = getDiffs(Lst2)
firstDiffsLst  = getDiffs(Lst)
print("vi =  40, differences are:", firstDiffsLst)
print("vi =   0, differences are:", firstDiffsLst2)
print("vi = -40, differences are:", firstDiffsLst3)

print( "\nSecond differences ... with ..." )
secondDiffsLst3 = getDiffs(firstDiffsLst3)
secondDiffsLst2 = getDiffs(firstDiffsLst2)
secondDiffsLst  = getDiffs(firstDiffsLst)
print("vi =  40, differences are:", secondDiffsLst)
print("vi =   0, differences are:", secondDiffsLst2)
print("vi = -40, differences are:", secondDiffsLst3)


print( "\nRecall extreme value for d(t) is reached at 't = -b/(2*a) " )
t_at_max = (-40)/(-2*16)
print( "For d(t), t_at_max =", t_at_max, "seconds, and d(t_at_max) =",
       d(t_at_max), "feet.\n" )


def roots( a, b, c ):
    return (-b - (b**2 - 4*a*c)**0.5)/(2*a), (-b + (b**2 - 4*a*c)**0.5)/(2*a)


# d(t) = 8 + 16*t*(2.5 - t) #
r1_1, r1_2 = roots( -16, 40, 8 )
print( "\nNow finding roots r1 and r2 for each ..." )
print( "for d(t),   r1_1 = {}, r1_2 = {}".format(r1_1, r1_2) )

# d2(t) = 8 - 16*t*t #
r2_1, r2_2 = roots( -16, 0, 8 )
print( "for d2(t),  r2_1 = {}, r2_2 = {}".format(r2_1, r2_2) )

# 8 = 16*t*(2.5 + t) implies f(t) = -8 + 16*t*(2.5 + t) #
r3_1, r3_2 = roots( 16, 40, -8 )
print( "for f(t) ,  r3_1 = {}, r3_2 = {}".format(r3_1, r3_2) )

print( '\nNote that {} + {} = {}'.format(2.5, r3_2, r1_1) )

print( "\nSo, if the ball also had a sideways constant velocity "
       "of {} feet/second, \n"
       "it would hit the ground at {} ft/sec * {:.4f} sec = {:.2f} feet away."
       .format(100, 100, r1_1, 100*r1_1 ) )


input("\nPress 'Enter' to continue/exit ... " )


# output of running program #
'''
INTRODUCTION to solving QUADRATIC EQUATIONS and PARABOLAS ...

What does it actually mean ...
if we have *constant* acceleration ...
for constant acceleration, a,
in units of feet per cecond per second,
starting with initial velocity, vi = 0,
in units of feet per second,
if the constant acceleration, a = 32 feet per second per second?

This means that ...
at 1 second point, the velocity reached is 32 feet per second
st 2 second point, the velocity reached is 64 feet per second
st 3 second point, the velocity reached is 96 feet per second
st 4 second point, the velocity reached is 128 feet per second
etc...

So what is the distance traveled in each second?

We can easily find the average velocity over each second,
to see the total change in distance *for that second* ...

Then we can add up all the changes in distance over all the seconds.

Over the 1st second, the average velocity was (0+32)/2 feet per second.
So distance travelled then was: 16 feet

Over the 2nd second, the average velocity was (32+64)/2 feet per second.
So distance travelled then was: 16+32 feet = 48 feet

Over the 3rd second, the average velocity was (64+96)/2 feet per second.
So distance travelled then was: 32+48 feet = 80 feet

Over the 4th second, the average velocity was (96+128)/2 feet per second.
So distance travelled then was:, 48+64 feet = 112 feet


Thus at time zero, at (0, 0)
and  at time    1, at (1, 16)
and  at time    2, at (2, 64)
and  at time    3, at (3, 144)
and  at time    4, at (4, 256)
etc...


Can you see a pattern ?

Thus at time    n, at (n, 16*n**2)

But notice that 16 is exactly 1/2 of 32,
(the constanct acceleration here) ...
Thus, we can see, here, that for constant acceleration, a, the distance, d, is:

d = (1/2)*a*t**2

but if we had an initial velocity, vi,
in the same direction as the constant acceleration, a,

the distance, d, then becomes:

d = vi*t + (1/2)*a*t**2

and if we started at initial distance, di,
then the distance. d = f(t), becomes:

d = di + vi*t + (1/2)*a*t*t



NOTE ALSO:

d(1) = (a*0 + a*1)/2
     = a/2
     = a/2 * (1)**2


d(2) = (a*0 + a*1)/2 + (a*1 + a*2)/2
     = a/2 + a/2 + a
     = 2*a
     = a/2 * (2)**2


d(3) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2
     = a/2 + a/2 + a + a + 3*a/2
     = 4.5*a
     = a/2 * (3)**2


d(4) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2
     = a/2 + a/2 + a + a + 3*a/2 + 3*a/2 + 2*a
     = 8*a
     = a/2 * (4)**2


d(5) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2 + (a*4 + a*5)/2
     = 8*a + 4.5*a
     = 12.5*a
     = a/2 * (5)**2

Demo of 'proof by induction' ...
We assume:  d(n) = a/2 * (n)**2

Then:  d(n+1) = a/2 * (n+1)**2
              = a/2 * (n**2 + 2*n + 1)
              = a/2 * (n)**2 + a/2 *(2*n + 1)
              = d(n) + a*(n + n+1)/2
And that fulfills the pattern ...
So ... d(n) = a/2 * n**2
AND    d(t) = a/2 * t**2 = (1/2) * a * t**2
       

So we have 3 quadratic relations demo'd here ...
d(t)  = 8 + 16*t*(2.5 - t)
d2(t) = 8 - 16*t*t
f(t)  = -8 + 16*t*(2.5 + t)


Now let's get and print Python lists of (x, f(x)) for x in range -3..5
Note that at t = 0, ball is at 8 feet up,

1st distance column in has vi(up component)   = 40 feet per second,
i.e. (up)        d(t) = 8 + 16*t*(2.5 - t)

2nd distance column in has vi                 =  0 feet per second,
i.e. (up)       d2(t) = 8 - 16*t*t

3rd distance column in has vi(down component) = 40 feet per second,
and now find time it takes to go down 8 more feet to the ground,
i.e. for (down) d3(t) = 16*t*(2.5 + t), solve for d3(t) = 8
i.e. solve f(t) = 0 for f(t) = -8 + 16*t*(2.5 + t)

------------------------
  t      d     d2   f(t)
------------------------
 -3 -256.0   -136   16.0
 -2 -136.0    -56  -24.0
 -1  -48.0     -8  -32.0
  0    8.0      8   -8.0
  1   32.0     -8   48.0
  2   24.0    -56  136.0
  3  -16.0   -136  256.0
  4  -88.0   -248  408.0
  5 -192.0   -392  592.0

First differences ... with ...
vi =  40, differences are: [120.0, 88.0, 56.0, 24.0, -8.0, -40.0, -72.0, -104.0]
vi =   0, differences are: [80, 48, 16, -16, -48, -80, -112, -144]
vi = -40, differences are: [-40.0, -8.0, 24.0, 56.0, 88.0, 120.0, 152.0, 184.0]

Second differences ... with ...
vi =  40, differences are: [-32.0, -32.0, -32.0, -32.0, -32.0, -32.0, -32.0]
vi =   0, differences are: [-32, -32, -32, -32, -32, -32, -32]
vi = -40, differences are: [32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32.0]

Recall extreme value for d(t) is reached at 't = -b/(2*a)
For d(t), t_at_max = 1.25 seconds, and d(t_at_max) = 33.0 feet.


Now finding roots r1 and r2 for each ...
for d(t),   r1_1 = 2.686140661634507, r1_2 = -0.18614066163450715
for d2(t),  r2_1 = 0.7071067811865476, r2_2 = -0.7071067811865476
for f(t) ,  r3_1 = -2.686140661634507, r3_2 = 0.18614066163450715

Note that 2.5 + 0.18614066163450715 = 2.686140661634507

So, if the ball also had a sideways constant velocity of 100 feet/second,
it would hit the ground at 100 ft/sec * 2.6861 sec = 268.61 feet away.

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on April 21, 2016, 09:07:00 AM
A slightly different path to a solution ...

Code: [Select]
# solution_2.py #

INFO_1 = '''Points (0,2) and (12,0) are on the parabola with a max value of 10
find the equation(s) for the parabola(s).
'''

INFO_2 = '''Since 2 = a(0)**2 +b(0) + c,
c = 2
'''
c = 2

def f( a, b, x ):
    return (a*x + b)*x + 2

INFO_3 = '''But also (12,0) is on parabola ... so ...
0 = 144*a + 12*b + 2
thus ...
-12*b = 144*a + 2
b = -(12*a + 1/6)
or ...
144*a = -12*b - 2
thus...
a = -(12*b + 2)/144 = -(6*b + 1)/72
'''

def b_from_a( a ):
    return -(12*a + 1/6)

def extreme( a, b ): # recall extreme at x = -b/(2*a)
    #return a*(-b/(2*a))**2 + b*(-b/(2*a)) + 2
    return 2 - b*b/(4*a)

INFO_4 = '''But also max of 10 occurs for ...
10 = 2 - b*b/(4*a)
 8 = - b*b/(4*a)
thus ...
b*b = -32*a
and ...
a = -b*b/32

but also, recall: a = -(6*b + 1)/72
so we get ...
-b*b/32  = -(6*b + 1)/72

so ... multiply both sides by -8 gives ...
b*b/4 = (6*b +1)/9

now ... multiply both sides by 36 gives ...
9*b*b - 24*b - 4 = 0

'''
print( INFO_1 )
print( INFO_2 )
print( INFO_3 )
print( INFO_4 )


def a_from_b( b ):
    return -b*b/32


def roots( a, b, c ):
    return (-b -(b*b-4*a*c)**0.5)/(2*a), (-b +(b*b-4*a*c)**0.5)/(2*a)

b1, b2 = roots(9, -24, -4)
print( "b1 = {:.6f}, b2 = {:.6f}".format(b1, b2) )

a1 = a_from_b(b1)
a2 = a_from_b(b2)
print( "a1 = {:.6f}, a2 = {:.6f}".format(a1, a2) )

print( "Checking ..." )
print( 'y = {:.6f}*x**2 + {:.6f}*x + 2'.format(a1, b1) )
print( 'y = {:.6f}*x**2 + {:.6f}*x + 2'.format(a2, b2) )

print( 0, 2, "=? {:.2f}".format(f(a1,b1,0)) )
print( 12, 0, "=? {:.2f}".format(f(a1,b1,12)) )
       
print( 0, 2, "=? {:.2f}".format(f(a2,b2,0)) )
print( 12, 0, "=? {:.2f}".format(f(a2,b2,12)) )


print( "extreme is:", extreme(a1,b1), "at x =", "{:.6}".format(-b1/2/a1) )
print( "extreme is:", extreme(a2,b2), "at x =", "{:.6}".format(-b2/2/a2) )

input( "\nPress 'Enter' to continue/exit ... " )


# OUTPUT Oor running program ... #
'''
Points (0,2) and (12,0) are on the parabola with a max value of 10
find the equation(s) for the parabola(s).

Since 2 = a(0)**2 +b(0) + c,
c = 2

But also (12,0) is on parabola ... so ...
0 = 144*a + 12*b + 2
thus ...
-12*b = 144*a + 2
b = -(12*a + 1/6)
or ...
144*a = -12*b - 2
thus...
a = -(12*b + 2)/144 = -(6*b + 1)/72

But also max of 10 occurs for ...
10 = 2 - b*b/(4*a)
 8 = - b*b/(4*a)
thus ...
b*b = -32*a
and ...
a = -b*b/32

but also, recall: a = -(6*b + 1)/72
so we get ...
-b*b/32  = -(6*b + 1)/72

so ... multiply both sides by -8 gives ...
b*b/4 = (6*b +1)/9

now ... multiply both sides by 36 gives ...
9*b*b - 24*b - 4 = 0


b1 = -0.157379, b2 = 2.824045
a1 = -0.000774, a2 = -0.249226
Checking ...
y = -0.000774*x**2 + -0.157379*x + 2
y = -0.249226*x**2 + 2.824045*x + 2
0 2 =? 2.00
12 0 =? -0.00
0 2 =? 2.00
12 0 =? 0.00
extreme is: 10.0 at x = -101.666
extreme is: 10.0 at x = 5.66563

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on April 21, 2016, 09:12:32 AM
More differences ... 1st, 2nd, 3rd and 4th demo'd here ...

Code: [Select]
# differences_demo.py #

for loop in range(1, 5):

    print( "For: ", end = '' )

    if loop == 1:
        def f( t ):
            return 8 + 40*t
        print( "y = 8 + 40*t" )
    elif loop == 2:
        def f( t ):
            return 8 + 40*t - 32/2*t**2
        print( "y = 8 + 40*t - 32/2*t**2" )
    elif loop == 3:
        def f( t ):
            return 8 + 40*t - 32/2*t**2 + 10/2/3*t**3
        print( "y = 8 + 40*t - 32/2*t**2 + 10/2/3*t**3" )
    elif loop == 4:
        def f( t ):
            return 8 + 40*t - 32/2*t**2 + 10/2/3*t**3 - 5/2/3/4*t**4
        print( "y = 8 + 40*t - 32/2*t**2 + 10/2/3*t**3 - 5/2/3/4*t**4" )


    def getDiffs( lst ):
         diffs = []
         for i in range(1, len(lst)):
              diffs.append(lst[i] - lst[i-1])
         return diffs


    Lst  = []
    for t in range(-3, 6):
        Lst.append( f(t) )

    roundedLst = [ eval('{:.1f}'.format(i)) for i in Lst]
    print( '\nValues are: ', end = '' )
    print( roundedLst )

    def show( diffs ):
        nLst = [ '{:.1f}'.format( i ) for i in diffs ]
        print( '[' + ', '.join(nLst) + ']' )

    print( "\n1st differences are: ", end = '' )
    firstDiffs = getDiffs(Lst)
    show( firstDiffs )

    print( "\n2nd differences are: ", end = '' )
    secondDiffs = getDiffs(firstDiffs)
    show( secondDiffs )

    print( "\n3rd differences are: ", end = '' )
    thirdDiffs = getDiffs(secondDiffs)
    show( thirdDiffs )

    print( "\n4th differences are: ", end = '' )
    fourthDiffs = getDiffs(thirdDiffs)
    show( fourthDiffs )

    if loop < 4:
        msg = ' on to do loop ' + str(loop+1)
    else:
        msg = '/exit'

    input( "\nPress 'Enter' to continue{} ... ".format( msg ) )

    print( '-'*45, '\n' )
    print( '-'*45 )


# output from running program ... #
'''
For: y = 8 + 40*t

Values are: [-112.0, -72.0, -32.0, 8.0, 48.0, 88.0, 128.0, 168.0, 208.0]

1st differences are: [40.0, 40.0, 40.0, 40.0, 40.0, 40.0, 40.0, 40.0]

2nd differences are: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

3rd differences are: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

4th differences are: [0.0, 0.0, 0.0, 0.0, 0.0]

Press 'Enter' to continue on to do loop 2 ...
---------------------------------------------

---------------------------------------------
For: y = 8 + 40*t - 32/2*t**2

Values are: [-256.0, -136.0, -48.0, 8.0, 32.0, 24.0, -16.0, -88.0, -192.0]

1st differences are: [120.0, 88.0, 56.0, 24.0, -8.0, -40.0, -72.0, -104.0]

2nd differences are: [-32.0, -32.0, -32.0, -32.0, -32.0, -32.0, -32.0]

3rd differences are: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

4th differences are: [0.0, 0.0, 0.0, 0.0, 0.0]

Press 'Enter' to continue on to do loop 3 ...
---------------------------------------------

---------------------------------------------
For: y = 8 + 40*t - 32/2*t**2 + 10/2/3*t**3

Values are: [-301.0, -149.3, -49.7, 8.0, 33.7, 37.3, 29.0, 18.7, 16.3]

1st differences are: [151.7, 99.7, 57.7, 25.7, 3.7, -8.3, -10.3, -2.3]

2nd differences are: [-52.0, -42.0, -32.0, -22.0, -12.0, -2.0, 8.0]

3rd differences are: [10.0, 10.0, 10.0, 10.0, 10.0, 10.0]

4th differences are: [0.0, -0.0, -0.0, 0.0, 0.0]

Press 'Enter' to continue on to do loop 4 ...
---------------------------------------------

---------------------------------------------
For: y = 8 + 40*t - 32/2*t**2 + 10/2/3*t**3 + 5/2/3/4*t**4

Values are: [-284.1, -146.0, -49.5, 8.0, 33.9, 40.7, 45.9, 72.0, 146.5]

1st differences are: [138.1, 96.5, 57.5, 25.9, 6.8, 5.2, 26.1, 74.5]

2nd differences are: [-41.6, -39.1, -31.6, -19.1, -1.6, 20.9, 48.4]

3rd differences are: [2.5, 7.5, 12.5, 17.5, 22.5, 27.5]

4th differences are: [5.0, 5.0, 5.0, 5.0, 5.0]

Press 'Enter' to continue/exit ...
'''
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 03:59:50 PM
Review of quadratics ...

beginning with this simple form:

y = f(x) = a*x*x + b*x

(i.e. NOTE: here we have NO c term, i.e. c = 0),

If you are then asked to find roots, (zeros),
i.e. values for x that make f(x) equal to zero,
how to start?

Firstly, note that you can factor out .. one 'x' factor ...
in each term of the expression for f(x)


So ... Step 1:

Factoring out 'x' gives ...

f(x) = x*(a*x + b)

And if f(x) is to reach the value of 'zero' ...

what is x then?

1st root is 0

Because:
0*(a*0 + b) is 0

To find the 2nd root,
solve: (a*x + b) = 0

and that is true when x is -b/a

Now what is mid way between x = 0 and x = -b/a ?


Answer: -b/(2*a)

So axis of symmetry for this parabola runs parallel to the y-axis ...
and that line crosses the x-axis at x = -b/(2*a)



If 'a' is a positive value, the parabola 'opens up'

If 'a' is a negative value, then the parabola 'opens down'

If 'a' is equal to zero, we do NOT have a parabola. ( Recall the graph of y = b*x is a straight line through the origin, with slope here equal to 'b' )





Review of some algebra stuff ...

If x, c, b, a are numbers ...

can you expand:

c * (a + b) = ?

c * (a - b) = ?


a * (a + b) = ?

a * (a - b) = ?

(a + b) * (a + b) = ?

(a + b) * (a - b) = ?

(a - b) * (a - b) = ?

3*(x+2) * (x-2) = ?

-2*(x-3)*(x-2) = ?


If case 1: f(x) = 3*(x+2) * (x-2)
or case 2: f(x) = -2*(x-3) * (x-2)

describe the graph of the relations in the (expanded) expressions?

For each list:

roots (i.e. the 'zeros', the values of x that set f(x) to zero)

the vertex point

if the graph opens up or down

if it has a max or min value, and what that value is

sketch the graph using the 3 points 'supplied' by the above 'questions being answered'

Recall that the graph of a parabola is 'symmetric' ...
and that the 'axis of symmetry' for the above two 'quadratic' expressions (parabolas)
is a line parallel to the y axis the intersects the x axis mid-way between their roots.

Recall also that the point midway between any two x values, say x=a and x=b is simply:

(a+b)/2

i.e. the 'mean value'
i.e. the 'average value'
i.e. the 'middle value'



Big hint, substitute the 'mid point of the roots' back into the original expressions
for f(x) to find the value then ...
and that f(x) is the max or min value of that parabola.



Practical exam question (here we overlook the effect of air resistance):

If a ball is thrown upward and leaves the throwers hand with an upward velocity of 32 feet per second,
and gravity acts (downward) constantly at -32 feet per second per second,
what is ...

(a) the max height (above the ground) reached by the ball,
    if it leaves the throwers hand at 8 feet above the ground?

(b) how long will I take to reach that max height in seconds?

(c) how long will it take to get back to the 8 feet height from which it started?

(d) how long will it take from the start time till it hits the (level) ground (in seconds)?

(e) if the ball had a constant positive x direction velocity of
    10 feet per second, and the thrower was standing at x = 0
    when he threw the ball,
    what is the value of x where the ball hits the (level) ground?

    Hint:
    Use the relation for the vertical height (h): h = f(t)
    and note that ...

    f(t) - 8 = 32*t - (1/2)*(32)*t*t

    where h is the height in feet
    and t is the time in seconds

    Note: in the above, we assume 'ideal conditions' of NO air resistance effect on the ball,
    to get an easier first approximation to the  path it takes ...
    i.e. we assume the (vertical part of the) path is a perfect parabola and is described perfectly by:

    h = f(t)

    with,

    f(t) - 8 = 32*t - 16*t*t

    for t taking values 0 to its final time.


    Their is an easy way to solve the 'ball trajectory ' problem  ...
    and also a 'grunt work' way ...

    Using the 'easy way' is more fun and you are less likely to make
    calculation mistakes on the way to the final answer.




Answers to review of algebra stuff:

If c, b, a are numbers ...

Expanded:

c * (a + b) = c*a + c*b = a*c + b*c

c * (a - b) = c*a - c*b = a*c - b*c

a * (a + b) = a*a + a*b = a**2 + a*b

a * (a - b) = a*a - a*b = a**2 - a*b

(a + b) * (a + b) = a*a + a*b + b*a + b*b  = a**2 + 2*a*b + b**2

(a + b) * (a - b) = a*a - a*b + b*a - b*b  = a**2 - b**2

(a - b) * (a - b) = a*a - a*b - b*a + b*b  = a**2 - 2*a*b + b**2


Answer to case 1:

3*(x+2) * (x-2) = 3*(x**2 - 4) = 3*x**2 - 12

And graph of:  y = 3*x**2 - 12
is:

a parabola opening up with roots -2 and 2 and mid-point of roots is 0,
so parabola is symmetric about the y-axis with minimum value of -12,
i.e. vertex is at point (0,-12), since

 3*(0)**2 -12 = -12


Answer to case 2:

-2*(x-3)*(x-2) = -2*(x**2 - 5*x + 6) = -2*x**2 +10*x - 12

And graph of:  y = -2*(x-3)*(x-2)
is:

a parabola opening down with roots 2 and 3 and mid-point of roots is (2+3)/2 = 5/2,
so axis of symmetry is a line parallel to the y-axis that intersects the x-axis at
x = 5/2 = 2.5

Substituting in this (middle-roots-point) x = 5/2, we get:

-2*(5/2-3)*(5/2-2) = -2*(-1/2)*(1/2) = 1/2

So vertex is point (5/2, 1/2) 
i.e. (2.5, 0.5)

And maximum value is 1/2 i.e. 0.5



For the two cases above ... can you now sketch the graph using the 3 points 'supplied' ?



Using the hint re. the ball trajectory problem ...

i.e. using the relation:
h = f(t) with:
f(t) - 8 = 32*t -(1/2)*(32)*t*t

where h is the height in feet and t is the time in seconds ...

The easy way to do this is to ... 'do the problem from the perspective of having the x-axis
at the point where the ball leaves the throwers hand.'

There, we can let:

y = 32*t - 16*t*t = 16*t(2 - t)

which has easy to find roots (i.e. zeros at) : t=0, t=2 with mid-point t=1

And when t=1, then y = 32 - 16 = 16

But we started here at 8 feet up already,
so the max height reached by the ball is: (8+16) feet = 24 feet, and that height is reached
after 1 second.

Note that because of symmetry of ideal conditions assumed here,
the time to fall back down to the level of the throwers hand
is the same time, 1 second, for the ball to reach its max height here,
so after 2 seconds the ball is back at 8 feet above the ground ...
but now traveling down at 32 feet per second ...
with acceleration down of 32 feet per second per second.

So ... we can now solve for an other t,
here, t is the added time to reach the ground,
in a new relation: 

8 = 32*t + 16*t*t

Re-writing this we can set:              y = 16*t*t +32*t - 8

and solving this for y = 0 we get:       0 = 16*t*t +32*t - 8

Thus: (dividing everything by 8 we get): 0 = 2*t*t +4*t - 1

We can solve for the roots here easily by the ... '
completing the square' method:

1 = 2*t*t +4*t

1/2 = t**2 + 2*t = (t + 1)**2 - 1

Thus:
3/2 = (t+1)**2

and then ...
(t+1) = sqrt( 3/2 )
and thus:
t = sqrt(3/2) - 1

And this is the added time, about 0.225 seconds,
for the ball to hit the ground,
as it descends from the 8 foot height, to the ground.

So the total flight time for the ball is: (2 + 0.225) sec's


And if the ball had a constant horizontal velocity component
(in the positive x direction) of 10 feet per second,
after 2.225 sec's it would be 22.25 feet away
from the place from which it was thrown.


Can you now see how to do this, the easy way,
with the horizontal axis moved to the place from which the ball starts to move up,
and to do the whole problem in easier steps ...
using the symmetry conditions of the perfect parabola shaped curve assumed here ?
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 04:02:32 PM
More review ...

Expanded, what is:

(x + a)**2 = ?

(x - a)**2 = ?

(x + a)*(x - a) = ?


Factor these next:

(Hint, a difference of squares)

x**2 - a**2 = ?


(Hint, next two are 'perfect' squares)

x**2 - 2*a*x + a**2 = ?

x**2 + 2*a*x + a**2 = ?



2*x**2 - 3*x + 1 = ?

3*x**2 + 4*x + 1 = ?

3*x**2 - x - 2 = ?

10*x**2 + 11*x - 6 = ?


Answers to last 4 ...

Factors are:

2*x**2 - 3*x + 1   = (2*x - 1)*(x - 1)

3*x**2 + 4*x + 1   = (3*x + 1)*(x + 1)

3*x**2 - x - 2     = (3*x + 2)*(x - 1)

10*x**2 + 11*x - 6 = (5*x - 2)*(2*x + 3)




Describe how these two parabolas compare:
part (a)
1st:  y = 2*(x-3)*(x+6)

2nd:  y = 2*(x-6)*(x+3)

part (b): Prove it.

Hint:
One way might be to convert each to 'vertex' form
So ...
firstly expand each,
then convert each to  vertex form and compare vertices
and note that both have the same distance (span) between each pair of roots
and note shift in roots and shift in vertices is same ...
so 3 corresponding points are each shifted the same ...

so one parabola is exactly the same as the other, excepted shifted ... how much ?

To go from 1st, to 2nd, just shift each point  (Right or Left?) (and how much?)



Answers to 'advanced' question above:
(The easiest way to do this is ... )

(It is easy to see that) the '1st' parabola has roots (i.e. zero's) at:
at x = -6 and x = 3 and the mid-point is (-6+3)/2 = -3/2 (i.e. -1.5)

i.e. the axis of symmetry for the first parabola,
is a line parallel to the y-axis that intersects the x-axis at x = -3/2

And substituting in (-3/2) for x we get:

2*(-3/2-3)*(-3/2+6)
= 2*(-9/2)*(9/2)
= -81/2

So vertex point here is at:  (-3/2, -81/2)

The 2nd parabola has roots -3 and 6, and mid-point 3/2
and all these values are the same as the corresponding first parabola values
shifted 3 units to the right.

Now substituting in 3/2 for x we get:

2*(3/2-6)*(3/2+3) = 2*(-9/2)*(9/2) = -81/2

So vertex point here is at:  (3/2, -81/2)

And this point also is the same as the vertex point
of the 1st parabola shifted 3 units to the right

So since 3 unique points determine a unique parabola,
and the 2nd 3 points are all the same as the 1st 3 unique points
each shifted 3 units to the right ...
the 2nd parabola is the very same as the 1st parabola
but every point on the 1st is shifted 3 units to the right
to get the graph of the 2nd parabola.

q.e.d.




SOME ... Grade 9 review stuff:

(Note that I'm using the Python notation for exponentiation,
 i.e. 2**3 means 2*2*2, i.e. 3 factors of 2.)


3*x**2 + 4*x + 5
- x**2 + 3*x - 7
= ?


If a car starts off at time t0 with an initial velocity of 44 mph,
and travels at that constant velocity due west for 1 and 1/2 hours,
how far west will it be from the starting point it had at time t0?


If a fenced field takes the shape of a rectangle with opposite sides of length (2*x + 3) and
(3*x + 1) what is the perimeter and area if x is any positive real number?

If the sides are scaled up to be each side longer by a factor of 2,
how will that change the new perimeter and area?


What is another way we write: (x**n)**m = ?
where x is any non-zero real number and n and m are any integer numbers ... ?



Also, what is another way we write: (x**n)/(x**m) = ?


Re-express adding and multiplying these two decimal numbers, a and b if
a =  32.1 and b = 12.3 using powers of 10 notation,

i.e. for example:  a = 3*10**1 + 2*10**0 + 1*10**(-1)


and thus show that we have been using many properties of numbers,
like the commutative law of adding and multiplying ...
the distributive law, and the associative law also.



Answers to SOME Grade 9 review questions:


3*x**2 + 4*x + 5
- x**2 + 3*x - 7
=
2*x**2 + 7*x - 2


If a car starts off at time t0 with an initial
velocity of 44 mph due west and travels at that constant velocity for 1 and 1/2 hours,
how far west will it be from the starting point it had at time t0?

Answer:

44*(1+1/2)
i.e. it will be 66 miles due west of the point it started from at time t0.


If a fenced field takes the shape of a rectangle with opposite sides of length (2*x + 3) and (3*x + 1),
what is the perimeter and area if x is any positive real number?

Answer:

Perimeter is:
2*((2*x + 3) + (3*x + 1)) = 10*x + 8

Area is:
(2*x + 3) * (3*x + 1) = 6*x**2 + 11*x + 3

If the sides are scaled up to be each side longer by a factor of 2,
how will that change the new perimeter and area?

Answer:
The perimeter is doubled (times 2 - why?),
and the area is times 2**2, (times 4 - why?)
So ...
New perimeter:  20*x + 16
New area:       4*(6*x**2 + 11*x + 3) = 24*x**2 + 44*x +12


What is another way we write: (x**n)**m = ?
where x is any non-zero real number and n and m are any integer numbers ...


Answer:  (x**n)**m  =  x**(n * m)


Also, what is another way we write: (x**n)/(x**m) = ?

Answer:  (x**n)/(x**m)  =  x**(n - m)


Re-express adding and multiplying these two decimal numbers, a and b if

a =  32.1 and b = 12.3 using powers of 10 notation,

i.e. for example a =
3*10**1 + 2*10**0 + 1*10**(-1)

and thus show that we have been using many properties of numbers,
like the commutative law of adding and multiplying ...
the distributive law, and the associative law also ...

Answer:

a + b = b + a =
32.1 + 12.3 =
44.4

i.e.

3*10**1 + 2*10**0 + 1*10**(-1)

+

1*10**1 + 2*10**0 + 3*10**(-1)

=

4*10**1 + 4*10**0 + 4*10**(-1)

= 44.4


Also ...

a * b = b * a = 32.1 * 12.3
=
     9.63 +
    64.2 +
   321
=
   394.83

i.e.

( 3*10**1 + 2*10**0 + 1*10**(-1) )

*

( 1*10**1 + 2*10**0 + 3*10**(-1) )

=

9*10**0 + 6*10**(-1) + 3*10**(-2)

+

6*10**1 + 4*10**0 + 2*10**(-1)

+

3*10**2 + 2*10**1 + 1*10**0

=

394.83

=

3*10**2 +
9*10**1 +
4*10**0 +
8*10**(-1) +
3*10**(-2)




Did you notice ...
that in the multiplication above, we had this partial result ?

9 + 4 + 1 = 14

And that 14 is also:  1 * 10**1 + 4

Thus, when we 'carry' ...
what we are really doing is 'rewriting as a sum of powers of 10'

For example 14, is here rewritten as:  1*10**1 + 4*10**0

then we can collect (sum up) all the terms with powers of 10**0
and collect all the terms with powers of 10**1,
etc ... re-writing any sum > 9 as a sum of its parts.




Were you able to understand ok the above little review of algebra and exponents?




Review of ...

Shifting a graph so many units to the right (or to the left left) ...
(below ... see demo of graph shifted right 3 units):


for:  y = m*x + b
if:   y = 0 then ... x = -b/m

If x is replaced by w-3, then ...
y = m*w - 3*m + b
And if then y = 0, we get ... w = 3 - b/m

Thus this line has same slope (m)
but intersects the w-axis 3 units to the right of w = -b/m



Now consider this quadratic relation:

y = a*x**2 + b*x + c

If x replaced by w-3

Lot's of algebra here ... to show the effect of replacing x with (w - 3) ...


y = a*x**2 + b*x + c

if y = 0, then the roots/zeros are ...

x = (-b +- sqrt(b**2 - 4*a*c))/(2*a)


BUT  ... if x is replaced by w - 3

then ...

y = a*(w-3)**2 + b(w-3) + c
  = a*(w**2 -6*w + 9) + b*w - 3*b + c
  = a*w**2 + (b - 6*a)*w  + 9*a - 3*b + c

if y = 0;
x = ( -(b-6*a) +- sqrt( (b-6*a)**2 - 4*a*(9*a -3*b + c) ) )/(2*a)
  = ( -(b-6*a) +- sqrt( b**2 - 12a*b + 36*a**2 - 36*a**2 + 12*a*b -4*a*c ) )/(2*a)
  = ( -(b-6*a) +- sqrt( b**2 - 4*a*c) ) / (2*a)
  = ( -b +-sqrt( b**2 - 4*a*c) ) / (2*a) + 6*a/(2*a)
  = ( -b +-sqrt( b**2 - 4*a*c) ) / (2*a) + 3

So ... roots are the same values... each shifted 3 units to the right ...
and extreme values of y occur at:
x = -b/(2*a) 
and w at:
w =  -b/(2*a) + 3
and are:

a*(b**2/(4*a**2) - b**2/(2*a) + c
=
-b**2/(4*a) + c

and ...

a*( -b/(2*a) + 3 )**2 + (b - 6*a)*(-b/(2*a) + 3) + 9*a - 3*b + c
=
a*( b**2/(4*a**2) - 3*b/a + 9) + (-b**2/(2*a) + 3*b + 3*b - 18*a + 9*a - 3*b + c
=
b**2/(4*a) - 3*b + 9*a - b**2/(2*a) + 3*b -9*a + c
=
-b**2/(4*a) + c

the same y value ...
with graph on the 'w-axis' shifted 3 units to the right wrt graph on the x-axis

So ... curves are same (since each have same 3 points shifted the same.)

THUS ...
2nd parabola is same as 1st,
except each point is shifted 3 units to the right with respect to (wrt) the 1st parabola.

q.e.d
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 04:06:58 PM
Looking ahead ...

when finished with quadratics to start trigonometry with its:

sine (sin),
cosine (cos),
tangent (tan) functions and their recipricals ...

cosecant (csc),
secant (sec),
cotangent (cot) ?


http://www.watchknowlearn.org/Video.aspx?VideoID=37485&CategoryID=11359

If theta = a, is the angle measured cc (counter clockwise) from the x-axis,
then  for points (x,y) on a circle with radius r,

sin(theta) = y/r
cos(theta) = x/r

tan(theta) = y/x = sin(theta)/cos(theta)

Note that tan(theta) is also rise/run

and that is the slope of the line that passes through the origin and point (x,y)
on the circle with radius r

The reciprocal relationships are:
csc(theta) = r/y = 1/sin(theta)

sec(theta) = r/x = 1/cos(theta)

cot(theta) = x/y = 1/tan(theta) = csc(theta)/sec(theta)

wrt this next right angled triangle ... with acute angle a ...
and sides: x, y and r ...

            (x,y)
            /|
           / |
        r /  |
         /   | y
        /    |
       /a   |
       ===
(0,0)  x    (x,0)

sin(a) = opposite / hypotenuse = y/r

cos(a) = adjacent / hypotenuse = x/r

tan(a) = opposite / adjacent   = y/x  (i.e. same as the slope, i.e. the rise/run)




Finding roots/(zeros) by ...

Completing the square method ...


Recall:  (a + b)**2 = a**2 + 2*a*b + b**2


         (x + a)**2 = x**2 + 2*a*x + a**2


So going backwards, if you start with only:

x**2 + k*x ...  ?

And then ... you want to eventually have:

(x + k/2)**2 + ?

So what do you need to add and then subtract to preserve equality ?

Recall that here you are starting with only:
x**2 + k*x + d



For example:
x**2 + 3*x - 5


1st step:

(x + 3/2)**2

Need to subtract what?  ( Hint: (3/2)**2 = ? )



9/4


Yes ... 9/4 ... and recall:  x**2 means x raised to exponent 2

1st step:

(x + 3/2)**2

need to subtract what?
9/4

Why ?

Because (3/2)**2 is 9/4

So to keep equality we need to now then subtract 9/4

Recall that here you are starting with only:  x**2 + k*x + d

For example:  x**2 + 3*x - 5  =  (x+3/2)**2 - 9/4 - 5

What is the next / last step?


Last step is ...

Recall that we are finding zero's / roots here by completing the square method,
so we had to set the left hand side to zero (0) ...

So ... here we start with:  0 = x**2 + k*x + d

For example:  0 = x**2 + 3*x - 5
                = (x+3/2)**2 - 9/4 -5

Thus ...

(x+3/2)**2  = 9/4 + 5 = 29/4

So taking square root of each side we have ...

(x+3/2) = +- sqrt(29)/2


So x = ?


x = -3/2 + sqrt(29)/2

and, the 2nd root/zero is at:

x = -3/2 - sqrt(29)/2


To plot these two roots you could use your calculator to firstly find: (29)**(1/2)

Or guesstimate the root as between 5 and 6, and then ...
keep getting closer guesses of a number that squared is 29



sqrt(29) is about 5.4

Recall computer jargon for square root function is sqrt( some_number )
i.e Same as Python: (some_number)**(1/2)

So now find estimate to 1 decimal place for  both roots (zeros)


x = -3/2 + 5.4/2 =  2.4/2 = 1.2

and 2nd root/zero is at:

x = -3/2 - 5.4/2 =  -8.4/2 = -4.2


Now, for extra marks, sub these back into the original, 
y = f(x) = x**2 + 3*x - 5

and see if y is zero for these x's



Here is where a few lines of Python code could come in handy:


# file name: find_func_value_at_x.py #

def f( x ):
   return x**2+3*x-5

# then put in values for x #

x = 1.2

print( f(x) )

x = -4.2

print( f(x) )



I get 0.039999...
for each which is close enough to to zero here since we only carried 1 decimal place
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 04:11:13 PM
Ok... try this also ...

Find roots, by completing the square method, for ...

y = x**2 - 3*x - 1

First step is ?



If ...
0 = x**2 - 3*x - 1

then ...
(x-3/2)**2  - 9/4 -1 = 0

So ...
(x-3/2)**2  =  13/4

and thus ...
(x-3/2) = +- sqrt(13)/2
or ...
x = 3/2 +- sqrt(13)/2

Note that (3.61)**2 is about 13

so ...
x = -.61/2 = - 0.305

and 2nd root is:
x = 6.61/2 = 3.305





Let's try a 3rd ...

By completing the square method ...

find roots for:  y = 4*x**2 - 3*x - 1


But firstly notice that this can be factored into:

y = (4*x + 1)*(x - 1)

so we can esily see here, that the roots (the values of x that make y = 0) are ?


Look at each factor ... what value of x will make a factor evaluate to 0 ?


Hint:  If x is 1, x - 1 is zero

Can you solve this also?

(4*x + 1) = 0
x = ?



-1/4


Can you see now that the roots are:  -1/4 and 1

Thus for:  y = (4*x + 1)*(x - 1)

the roots (the values of x that make y = 0) are: x = -1/4 and x = 1

So we easily know here what the roots are ...


Now ... back to completing the square method.

By completing the square method ... find roots for: y = 4*x**2 - 3*x - 1


First step is ?

Let ... y = 0, then ... (factoring out the 4, and putting it out-front) ...
0 = 4*(x**2 - 3/4*x) - 1

Next step ?


Notice that:  (x**2 - 3/4*x) = (x - 3/8)**2 - 9/64

So 4 times ALL that is:

4*(x - 3/8)**2 - 4*9/64 = 4*(x - 3/8)**2 - 9/16

So next step ?


We need to deal with the - 1


So ... for 0 = 4*(x - 3/8)**2 - 9/16  - 1

Then ?


4*(x - 3/8)**2 = 9/16 + 1  = 25/16

Then dividing both sides by 4 ... we get:

(x - 3/8)**2 = 25/64


Then ...
(x - 3/8) = +- 5/8


Recall I am using +- to plus or minus to mean:  'plus or minus'

So roots are:

3/8 + 5/8 = 8/8 = 1
and ...
3/8 - 5/8 = -2/8 = -1/4



Recall that both -a and +a ...
when each are squared are both a positive value equal to a**2


Can you see now that ...
the goal of our completing the square steps was to led us to this:

(x - 3/8)**2 = 25/64

Then, taking square roots of both sides of that equation gave us:

(x - 3/8) = +- 5/8

and thus we have two cases to solve,

the case of RHS  (right hand side) being equal to + 5/8

And case of RHS being - 5/8

Does that help?


I chose the above example with an a = 4 coefficient, (not equal to 1),
in the quadratic ...

and also example was chosen so that ...
we knew the correct roots in advance by seeing it had 2 easy factors.




As you can see, keeping signs correct in all algebra manipulations is very important.
Note!!!

The goal of our completing the square steps was to get us to this:


(x - 3/8)**2 = 25/64

Then we can take square roots of both sides of that equation to solve and find both roots.



Note that we get the general formula for the roots of any quadratic:

y = f(x) = a*x**2 + b*x + c

by using the 'Completing the Square' method ...

the roots are:  (-b +- sqrt(b**2 - 4*a*c)) / (2*a)

Note the +- above means 'plus or minus' ...
so we have two cases to solve to find each of the 2 roots.



The value inside the sqrt function is called the 'discriminant'

(b**2 - 4*a*c)


if the discriminant evaluates to zero we say ...
we have 'two equal roots both equal to the same value'...

and also note that this implies that the graph of the quadratic
just ***touches*** the x-axis (not crossing it)

If the discriminant is positive,
we have 2 *real* roots

If the discriminant is negative,
we have 2 *imaginary* roots (i.e. NO real roots)

+- means ... we ***have*** two cases to solve to find the roots.


Recall ...
Solving to find roots means ...

'Find values of x for which y becomes zero'

Recall also that ...

y = 0

is also the equation of the x-axis line.



For derivation of ...

'finding roots by completing the square method' ...

see this next link:

http://developers-heaven.net/forum/index.php/topic,2624.msg3189.html#msg3189



This is a good example of careful algebraic manipulations.

See if you can follow this 'general case' where we are given just a, b, c parameters
in y = f(x)

y = a*x**2 + b*x + c

We need to find the general formula for the two roots.



Also ... it's a good idea to make up some cases with KNOWN roots ...

to (ease your) practice in finding the roots by 'completing the square method.'


For example:        y = (2*x - 1)*(x + 1)
which expands to:   y = 2*x**2 + x - 1
and you there can easily see that the roots are: -1 and 1/2


and then ...

using the completing the square method to find the roots in the expanded form,

since you already know what they should be,

this will help you to know if your algebraic manipulations were all ok :)


For example:       y = (2*x - 1)*(x + 1)
which expands to:  y = 2*x**2 + x - 1

and you can easily see that the roots are: -1 and 1/2

since if (x + 1) = 0, then x = -1
and if (2*x - 1) = 0, then x = 1/2




Can you do all the steps to complete the square to yield these two values of the roots?


Finding roots by 'completing the square' method of: y = 2*x**2 + x - 1

1st step we factor out the 2 from the 1st two terms ... so:

2*x**2 + x - 1 = 2*(x**2 + 1/2*x) - 1 = 2*(x**2 + 1/2*x + 1/16) - 2*(1/16) - 1


Then ... if y is 0:
2*(x**2 + 1/2*x + 1/16)  = 2*(1/16) + 1

Simplifying we get:
2*(x + 1/4)**2  = 2*(1/16) + 1 = 9/8

Then dividing both sides by 2 and we get:

(x + 1/4)**2  = 2*(1/16) + 1 = 9/16

Then taking square roots of both sides we can find that the roots are ?


1st root is: -1/4 - 3/4 = -1
2nd root is: -1/4 + 3/4 = 1/2

q.e.d.
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 04:13:43 PM
Try this ...
Expand firstly, then (re-)find both roots by the completing the square method:

y = (1 - x)*(2 + 3*x)

Firstly, and so that we can see if we are keeping on the right track, by easy inspection,
the two roots are: 1 and -2/3
since factor (1 - x) is zero if x = 1
and factor (2 + 3*x) = 0 if x = -2/3


Then expanding we get: y = (1 - x)*(2 + 3*x)
                         = 2 + x - 3*x**2
                         = -3*(x**2 - 1/3*x) + 2
                         = -3*((x - 1/6)**2 - 1/36) +2
                         = -3*(x-1/6)**2 + 1/12 + 2

So if y = 0, then we have: 3*(x-1/6)**2 = 2 + 1/12 = - 25/12

And dividing both sides by 3 implies: (x-1/6)**2 = 25/36

So taking square root of both sides we get: (x-1/6) = +- (5/6)

Recall that by this +- ... I mean to say 'plus or minus'

Thus roots are:
1/6 + 5/6 = 1
and:
1/6 - 5/6 = -4/6 = -2/3



Looking back...

Can you also see here that 1/6 is the mid point of these roots?

Note:  (-2/3 + 3/3)/2 = 1/6

(Also, If you add them together, the +- parts add to zero, and 1/2 of 2*(1/6) is just 1/6, the mid-point.)


So recalling that the graph of a parabola is symmetric,
the extreme value for y is reached when we sub in x = 1/6,
the midpoint of the roots.


So, wrt the form, y = a*(x - h)**2 + k,
we already here know that a = -3 and that h = 1/6, so what is k, the extreme value?


Going back to original expression and subbing in for x the value x = 1/6,
the mid-point of the roots, we find that:

y = (1-1/6)*(2+3*(1/6))
  = (5/6)*(2+1/2)
  = (5/6)*5/2
  = 25/12 the same thing as
    (2 + 1/12) or about 2.1, if we need to plot an estimated value, to one decimal place.

Thus, since a = -3, and this is negative, the parabola opens down ...
and so the extreme value, k = 25/12 is a maximum.




Looking forward to the general formula for roots (zeros,
i.e. values of x that make y = 0) of a quadratic ...

If you start with general form: y = a*x**2 + b*x + c

and there, (very carefully), apply the 'completing the square' method ...

(see web link, linked above) ...

you will find that the roots are:

(-b +- sqrt(b**2 - 4*a*c))/(2*a)

where again I am using the +- notation above to indicate 'plus or minus',
(i.e to find both roots we need both cases),

and sqrt(...) means ... take the square root of the value inside the brackets.



Recall ... the value:

b*b - 4*a*c,

is called the 'discriminant' (D).

Can you see here that the mid point of the roots is just:

-b/(2*a)

and that this is the value of x where y reaches an 'extreme value'?

(Recall that the +- parts add to zero.)


Note also that if D = 0, the roots are 'both equal'
(i.e. only one value for roots and that the graph just touches the x-axis at x = -b/(2*a)

Note also the case where D < 0, i.e. D is negative.

What does this imply?


This is the case where a, b, c are such that the graph of the parabola

does NOT touch or cross the x-axis,

and so is the case where there are NO *real* roots,

i.e. we say, in this case where D < 0
that the roots are paired and both 'imaginary',
i.e, the roots involve the use of an (imagined) value ... the imagined value of the sqrt(-1)

Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 05:28:49 PM
How are you progressing in math these days?

Are you seeing the 'big picture' re. quadratic relations?


wrt the general form: y = f(x) = a*x*x + b*x + c


1) the graph is a parabola ... And the graph is symmetric about about the line:

   x = -b/(2*a)

2) it opens up with a min extreme value if a > 0, i.e. if a is pos.

3) it opens down with a max extreme value if a < 0, i.e. if a is neg.

(Recall that here, a != 0, i.e. a is NOT zero, since if a is zero, we no longer have an x**2 term.)

4) it has a pair of roots (zeros) about the axis of sym-metry, the line:

   x = -b/(2*a)

   And the two roots here are given by:   (-b +- sqrt(b*b - 4*a*c))/(2*a)

   Or ... re. the discriminant, D = (b*b - 4*a*c),

   in case 1, we take the pos. sqrt(D), so y = 0 at x = (-b + sqrt(D))/(2*a)

   in case 2, we use the neg. sqrt(D), so also y = 0 at x = (-b - sqrt(D))/(2*a)

   Note! If D = 0, then we say that we have just one ... (or 'two equal roots') ...
i.e. the graph of the quadratic just 'touches' the x-axis.
   If D > 0, then we have two *real* roots,
   If D < 0, we say that roots are 'imaginary',
   i.e. the roots in the case where D is neg. involve the use of the 'imagined number': sqrt(-1)


Note that we obtained this general formula for the roots of:   y = a*x*x + b*c + c

by using the 'completing the square' method.


So now, via this general formula, and understanding the significance of D, the discriminant,
we can quickly just sub into the formula and find the roots,
and do not need to use factoring method, or completing the square method,
which were steps on the way to understanding the quadratic's (paired) roots
and how we derive the general formula for the roots.


Note in particular, that if D evaluates to zero,
then that is the case of there being only one root, (and the graph just touches the x-axis),
i.e., the case where y = 0 ONLY at this one value of x = ?

Hint: what is equation for axis of symmetry?
x = ?

Answer:
x = -b/(2*a) is equation of axis of symmetry for all parabolas and
so this x, is also the one value of x if a parabola's a, b, c's are such that
the graph only touches the line.

You can also see this easily from setting D = 0 in the general formula.

Then roots are:  (-b +- sqrt(0))/(2*a) = -b/(2*a)

Can you now see that this all makes sense, since the parabola is symmetric about:  x = -b/(2*a)

So if the (a,b,c's of a) parabola (are such that it) just touches the x-axis at only one place,
then it must be there, at x = -b/(2*a)



Ok ... let's now ...

Start back at the simplest example of a quadratic relation:

What is graph of:

y = x*x

Then ask:

What changes if we graph:

y = a*x*x where a is pos or neg and the absolute value of a gets bigger than one ... or ... gets smaller than one ?


How does the graph change if we graph:

y = a*x*x + k

?


Then, finally, how does the graph change if we graph:

y = a*(x - h)**2 + k

?


Note that the final form above is the ... 'Vertex form' of a quadratic with the vertex point being:  (h, k)

i.e. the extreme value of y = k occurs here at x = h

and is a max if a < 0

or is a min value if a > 0


Note that if a < 0, then for values of x different from h, we are always subtracting a value from k ... So k is the max

And if a > 0, then for values of x different from h, we are always adding a value to k ... So k is the min value.

Note that the 'extreme' value of:       y = k
in this vertex form, always occurs at:  x = h

The only other form you were given was the root form, where the roots are r1 and r2:  y = a*(x - r1)*(x - r2)

And you can expand this now and find ...

y = a(x*x -(r1+r2)*x + r1*r2)
  = a*x*x - a*(r1+r2)*x + a*r1*r2

And comparing the relevant coefficients here with the general equation that uses
parameters of a, b, c for a quadratic, we can see that:

a is same ...
and ...

b = -a*(r1+r2)

i.e.
(r1+r2)/2 = -b/(2*a)

which we knew already from symmetry, that the extreme value for y occurs at x = mid point of roots,

and finally ... (comparing coefficients)

c = ?
here c = a*r1*r2

Or alternately:
r1*r2 = c/a

and ...
(r1+r2) = -b/a



So ... back now to practicing completing the square method.

Try this:

y = 3*(2-x)*(1+5*x)

We know here (in advance by inspection) that the roots are: 2 and -1/5 since a factor becomes zero with x taking either one of these values.

Firstly, expand ...

then see what you can do?  Can you expand it?

Recall that:  3*(a + b) = 3*a + 3*b (distributive law)

And so also we get:
(a + b) * (c + d) =
a*c + a*d + b*c + b*d

Hint: when you expand it,

3*(2-x)*(1+5*x)

in your first step ...
leave the times 3 factor out front the brackets, where, inside the brackets,
you show the expansion of the other two factors.

So 1st step:                y = 3*(2-x)*(1+5*x)

Firstly, expanding we get:  y = 3*(2 + 9*x - 5*x*x)


Note: we were probably here starting with:  y = 6 + 27*x - 15*x*x

and then our 1st step might be,
(after dividing each term by -3 and rearranging with -3 factor out front all):

y = -3*(5*x*x -9*x -2)
  = -3*(5*x*x -9*x) + 6


Now starting with :  y = -3*(5*x*x -9*x) + 6

we might next divide the 5 and 9 by 5 and put the 5 factor out front,
so ...

y = -15*(x*x - 9/5*x) + 6


Now what is (1/2 of (-9/5)) squared?

thus:  y = -15*(x*x - 9/5*x + 81/100 - 81/100) + 6

         = -15*(x - 9/10)**2 + 15*81/100 + 6

And if y is 0, then dviding both sides by -15 gives ...

0 = (x - 9/10)**2 - 81/100 - 6/15

Or ...

(x - 9/10)**2 = 81/100 + 6/15

              = (243 + 120)/300
              = 363/300
              = 121/100

So taking square roots of both sides we get:

x - 9/10 = +- 11/10

Thus ...

y is zero if ...
x = 9/10 + 11/10 = 2
or ...
x =9/10 -11/10= -1/5

And that is probably the hardest completing the square example you are ever likely to get on a test ...

The trick here, on a test, if you need to show steps to completing square method,
would be to firstly use the general formula to quickly find the roots ...

and then, knowing what your final values should be,
that can help you see if all your algebraic manipulating is on track :)


But can you see now ... why it is a good idea to do all this grunt work, (once),
to develop the general formula for the roots of a quadratic,
by the 'completing the square method' ...

then ...

all we ever need to do after ... is to sub the values of a, b, c into the formula, to find the roots?



What do we mean when we say a number is itself squared?

Recall that for a square room, with sides 4 ft by 4 ft ... the area is 16 sq. ft.

Or the other way around ...
if a perfectly square room had area 16 square feet, what is the length of each side?

Answer:  Each side is 4 ft. long.

Recall I am using Python exponent notation of **  ... so ... by using ... 2**3
I mean to indicate:  3 factors of 2

So 4**4 = ?
Four factors of 4 = ?
4*4*4*4 = ?
Same as : 16 * 16
Same as : 2**8 = 256

Recall 4 = 2**2
and so 4**4 = (2**2)**4 = 2**(2*4) = 2**8 = 256


We maybe need to do more practice with exponents ?

What is 3**2 ?
What is 4**2 ?

What is 5**2 ?

What is sqrt(81) ?

What is sqrt(144) ?

What is sqrt(49) ?


Recall ...
I am NOT using 'x' to indicate times ...
since we are using 'x' as an independent variable in all our functions here like y = f(x)

And the Python language ... and all standard computer programming languages ...
they pretty much all use calculator notation to indicate multiplication by using the star. *, i.e. the asterisk symbol.


Note also ... that in all computer programs (and calculators) you can NOT code:  x = 3(4+5)
you must instead, always code like this:  x = 3*(4+5)


So now memorize the general formula to find the roots of any quadratic ...

For:  y = f(x) = a*x**2 + b*x + c
Roots are:  (-b +- sqrt(b*b-4*a*c))/(2*a)


Note: we need to take both + and - cases to find both roots if discriminate D = (b**2 - 4*a*c) is not zero.



NOW ... practice more on completing the square method on some easier equations that you can make yourself by using root form:

y = a*(x-r1)*(x-r2)

and sub in easy values for roots r1, r2 and also for a.

Then expand and practice completing the square method of finding the roots from that starting point ... already knowing what the roots each are :)

If you get stuck ...I'm only a quick e-mail away :)

The Lord knows all about perfect squares since He created it all perfect.

Bless the Lord oh my soul, and all that is in me, bless His Holy Name!!!

Baruch HaShem!!!
(Bless His Name)

Praise the Lord!!! ... He has promised to never leave or forsake those who place their trust in Him..

Recall also His encouraging words to these ones,  that He speaks at the end of Matthew's Gospel ...

ALL power/authority is given to me in heaven and in earth ... go ... I am with you alway, (even) unto the end of the world.

(Matthew 28:16-20)

16 Then the eleven disciples went away into Galilee, into a mountain where Jesus had appointed them.

17 And when they saw him, they worshipped him: but some doubted.

18 And Jesus came and spake unto them, saying, All power is given unto me in heaven and in earth.

19 Go ye therefore, and teach all nations, baptizing them in the name of the Father, and of the Son, and of the Holy Ghost:

20 Teaching them to observe all things whatsoever I have commanded you: and, lo, I am with you always, even unto the end of the world. Amen.


And recall:

But of him are ye in Christ Jesus, who of God is made unto us wisdom, and righteousness, and sanctification, and redemption. (1 Cor. 1:30)

And ...

For he (God) hath made him (Jesus to be) sin for us, who knew no sin; that we might be made the righteousness of God in him (in Jesus.) (2 Cor. 5:21)
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 05:30:52 PM
Another grade 9 type problem concerns ...

what happens to the graph of the linear relation y = m *x if you replace it by the graph of,

in case 1),
y = m*x + b

or in case 2,
y  = m*(x - h)


How is the line moved in each case wrt
(with respect to) the base case of the graph of the linear relationship: y = m*x

?

If you need help to see what happens,
plot ALL the simple cases where you take the value of m as 1
and the value of  b as, say 2, or -2, and then the value of h as, say 3, or -3

?


We need to 'see' what happens to the 'line' here firstly ...


Then we can more easily see what happens to the graph of the quadratic relationship:

y = a*x*x

in case 1), we replace by graph of:
y = a*x*x + k

and in case 2, we replace by graph of:
y = a*(x - h)*(x - h)


How is the parabola moved, in each case, wrt to the base case of the graph of the parabola:

y = a*x**2

?



Please be specific ...

You need to fill in all the ? mark places with an answer:


If ?  > 0,
then ? is moved ? units to  ?

Or if ? < 0,
then ? is moved ? units to ?



Filling in all the (?) places with an answer:

With respect to base cases (where h = 0 and b = k and both here are 0):

If (h) > 0,
then (each point on the line) is moved (h) units to (right) and the same for the parabola.

If (h) < 0,
then (each point on the line) is moved (h) units to (left) and the same for the parabola.


If (b) > 0,
then (each point on the line) is moved (b) units (up) and the same for the parabola if (b=k) > 0

If (b) < 0,
then (each point on the line) is moved (b) units (down) and the same for the parabola if (b=k) < 0


Questions (grade 9 review) re. point(s) of intersection (if any):

Line 1:
2*x + 3*y + 4 = 0

Line 2:
3*x - 2*y - 1 = 0

Question 1: Are the lines the same? Prove your answer.
(Note: if there exists even one point on one line that is not on the other line, are they the same lines?)

Question 2: Are the lines parallel? (Again prove your answer.)

Question 3: Do they have any common points, if so how many?
(How might you prove your answer? If you'd like a hint ... see below.)
What other relationship might you mention regarding/comparing these 'lines'?

Finally, sketch a graph of the above lines that helps to illustrate your answers above, using the x-y rectangular co-ordinate system.



Answers to...

Questions re. point(s) of intersection (if any):

Line 1:
2*x + 3*y + 4 = 0

Line 2:
3*x - 2*y - 1 = 0

Question 1 (answered): The lines are NOT the same ...
since when y = 0, for the first line, x = -4/2 = -2, but on the second line, x = 1/3. 
And since even one point is different, the lines are NOT the same.



Question 2 (answered): The lines are not parallel since they have different slopes. 
Line 1 has slope -2/3 while line 2 has slope 3/2

Question 3:
Since the lines are different (see 1st answer above) and have different slopes
(see the 2nd answer above)
and they are both 'straight lines'
i.e. the slope is at every point on each line the same continuous slope that it had at any
'previous' point on that respective line, therefore the 2 different lines must intersect
at one (and ONLY at one) point of intersection.


If we multiple both sides of linear relation 1 by 3 ...
and also multiply both sides of relation 2 by 2, we get:

Line 1:
6*x + 9*y + 12 = 0

Line 2:
6*x - 4*y - 2 = 0

Then subtracting, (since 6*x - 6*x = 0)

13*y + 14 = 0
Thus, y = -14/13
And for this y subbed into line 1:

2*x + 3*(-14/13) + 4 = 0

Thus ...
2*x = 3*(14/13) - 4
And ...
 x = 3*7/13 - 2
    = 21/13 - 26/13
    = -5/13

And subbed into line 2:

3*x - 2*(-14/13) - 1 = 0
Thus ...
3*x = -28/13 +13/13
       = -15/13
    x = -5/13

Thus the 2 different lines intersect at, and only at, point (-5/13, -4/13)

Since slope_1 was -2/3 and slope_2 was 3/2 =
- 1/(slope_1),

Thus the lines are perpendicular to each other.

q.e.d.


Recall that if two lines have slopes m1 and m2 such that:

m1 * m2 = -1

i.e. m1 = -1/m2

then the lines are perpendicular to each other, i.e. (wrt the extended lines), they form a 'right angle',
i.e. a 90 degree angle, i.e. an angle of pi/2 to each other at their point of intersection.
Review also

 'times table':

*  0 1 2 3 4 5 6 7 8 9 10 11 12
0  0 ... (Fill in to 12)
1   0 1 ...
2  0 2 4
3  0 3 6 9
4  0 4 8 12 16
5  0 5 10 15 20 25...
6
8
9
10
11
12

Fill in whole table ...

(Note the symmetry of entries around the 'diagonal' line is but a reflection of the commutative law of multiplication, i.e. that a*b = b*a for all integer values a, b (and also for all rationals and reals ... and even complex numbers, the commutative law applies for both addition and multiplication, but NOT for subtraction or division.)

Note that the diagonal in the table is a 'line' of perfect squares:

0*0 = ?
1*1 = ?
2*2 = ?
.
.
8*8 = 64
9*9 = 81
10*10 = 100
11*11 = 121
12*12 = 144 (also called 'a gross')

What is sqrt(49) ?
What is sqrt(25) ?
What is sqrt(36) ?
What is sqrt(9) ?
What is sqrt(16) ?

Recall the 'perfect squares' like:
49 = 7 * 7
Yes?
Thus we can easily find that: sqrt(49) = 7
Try to make, all your math statements, logically true statements.

49  != 7
(49 does not equal 7)

but ...
sqrt(49) is 7
Good :)
The next ones ?
sqrt(49) = 7
sqrt(25) =
sqrt(36) =
sqrt(9) =
sqrt(16) =

No calculator here please ...
sqrt(121) =
sqrt(81) =
sqrt(100) =
sqrt(4) =
sqrt(144) =
sqrt(64) =
sqrt(1) =
sqrt(0) =
sqrt(1/4) =
sqrt(9/16) =
sqrt(81/121) =

Review question(s):

Below, whenever I write the symbol s, replace it with the symbol sqrt(2)

1)
if y = s*(x-s)*(x+s)
What are the roots?
What is extreme value?
Is this a max or min?
What happens to all the above if s is replaced by -s ?
Hint re. finding extreme value:

recall that the extreme y value is reached,

when x is the value of the mid-point of the roots.
2)
if y = s*(s-x)**2

answer for this y, all of the same questions as in question 1) above
Answer for ...

2)
if y = s*(s-x)**2

answer for this y, all of the same questions as in question 1) above

Answers:
There is one and only one root and it occurs at x = s = sqrt(2), and there y = 0, a min extreme value,
since  here the parabola opens up, because the coefficient in front of the x**2 term is pos.

Now if s were to be: -sqrt(2), then single root is at:
x = s = -sqrt(2)
And here, y is 0, the max value, because the parabola graph of the quadratic opens down,
since here the coefficient in front of the x**2 term is negative.
If you now sketch in all these 4 parabolas ... that is good practice ...
and is often a good way to start to see what is going on.

To sketch the parabolas, recall that 2**(1/2) is about 1.4


sqrt(49) = 7
sqrt(25) = 5
sqrt(36) = 6
sqrt(9) = 3
sqrt(16) = 4

No calculator needed here either ... if one knows the 'times table' ...

sqrt(121) = 11
sqrt(81) = 9
sqrt(100) = 10
sqrt(4) = 2
sqrt(144) = 12
sqrt(64) = 8
sqrt(1) = 1
sqrt(0) = 0
sqrt(1/4) = 1/2
sqrt(9/16) = sqrt(9)/sqrt(16) = 3/4
sqrt(81/121) = 9/11

Now practice factoring all numbers ... (show all factors of each number, excluding 1 and itself)...

for all numbers from 4 to 144:

A start:

4:   2
5:   is prime number
6:   2,3
7:   is prime
8:   2,4
9:   3
10: 2,5
11:  prime
12:  2,3,4,6
13:  prime
14:  2,7
15:  3,5
16:  2,4,8
17:  prime
18:  2,3,6,9
19:  prime
20:  2,4,5,10
21:  3,7
22:  2,11
23:  prime
24:  2,3,4,6,8,12
25:  5
26:  2,13
27:  3,9
28:  2,19
29:  prime
30:  2,3,5,6,10,15
31:  prime
32:  2,4,8,16
33:  3,11 (and Jesus was in Israel about 33.5 years when he ascended ...
           back into heaven in a glorified body ...
           like we will soon be given.)



Can you prove this ?

... that if two lines have slopes m1 and m2 such that:

m1 * m2 = -1

i.e. m1 = -1/m2

then the lines are perpendicular to each other,
i.e. (wrt the extended lines), they form a 'right angle',
i.e. a 90 degree angle, i.e. an angle of pi/2 to each other at their point of intersection.


Hint:

take values a and b as positive, (with b > a),

then plot:      point1 ( a, b)
and also plot:  point2 (-b, a)

then what is length of r, the distance from the origin to each point ...

(what theorem is applicable? ... HINT: The Pythagorean Theorem)

then what is length of line from point2 to point1

... and is this squared ... the same as sum of squares of r ?  i.e. =? 2*r**2

If so ... what does that imply about the angle opposite this longest side of that triangle?



Also ... practice these:

2*2 = 4, sqrt(4) = ?
3*3 = 9, sqrt(9) = ?
.
.
.
12*12 = 144, sqrt(144) = ?


and ...

sqrt(121/81) = ?
sqrt(36/49) = ?
sqrt(64/25) = ?
sqrt(9/100) = ?


A start  ...

Each answer is a nice simple fraction because for each ...
the numerator and the denominator are each 'perfect squares'

sqrt(121/81) = sqrt(121)/sqrt(81) = 11/9

Note that:  11/9 * (11/9) = 121/81

sqrt(36/49) = ?
sqrt(64/25) = ?
sqrt(9/100) = ?
sqrt(64/25) = ?
sqrt(9/100) = ?
Title: Re: High School type Math questions solved using Python 3.x ...
Post by: David on May 16, 2016, 05:43:51 PM
Also see these ...


Simple Proofs of Pythagorean Theorem

http://jwilson.coe.uga.edu/EMT668/EMT668.Student.Folders/HeadAngela/essay1/Pythagorean.html


Also see ...

http://www.analyzemath.com/Geometry/pythagora_theorem.html

http://math.stackexchange.com/questions/803/what-is-the-most-elegant-proof-of-the-pythagorean-theorem

https://www.khanacademy.org/math/basic-geo/basic-geo-pythagorean-topic/basic-geo-pythagorean-proofs/v/garfield-s-proof-of-the-pythagorean-theorem

http://www.mathsisfun.com/geometry/pythagorean-theorem-proof.html

http://jwilson.coe.uga.edu/emt668/EMAT6680.Folders/Brooks/6690stuff/Righttriangle/Pythagconv.html


Proof of the Converse of the Pythagorean Theorem

Note: below I am using The Python Computer Programming Language convention
to indicate raising a value to an exponent,
i.e. 2**3 means 3 facters of 2,
i.e. 2**3 = 2*2*2


The Pythagorean Theorem states that if ABC is a triangle (with) right angled at C, then:

a**2 + b**2 = c**2

The converse of the Pythagorean Theorem states that if:

a**2 + b**2 = c**2 holds,

then:

triangle ABC is a right triangle (with) right angled at C

http://proofsfromthebook.com/2015/02/16/proof-converse-pythagorean-theorem/


Do you know and can you prove: the Sine Law?

In a triangle with angles A,B,C
and opposite sides a,b,c
we have: sin(A)/a = sin(B)/b = sin(C)/c

Do you know and can you prove: the Cosine Law?

In a triangle with angles A,B,C
and opposite sides a,b,c
we have:
c**2 = a**2 + b**2 - a*b*cos(C)

b**2  = a**2 + c**2 - a*c*cos(B)

a**2  = b**2 + c**2 - b*c*cos(A)

http://www.mathsisfun.com/algebra/trig-cosine-law.html