Sharedhomework 1 4.2 #3 .sagewsOpen in CoCalc
Homework
#Andrea Campos Carrillo
#4.2 #3
#trajectory
var("H,G")
k1=.1
k3=.1
@interact
def verify(n=(0,12)):
    t=srange(0,100,.1)
    sol = desolve_odeint([(1/(1+G^n))-k1*H,H-k3*G], ics=[.4,.4], dvars=[H,G],times=t)
    c=list_plot(zip(sol[:,0],sol[:,1]), plotjoined=True,axes_labels=["H","G"])
    show(c)
#no oscillation no matter what value of n due to the elimination of time delay.(eliminate middle man in this case P)
(H, G)
Interact: please open in CoCalc
#time series
var("H,G")
k1=.1
k3=.1
@interact
def timeseries(n=(0,12)):
    t=srange(0,100,.1)
    sol= desolve_odeint([(1/(1+G^n))-k1*H,H-k3*G], ics=[.4,.4], dvars=[H,G],times=t)
    d=list_plot(zip(t,sol[:,0]),plotjoined=True,axes_labels=["times","H,G"])+list_plot(zip(t,sol[:,1]))
    show(d)
(H, G)
Interact: please open in CoCalc
#homework 3
#5.1.2
#r=.5
#f(Xn)=Xn*r
#dol=[10]
#for t in srange(30):
   # dol.append(f(dol[-1]))
#g=list_plot(dol,axes_labels=["t","Xn"],color="royalblue")
#show(g)
r=.5
f(Xn)=Xn*r
sol=[2]
for t in srange(30):
    sol.append(f(sol[-1]))
p=list_plot(sol,axes_labels=["t","Xn"],color="royalblue")+list_plot(dol,axes_labels=["t","Xn"],color="coral")
show(p)
r=.5
f(Xn)=Xn*r
dol=[10]
for t in srange(30):
    dol.append(f(dol[-1]))
g=list_plot(dol,axes_labels=["t","Xn"],color="royalblue")
show(g)
#r=1
#f(Xn)=Xn*r
#aol=[2]
#for t in srange(30):
   # aol.append(f(aol[-1]))
#w=list_plot(aol,axes_labels=["t","Xn"],color="lavender")
#show(w)
r=1
f(Xn)=Xn*r
zol=[10]
for t in srange(30):
    zol.append(f(zol[-1]))
v=list_plot(zol,axes_labels=["t","Xn"],color="lightblue")+list_plot(aol,axes_labels=["t","Xn"],color="lavender")
show(v)
r=1
f(Xn)=Xn*r
aol=[2]
for t in srange(30):
    aol.append(f(aol[-1]))
w=list_plot(aol,axes_labels=["t","Xn"],color="lavender")
show(w)
#r=1.5
#f(Xn)=Xn*r
##lol=[10]
#for t in srange(30):
    #lol.append(f(lol[-1]))
#k=list_plot(lol,axes_labels=["t","Xn"],color="cornflowerblue")
#show(k)
r=1.5
f(Xn)=Xn*r
hol=[2]
for t in srange(30):
    hol.append(f(hol[-1]))
q=list_plot(hol,axes_labels=["t","Xn"],color="aquamarine",ymin=0)+list_plot(lol,axes_labels=["t","Xn"],color="cornflowerblue")
show(q)
r=1.5
f(Xn)=Xn*r
lol=[10]
for t in srange(30):
    lol.append(f(lol[-1]))
k=list_plot(lol,axes_labels=["t","Xn"],color="cornflowerblue")
show(k)
r=1.10
f(Xn)=Xn*r
ol=[10]
for t in srange(10):
    ol.append(f(ol[-1]))
ol
[10, 11.0000000000000, 12.1000000000000, 13.3100000000000, 14.6410000000000, 16.1051000000000, 17.7156100000000, 19.4871710000000, 21.4358881000000, 23.5794769100000, 25.9374246010000]
r=1.2
f(Xn)=Xn*r*(1-Xn)
lo=[.42]
for t in srange(0,1,.1):
    lo.append(f(lo[-1]))
e=list_plot(lo,axes_labels=["t","Xn"],color="cornflowerblue")
show(e)

#28
Alist=[[0,1],[2,8]]
Blist=[[10,4],[4,5]]
A=matrix(Alist)
B=matrix(Blist)
AB=A*B
product=zero_matrix(RR,A.dimensions()[0],B.dimensions()[1])

#29
for i in srange(0,2):#for every row in  A matrix, how many times to iterate
    for j in srange(0,2):#for every column in B
        R=A.row(i)#gets the i"th row of matrix A
        C=B.column(j)#gets the j'th column of matrix B
        Dproduct=R*C#for every i in A times it by the corresponding j in B matrix
        product[i,j]=Dproduct
product
[4.00000000000000 5.00000000000000] [52.0000000000000 48.0000000000000]
#30

def Matrixproduct(A,B):
    for i in srange(A.dimensions()[0]):
        for j in srange(B.dimensions()[1]):
            result=A.dimensions()[0]*B.dimensions()[1]
            newM=A*B
            return result*newM
Matrixproduct(A,B)
[ 16 20] [208 192]
alist=[[1,2],[5,6]]
blist=[[3,4],[9,8]]
A=matrix(alist)
B=matrix(blist)
Matrixproduct(A,B)
[ 84 80] [276 272]
alist2=[[10,23],[54,62]]
blist2=[[30,4],[9,4]]
A=matrix(alist2)
B=matrix(blist2)
Matrixproduct(A,B)
[2028 528] [8712 1856]
#31
def Matrixproduct(A,B):
    if A.dimensions()[0]!= B.dimensions()[1]:#if the condition is met do the following, != means is not equal
        print "Error"#if the above condition is met then print error
    else:#if first condition is not met then do the following
        for i in srange(A.dimensions()[0]):
            for j in srange(B.dimensions()[1]):
                result=A.dimensions()[0]*B.dimensions()[1]
                newM=A*B
                return result*newM
alist3=[[10,23],[54,62],[23,24]]
blist3=[[30,4],[9,4]]
A=matrix(alist3)
B=matrix(blist3)
Matrixproduct(A,B)
Error
#32
alist3=[[10,23],[54,62],[23,24]]
A=matrix(alist3)
type(A)#find the type of a matrix object



M=matrix(RDF,[[-.21,-.84],[1.68,1.47]])
M.eigenvectors_right()
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'> [(0.6299999999999999 + 0.84*I, [(-0.4082482904638632 + 0.408248290463863*I, 0.8164965809277261)], 1), (0.6299999999999999 - 0.84*I, [(-0.4082482904638632 - 0.408248290463863*I, 0.8164965809277261)], 1)]