CoCalc Shared FilesMath211-18F-PublicShared.sagews
Author: Paul Zeitz
Views : 11
Description: Now it should work
################################
#
#     (You can move to any line by using the "lightning bolt" button to the right of the large 'A')
#
#  65   Distributive property for dot- and cross-product
#  112  Miscellaneous examples, done in class on R 8/28/18
#  125  Plot a plane, given three points on it
#  170  Plot a plane, given a normal vector and the distance from the plane to the origin
#
#

#ILLUSTRATION OF DISTRIBUTIVE PROPERTY FOR DOT PRODUCT AND FOR CROSS PRODUCT
#In the diagram created, vector A is a unit vector. We draw both parallel and perpendicular projections of vectors B and C onto A.

# The main idea is that given any vectors B and A, we can resolve B into two orthogonal components: the PARALLEL component of B onto A is parallel to A, while the
# PERPENDICULAR component of B onto A is perpendicular to A and in the same plane as A and B.
# The MAGNITUDE of the PARALLEL projection of B onto A is the absolute value of the dot-product of B and A (assume A is a unit vector),
# and the PERPENDICULAR projection of B onto A (the actual VECTOR, not the magnitude) is the cross-product of B and A.

def perpProj(x,y):
#output is the perpendicular component of x wrt y, where
#it is understood for convenience that y is a unit vector
#and x, y are both vectors
return x-y*x.dot_product(y)

def parProj(x,y):
#output is the parallel component of x wrt y, where y is unit
return y*x.dot_product(y)

a=vector([0,1,0])
b=vector([-.3,.1,.7])
c=vector([-.7,.5,.3])
t=6 #thickness of some vectors
bc=b.cross_product(a)
P=plot(a, color='red', thickness=t)
P += plot(b, color='blue', thickness=t)
P += plot(c, color='black',thickness =t, start=b)
#P += plot(c,color='black',start=b)
#P += plot(b,color='blue',start=c)

P += plot(text3d("B",b*0.7-a*.05,color='blue'))
P += plot(text3d("A",a*1.05,color='red'))
P += plot(text3d("C",b*1.2+c*0.3,color='black'))
P += plot(b+c,color="magenta", thickness=t)
P += plot(text3d("B+C", (b+c)*.6, color='magenta'))
P += plot(-perpProj(b,a), color='blue',start=b)
P += plot(-perpProj(b,a), color='blue',start=b+parProj(c,a))
P += plot(parProj(b,a), color='blue',start=-0.05*perpProj(b,a))
P += plot(parProj(c,a), color='black',start = parProj(b,a)-0.08*perpProj(b,a))
P += plot(parProj(b+c,a), color='magenta',start=-0.12*perpProj(b,a))
P += plot(-perpProj(b+c,a), color='magenta',start=b+c)
P += plot(parProj(c,a),color='black',start=b)
P += plot(perpProj(c,a), color='black',start=b+parProj(c,a))
#P += plot(parProj(b+c,a), color='magenta',start=perpProj(b+c,a))
P.show(aspect_ratio=1.0,frame=false, spin=5)

3D rendering not yet implemented
78^543

25548726719570371226255187682826237626495114567336561342146579805780338587968682242723434623119650821725595954157695488460462846809201877877101685248835438277545547430259371949782997802506616873836495964781789596164252239566560525969473170257436451198555331307424151262645614190306662519157100743141199967027913417026847216132670063183094986837111669820368791714976148885032137794066342274413941769002125318064629115949358741519464979590531506856333639383376603934970263120108128195945327144359259742403137647398385745075341355975284746043220425048832590748346844105111873022911489985361074484973326385983468023945655325172654194703329836830176481535482759618437408618142114936637666353141144740356606252629412735038494923307954253201828522875665770502526479807331548495980718185340124774147586176082224989136985186394568443152716282859040204105716801734062596717887204195090976233956564686018563963443745498614955635316153284494537511251490152827702742425082397923764331727505659274103850737388252543730256622546808042424369152
plot(sin,0,pi)

%var x,y,z
pic=implicit_plot3d(x^2+y^2+z^2-1,(x,-1,0.5),(y,-1,1),(z,-1,1),color='red',mesh=1)
pic.show()

3D rendering not yet implemented
#Plot a plane, given three points on the plane
# try changing the points defined in line 27 of this

#declare variables
%var x, y, z

#define a function to draw axes. Very useful for understanding plots
def axes(size,xcolor='red',ycolor='green',zcolor='blue'):
#returns a plot of axis vectors, labeled, with size

xSize=size; ySize= size; zSize=size
xAxis = plot(vector((xSize,0,0)),color=xcolor,width=3)
yAxis = plot(vector((0,ySize,0)),color=ycolor,width=3)
zAxis = plot(vector((0,0,zSize)),color=zcolor,width=3)
#Labels for axes
#set fontsize (change if you need to)
fsize=20
xT=text3d("X",(xSize*1.1,0,0),color=xcolor,fontsize=fsize)
yT=text3d("Y",(0,ySize*1.1,0),color=ycolor,fontsize=fsize)
zT=text3d("Z",(0,0,zSize*1.1),color=zcolor,fontsize=fsize)
return xAxis+xT+yAxis+yT+zAxis+zT

asize = 16  #axis size
psize = 12  #plane size

#define the three points
a= (0,0,1); b= (0,1,0); c= (1,0,0)
#turn em into vectors
A = vector(a); B= vector(b); C=vector(c)
AB = B-A; AC = C-A
N = AB.cross_product(AC) #note the syntax for cross product
f = N[0]*x+N[1]*y + N[2]*z-N.dot_product(A)  #set this equal to zero to get equation of plane

P = plot(axes(asize))
P += implicit_plot3d(f, (x,-psize, psize), (y,-psize, psize), (z, -psize, psize), color='orange', opacity=0.1)
P += plot(points([a,b,c], thickness=40, color='black'))
P += plot(N, start = a, width = 3, color='black')

show('The equation of the plane is $'+latex(f)+'=0$')
show('Normal vector is black.')

show(P, spin =5)

The equation of the plane is $-x - y - z + 1 =0$
Normal vector is black.
3D rendering not yet implemented
#Plot a plane, given a normal vector and the distance from the origin

#declare variables
%var x, y, z

#define a function to draw axes. Very useful for understanding plots
def axes(size,xcolor='red',ycolor='green',zcolor='blue'):
#returns a plot of axis vectors, labeled, with size

xSize=size; ySize= size; zSize=size
xAxis = plot(vector((xSize,0,0)),color=xcolor,width=3)
yAxis = plot(vector((0,ySize,0)),color=ycolor,width=3)
zAxis = plot(vector((0,0,zSize)),color=zcolor,width=3)
#Labels for axes
#set fontsize (change if you need to)
fsize=20
xT=text3d("X",(xSize*1.1,0,0),color=xcolor,fontsize=fsize)
yT=text3d("Y",(0,ySize*1.1,0),color=ycolor,fontsize=fsize)
zT=text3d("Z",(0,0,zSize*1.1),color=zcolor,fontsize=fsize)
return xAxis+xT+yAxis+yT+zAxis+zT

asize = 16  #axis size
psize = 12  #plane size

#define the normal and distance to origin
N=vector((1,1,1))
d=5 #dist to origin

#equation of plane is K*<x,y,z>=d ONLY as long as K is a unit normal vector
K=N/N.norm() #note syntax for norm of a vector: the norm of A is A.norm()

f = K[0]*x+K[1]*y + K[2]*z-d #set this equal to zero to get equation of plane

P = plot(axes(asize))
P += implicit_plot3d(f, (x,-psize, psize), (y,-psize, psize), (z, -psize, psize), color='orange', opacity=0.1)

P += plot(10*N, width = 3, color='black') #I multiplied N to make it longer. You may want to change this.

show('The equation of the plane is $'+latex(f)+'=0$')
show('Normal vector is black')
show(P, spin =5)

The equation of the plane is $\frac{1}{3} \, \sqrt{3} x + \frac{1}{3} \, \sqrt{3} y + \frac{1}{3} \, \sqrt{3} z - 5 =0$
Normal vector is black
3D rendering not yet implemented


a=(2,-1,5)
A=vector(a)
b=(1,1,1); c=(0,-2,4)
B=vector(b);C=vector(c)
A.dot_product(B)

$6$
A.cross_product(B)

$\left(-6,\,3,\,3\right)$
B.cross_product(A)

$\left(22,\,-16,\,1\right)$
A.cross_product(B)

$\left(-22,\,16,\,-1\right)$
A.norm()

$\sqrt{29}$

n=2^63
for _ in range(30):
p=n.next_prime()

print p, p-n
n=p

9223372036854775837 29 9223372036854775907 70 9223372036854775931 24 9223372036854775939 8 9223372036854775963 24 9223372036854776063 100 9223372036854776077 14 9223372036854776167 90 9223372036854776243 76 9223372036854776257 14 9223372036854776261 4 9223372036854776293 32 9223372036854776299 6 9223372036854776351 52 9223372036854776393 42 9223372036854776407 14 9223372036854776561 154 9223372036854776657 96 9223372036854776687 30 9223372036854776693 6 9223372036854776711 18 9223372036854776803 92 9223372036854777017 214 9223372036854777059 42 9223372036854777119 60 9223372036854777181 62 9223372036854777211 30 9223372036854777293 82 9223372036854777341 48 9223372036854777343 2
n

9223372036854777343
prod=n*(n-2)

mod(prod,9)

8
prod

85070591730234644163149060928396584963