Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
load("__common__.sage")
2
3
def generator():
4
#Pick n vectors in Rn
5
n=choice([3,4,5])
6
vec=[]
7
for i in range(0,n):
8
v=[]
9
for _ in range(0,n):
10
v.append(randrange(-5,5))
11
vec.append(vector(v))
12
13
#Pick if yes a basis combination or not
14
basis = choice([false,true])
15
16
#If dependent, Generate the 3, 4, 5th vector sometimes
17
if basis==0:
18
if choice([false,true]):
19
vec[2] = randrange(-3,3)*vec[0]+randrange(-3,3)*vec[1]
20
if n>3 and choice([false,true]):
21
vec[3] = randrange(-3,3)*vec[0]+randrange(-3,3)*vec[1]+randrange(-3,3)*vec[2]
22
if n>4 and choice([false,true]):
23
vec[4] = randrange(-3,3)*vec[0]+randrange(-3,3)*vec[1]+randrange(-3,3)*vec[3]
24
25
A=matrix(vec).transpose()
26
if rank(A)<n:
27
basis=false
28
else:
29
basis=true
30
31
32
return {
33
"basis": basis,
34
"vecset": vectorSet(vec),
35
"dim": str(n),
36
"prompt": choice([true,false]),
37
"matrix": A,
38
"rref": A.rref(),
39
}
40
41